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.

Revision:
31:f95fc2ac1dbc
Parent:
3:5120491ba317
--- a/source/PersistentStorageHelper/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp	Wed May 10 13:00:31 2017 +0100
+++ b/source/PersistentStorageHelper/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp	Fri May 19 17:30:11 2017 +0100
@@ -14,14 +14,15 @@
  * limitations under the License.
  */
 
-#ifdef TARGET_NRF51822 /* Persistent storage supported on nrf51 platforms */
+#if defined(TARGET_NRF51822) || defined(TARGET_NRF52832) /* Persistent storage supported on nrf51 and nrf52 platforms */
 
 extern "C" {
-    #include "pstorage.h"
+    #include "fstorage.h"
 }
 
 #include "nrf_error.h"
 #include "../../EddystoneService.h"
+#include <cstddef>
 
 /**
  * Nordic specific structure used to store params persistently.
@@ -37,55 +38,52 @@
 
 /**
  * The following is a module-local variable to hold configuration parameters for
- * short periods during flash access. This is necessary because the pstorage
+ * short periods during flash access. This is necessary because the fstorage
  * APIs don't copy in the memory provided as data source. The memory cannot be
  * freed or reused by the application until this flash access is complete. The
  * load and store operations in this module initialize persistentParams and then
- * pass it on to the 'pstorage' APIs.
+ * pass it on to the 'fstorage' APIs.
  */
 static PersistentParams_t persistentParams;
 
-static pstorage_handle_t pstorageHandle;
-
 /**
- * Dummy callback handler needed by Nordic's pstorage module. This is called
+ * Dummy callback handler needed by Nordic's fstorage module. This is called
  * after every flash access.
  */
-static void pstorageNotificationCallback(pstorage_handle_t *p_handle,
-                                         uint8_t            op_code,
-                                         uint32_t           result,
-                                         uint8_t           *p_data,
-                                         uint32_t           data_len)
+static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
 {
     /* Supress compiler warnings */
-    (void) p_handle;
-    (void) op_code;
+    (void) evt;
     (void) result;
-    (void) p_data;
-    (void) data_len;
+}
 
-    /* APP_ERROR_CHECK(result); */
+FS_REGISTER_CFG(fs_config_t fs_config) = {
+    NULL,              // Begin pointer (set by fs_init)
+    NULL,              // End pointer (set by fs_init)
+    &fs_evt_handler,   // Function for event callbacks.
+    1,                 // Number of physical flash pages required.
+    0xFE               // Priority for flash usage.
+};
+
+
+void loadPersistentParams(void) {
+    // copy from flash into persistent params struct
+    memcpy(&persistentParams, fs_config.p_start_addr, sizeof(PersistentParams_t));
 }
 
 /* Platform-specific implementation for persistence on the nRF5x. Based on the
- * pstorage module provided by the Nordic SDK. */
+ * fstorage module provided by the Nordic SDK. */
 bool loadEddystoneServiceConfigParams(EddystoneService::EddystoneParams_t *paramsP)
 {
-    static bool pstorageInitied = false;
-    if (!pstorageInitied) {
-        pstorage_init();
-
-        static pstorage_module_param_t pstorageParams = {
-            .cb          = pstorageNotificationCallback,
-            .block_size  = sizeof(PersistentParams_t),
-            .block_count = 1
-        };
-        pstorage_register(&pstorageParams, &pstorageHandle);
-        pstorageInitied = true;
+    static bool fstorageInited = false;
+    if (!fstorageInited) {
+        fs_init();
+        fstorageInited = true;
     }
 
-    if ((pstorage_load(reinterpret_cast<uint8_t *>(&persistentParams), &pstorageHandle, sizeof(PersistentParams_t), 0) != NRF_SUCCESS) ||
-        (persistentParams.persistenceSignature != PersistentParams_t::MAGIC)) {
+    loadPersistentParams();
+
+    if ((persistentParams.persistenceSignature != PersistentParams_t::MAGIC)) {
         // On failure zero out and let the service reset to defaults
         memset(paramsP, 0, sizeof(EddystoneService::EddystoneParams_t));
         return false;
@@ -96,22 +94,20 @@
 }
 
 /* Platform-specific implementation for persistence on the nRF5x. Based on the
- * pstorage module provided by the Nordic SDK. */
+ * fstorage module provided by the Nordic SDK. */
 void saveEddystoneServiceConfigParams(const EddystoneService::EddystoneParams_t *paramsP)
 {
     memcpy(&persistentParams.params, paramsP, sizeof(EddystoneService::EddystoneParams_t));
     if (persistentParams.persistenceSignature != PersistentParams_t::MAGIC) {
         persistentParams.persistenceSignature = PersistentParams_t::MAGIC;
-        pstorage_store(&pstorageHandle,
-                       reinterpret_cast<uint8_t *>(&persistentParams),
-                       sizeof(PersistentParams_t),
-                       0 /* offset */);
     } else {
-        pstorage_update(&pstorageHandle,
-                        reinterpret_cast<uint8_t *>(&persistentParams),
-                        sizeof(PersistentParams_t),
-                        0 /* offset */);
+        fs_erase(&fs_config, fs_config.p_start_addr, sizeof(PersistentParams_t) / 4);
     }
+
+    fs_store(&fs_config,
+             fs_config.p_start_addr,
+             reinterpret_cast<uint32_t *>(&persistentParams),
+             sizeof(PersistentParams_t) / 4);
 }
 
 #endif /* #ifdef TARGET_NRF51822 */