Eddystone beacons broadcast a small amount of information, like URLs, to nearby BLE devices. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-ble/tree/master/BLE_EddystoneService

Eddystone beacons broadcast a small amount of information, like URLs, to nearby BLE devices.

The Eddystone Beacon sample application runs in two stages:

  • On startup, the Configuration Service (which allows modification of the beacon runs for a user-defined period (default - 30 seconds).
  • When the Configuration Service period ends, the Eddystone Service broadcasts advertisement packets.

Running the application

Requirements

You should install the *Physical Web* application on your phone:

- Android version

- iOS version

Note: It is also possible to use a regular scanner to interract with your Eddystone beacon but it requires knowledge about BLE and Eddystone beacon specification out of the scope of this document.

Hardware requirements are in the main readme.

Building instructions

Building with mbed CLI

If you'd like to use mbed CLI to build this, then you should refer to the main readme. The instructions here relate to using the developer.mbed.org Online Compiler

In order to build this example in the mbed Online Compiler, first import the example using the ‘Import’ button on the right hand side.

Next, select a platform to build for. This must either be a platform that supports BLE, for example the NRF51-DK, or one of the following:

List of platforms supporting Bluetooth Low Energy

Or you must also add a piece of hardware and the supporting library that includes a Bluetooth Low Energy driver for that hardware, for example the K64F or NUCLEO_F401RE with the X-NUCLEO-IDB05A1

List of components supporting Bluetooth Low Energy.

Once you have selected your platform, compile the example and drag and drop the resulting binary onto your board.

For general instructions on using the mbed Online Compiler, please see the mbed Handbook

Working with nRF51-based 16K targets

Because of memory constraints, you can't use the SoftDevice 130 (S130) to build for nRF51-based 16K targets. If you are using these targets, then before building:

  1. Open the ``config.json`` file in this sample.
  2. Change ``soft device`` to ``S110``.
  3. Save.

You can now build for nRF51-based 16K targets.

Setting up the beacon

By default, the beacon directs to the url ``http://mbed.org``. You can change this to your own URL in two ways:

  • Manually edit the code in ``main.cpp`` in your copy of the sample.
  • Build and run the application's default code as explained in the building instructions. When the beacon starts up, the Configuration Service runs for 30 seconds (this is the default value; you can change it in ``main.cpp``). While the Configuration Service runs, you can use a BLE scanner on your phone to edit the values the service presents.

Checking for success

  • Build the application and install it on your board as explained in the building instructions.
  • Open the *Physical Web* application on your phone. It will start to search for nearby beacons.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/app_start.png

figure 1 Start of the *Physical Web* application version 0.1.856 on Android

  • When the beacon starts up, the Configuration Service runs for 30 seconds. During this time it is possible to change the URL advertised by the beacon. It is also important to note that during these 30 seconds, your device will not advertise any URL.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/open_configuration.png

figure 2 How to open the beacon configuration view using the *Physical Web* application version 0.1.856 on Android

  • Edit the URL advertised by your beacon.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/edit_url.png

figure 3 How to edit the URL advertised by your beacon using the *Physical Web* application version 0.1.856 on Android

  • Save the URL which will be advertised by your beacon.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/save_url.png

figure 4 How to save your beacon configuration and start advertising URL using the *Physical Web* application version 0.1.856 on Android.

  • Find your device; it should advertise the URL you have set.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/result.png

figure 5 Display of URL advertised by your beacon using the *Physical Web* application version 0.1.856 on Android.

Note: You can use the Eddystone Observer sample instead of a phone application.

Committer:
Vincent Coubard
Date:
Thu Jul 28 23:27:37 2016 +0100
Revision:
2:9ee673e0b86a
Parent:
1:9db4d46bb63f
Child:
3:5120491ba317
Sync with mbed-os-5.1.0-rc3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 2:9ee673e0b86a 1 /* mbed Microcontroller Library
Vincent Coubard 2:9ee673e0b86a 2 * Copyright (c) 2006-2015 ARM Limited
Vincent Coubard 2:9ee673e0b86a 3 *
Vincent Coubard 2:9ee673e0b86a 4 * Licensed under the Apache License, Version 2.0 (the "License");
Vincent Coubard 2:9ee673e0b86a 5 * you may not use this file except in compliance with the License.
Vincent Coubard 2:9ee673e0b86a 6 * You may obtain a copy of the License at
Vincent Coubard 2:9ee673e0b86a 7 *
Vincent Coubard 2:9ee673e0b86a 8 * http://www.apache.org/licenses/LICENSE-2.0
Vincent Coubard 2:9ee673e0b86a 9 *
Vincent Coubard 2:9ee673e0b86a 10 * Unless required by applicable law or agreed to in writing, software
Vincent Coubard 2:9ee673e0b86a 11 * distributed under the License is distributed on an "AS IS" BASIS,
Vincent Coubard 2:9ee673e0b86a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Vincent Coubard 2:9ee673e0b86a 13 * See the License for the specific language governing permissions and
Vincent Coubard 2:9ee673e0b86a 14 * limitations under the License.
Vincent Coubard 2:9ee673e0b86a 15 */
Vincent Coubard 2:9ee673e0b86a 16
Vincent Coubard 2:9ee673e0b86a 17 #ifdef TARGET_NRF51822 /* Persistent storage supported on nrf51 platforms */
Vincent Coubard 2:9ee673e0b86a 18
Vincent Coubard 2:9ee673e0b86a 19 extern "C" {
Vincent Coubard 2:9ee673e0b86a 20 #include "pstorage.h"
Vincent Coubard 2:9ee673e0b86a 21 }
Vincent Coubard 2:9ee673e0b86a 22
Vincent Coubard 2:9ee673e0b86a 23 #include "nrf_error.h"
Vincent Coubard 2:9ee673e0b86a 24 #include "../../EddystoneService.h"
Vincent Coubard 2:9ee673e0b86a 25
Vincent Coubard 2:9ee673e0b86a 26 /**
Vincent Coubard 2:9ee673e0b86a 27 * Nordic specific structure used to store params persistently.
Vincent Coubard 2:9ee673e0b86a 28 * It extends EddystoneService::EddystoneParams_t with a persistence signature.
Vincent Coubard 2:9ee673e0b86a 29 */
Vincent Coubard 2:9ee673e0b86a 30 struct PersistentParams_t {
Vincent Coubard 2:9ee673e0b86a 31 EddystoneService::EddystoneParams_t params;
Vincent Coubard 2:9ee673e0b86a 32 uint32_t persistenceSignature; /* This isn't really a parameter, but having the expected
Vincent Coubard 2:9ee673e0b86a 33 * magic value in this field indicates persistence. */
Vincent Coubard 2:9ee673e0b86a 34
Vincent Coubard 2:9ee673e0b86a 35 static const uint32_t MAGIC = 0x1BEAC000; /* Magic that identifies persistence */
Vincent Coubard 2:9ee673e0b86a 36 };
Vincent Coubard 2:9ee673e0b86a 37
Vincent Coubard 2:9ee673e0b86a 38 /**
Vincent Coubard 2:9ee673e0b86a 39 * The following is a module-local variable to hold configuration parameters for
Vincent Coubard 2:9ee673e0b86a 40 * short periods during flash access. This is necessary because the pstorage
Vincent Coubard 2:9ee673e0b86a 41 * APIs don't copy in the memory provided as data source. The memory cannot be
Vincent Coubard 2:9ee673e0b86a 42 * freed or reused by the application until this flash access is complete. The
Vincent Coubard 2:9ee673e0b86a 43 * load and store operations in this module initialize persistentParams and then
Vincent Coubard 2:9ee673e0b86a 44 * pass it on to the 'pstorage' APIs.
Vincent Coubard 2:9ee673e0b86a 45 */
Vincent Coubard 2:9ee673e0b86a 46 static PersistentParams_t persistentParams;
Vincent Coubard 2:9ee673e0b86a 47
Vincent Coubard 2:9ee673e0b86a 48 static pstorage_handle_t pstorageHandle;
Vincent Coubard 2:9ee673e0b86a 49
Vincent Coubard 2:9ee673e0b86a 50 /**
Vincent Coubard 2:9ee673e0b86a 51 * Dummy callback handler needed by Nordic's pstorage module. This is called
Vincent Coubard 2:9ee673e0b86a 52 * after every flash access.
Vincent Coubard 2:9ee673e0b86a 53 */
Vincent Coubard 2:9ee673e0b86a 54 static void pstorageNotificationCallback(pstorage_handle_t *p_handle,
Vincent Coubard 2:9ee673e0b86a 55 uint8_t op_code,
Vincent Coubard 2:9ee673e0b86a 56 uint32_t result,
Vincent Coubard 2:9ee673e0b86a 57 uint8_t *p_data,
Vincent Coubard 2:9ee673e0b86a 58 uint32_t data_len)
Vincent Coubard 2:9ee673e0b86a 59 {
Vincent Coubard 2:9ee673e0b86a 60 /* Supress compiler warnings */
Vincent Coubard 2:9ee673e0b86a 61 (void) p_handle;
Vincent Coubard 2:9ee673e0b86a 62 (void) op_code;
Vincent Coubard 2:9ee673e0b86a 63 (void) result;
Vincent Coubard 2:9ee673e0b86a 64 (void) p_data;
Vincent Coubard 2:9ee673e0b86a 65 (void) data_len;
Vincent Coubard 2:9ee673e0b86a 66
Vincent Coubard 2:9ee673e0b86a 67 /* APP_ERROR_CHECK(result); */
Vincent Coubard 2:9ee673e0b86a 68 }
Vincent Coubard 2:9ee673e0b86a 69
Vincent Coubard 2:9ee673e0b86a 70 /* Platform-specific implementation for persistence on the nRF5x. Based on the
Vincent Coubard 2:9ee673e0b86a 71 * pstorage module provided by the Nordic SDK. */
Vincent Coubard 2:9ee673e0b86a 72 bool loadEddystoneServiceConfigParams(EddystoneService::EddystoneParams_t *paramsP)
Vincent Coubard 2:9ee673e0b86a 73 {
Vincent Coubard 2:9ee673e0b86a 74 static bool pstorageInitied = false;
Vincent Coubard 2:9ee673e0b86a 75 if (!pstorageInitied) {
Vincent Coubard 2:9ee673e0b86a 76 pstorage_init();
Vincent Coubard 2:9ee673e0b86a 77
Vincent Coubard 2:9ee673e0b86a 78 static pstorage_module_param_t pstorageParams = {
Vincent Coubard 2:9ee673e0b86a 79 .cb = pstorageNotificationCallback,
Vincent Coubard 2:9ee673e0b86a 80 .block_size = sizeof(PersistentParams_t),
Vincent Coubard 2:9ee673e0b86a 81 .block_count = 1
Vincent Coubard 2:9ee673e0b86a 82 };
Vincent Coubard 2:9ee673e0b86a 83 pstorage_register(&pstorageParams, &pstorageHandle);
Vincent Coubard 2:9ee673e0b86a 84 pstorageInitied = true;
Vincent Coubard 2:9ee673e0b86a 85 }
Vincent Coubard 2:9ee673e0b86a 86
Vincent Coubard 2:9ee673e0b86a 87 if ((pstorage_load(reinterpret_cast<uint8_t *>(&persistentParams), &pstorageHandle, sizeof(PersistentParams_t), 0) != NRF_SUCCESS) ||
Vincent Coubard 2:9ee673e0b86a 88 (persistentParams.persistenceSignature != PersistentParams_t::MAGIC)) {
Vincent Coubard 2:9ee673e0b86a 89 // On failure zero out and let the service reset to defaults
Vincent Coubard 2:9ee673e0b86a 90 memset(paramsP, 0, sizeof(EddystoneService::EddystoneParams_t));
Vincent Coubard 2:9ee673e0b86a 91 return false;
Vincent Coubard 2:9ee673e0b86a 92 }
Vincent Coubard 2:9ee673e0b86a 93
Vincent Coubard 2:9ee673e0b86a 94 memcpy(paramsP, &persistentParams.params, sizeof(EddystoneService::EddystoneParams_t));
Vincent Coubard 2:9ee673e0b86a 95 return true;
Vincent Coubard 2:9ee673e0b86a 96 }
Vincent Coubard 2:9ee673e0b86a 97
Vincent Coubard 2:9ee673e0b86a 98 /* Platform-specific implementation for persistence on the nRF5x. Based on the
Vincent Coubard 2:9ee673e0b86a 99 * pstorage module provided by the Nordic SDK. */
Vincent Coubard 2:9ee673e0b86a 100 void saveEddystoneServiceConfigParams(const EddystoneService::EddystoneParams_t *paramsP)
Vincent Coubard 2:9ee673e0b86a 101 {
Vincent Coubard 2:9ee673e0b86a 102 memcpy(&persistentParams.params, paramsP, sizeof(EddystoneService::EddystoneParams_t));
Vincent Coubard 2:9ee673e0b86a 103 if (persistentParams.persistenceSignature != PersistentParams_t::MAGIC) {
Vincent Coubard 2:9ee673e0b86a 104 persistentParams.persistenceSignature = PersistentParams_t::MAGIC;
Vincent Coubard 2:9ee673e0b86a 105 pstorage_store(&pstorageHandle,
Vincent Coubard 2:9ee673e0b86a 106 reinterpret_cast<uint8_t *>(&persistentParams),
Vincent Coubard 2:9ee673e0b86a 107 sizeof(PersistentParams_t),
Vincent Coubard 2:9ee673e0b86a 108 0 /* offset */);
Vincent Coubard 2:9ee673e0b86a 109 } else {
Vincent Coubard 2:9ee673e0b86a 110 pstorage_update(&pstorageHandle,
Vincent Coubard 2:9ee673e0b86a 111 reinterpret_cast<uint8_t *>(&persistentParams),
Vincent Coubard 2:9ee673e0b86a 112 sizeof(PersistentParams_t),
Vincent Coubard 2:9ee673e0b86a 113 0 /* offset */);
Vincent Coubard 2:9ee673e0b86a 114 }
Vincent Coubard 2:9ee673e0b86a 115 }
Vincent Coubard 2:9ee673e0b86a 116
Vincent Coubard 2:9ee673e0b86a 117 #endif /* #ifdef TARGET_NRF51822 */