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:
3:5120491ba317
Parent:
2:9ee673e0b86a
--- a/source/TLMFrame.h	Thu Jul 28 23:27:37 2016 +0100
+++ b/source/TLMFrame.h	Fri Jul 29 22:45:40 2016 +0100
@@ -1,158 +1,158 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2015 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TLMFRAME_H__
-#define __TLMFRAME_H__
-
-#include "EddystoneTypes.h"
-
-/**
- * Class that encapsulates data that belongs to the Eddystone-TLM frame. For
- * more information refer to https://github.com/google/eddystone/tree/master/eddystone-tlm.
- */
-class TLMFrame
-{
-public:
-    /**
-     * Construct a new instance of this class.
-     *
-     * @param[in] tlmVersionIn
-     *              Eddystone-TLM version number to use.
-     * @param[in] tlmBatteryVoltageIn
-     *              Initial value for the Eddystone-TLM Battery Voltage.
-     * @param[in] tlmBeaconTemperatureIn
-     *              Initial value for the Eddystone-TLM Beacon Temperature.
-     * @param[in] tlmPduCountIn
-     *              Initial value for the Eddystone-TLM Advertising PDU Count.
-     * @param[in] tlmTimeSinceBootIn
-     *              Intitial value for the Eddystone-TLM time since boot timer.
-     8              This timer has a 0.1 second resolution.
-     */
-    TLMFrame(uint8_t  tlmVersionIn           = 0,
-             uint16_t tlmBatteryVoltageIn    = 0,
-             uint16_t tlmBeaconTemperatureIn = 0x8000,
-             uint32_t tlmPduCountIn          = 0,
-             uint32_t tlmTimeSinceBootIn     = 0);
-
-    /**
-     * Set the Eddystone-TLM version number.
-     */
-    void setTLMData(uint8_t tlmVersionIn = 0);
-
-    /**
-     * Construct the raw bytes of the Eddystone-TLM frame that will be directly
-     * used in the advertising packets.
-     *
-     * @param[in] rawFrame
-     *              Pointer to the location where the raw frame will be stored.
-     */
-    void constructTLMFrame(uint8_t *rawFrame);
-
-    /**
-     * Get the size of the Eddystone-TLM frame constructed with the
-     * current state of the TLMFrame object.
-     *
-     * @return The size in bytes of the Eddystone-TLM frame.
-     */
-    size_t getRawFrameSize(void) const;
-
-    /**
-     * Update the time since boot.
-     *
-     * @param[in] nowInMillis
-     *              The time since boot in milliseconds.
-     */
-    void updateTimeSinceBoot(uint32_t nowInMillis);
-
-    /**
-     * Update the Battery Voltage.
-     *
-     * @param[in] tlmBatteryVoltageIn
-     *              The new Battery Voltage value.
-     */
-    void updateBatteryVoltage(uint16_t tlmBatteryVoltageIn);
-
-    /**
-     * Update the Beacon Temperature.
-     *
-     * @param[in] tlmBeaconTemperatureIn
-     *              The new Beacon Temperature value.
-     */
-    void updateBeaconTemperature(uint16_t tlmBeaconTemperatureIn);
-
-    /**
-     * Increment the current PDU counter by 1.
-     */
-    void updatePduCount(void);
-
-    /**
-     * Get the current Battery Voltage.
-     *
-     * @return The Battery Voltage.
-     */
-    uint16_t getBatteryVoltage(void) const;
-
-    /**
-     * Get the current Beacon Temperature.
-     *
-     * @return The Beacon Temperature.
-     */
-    uint16_t getBeaconTemperature(void) const;
-
-    /**
-     * Get the current TLM Version number.
-     *
-     * @return The TLM Version number.
-     */
-    uint8_t getTLMVersion(void) const;
-
-private:
-    /**
-     * The byte ID of an Eddystone-TLM frame.
-     */
-    static const uint8_t FRAME_TYPE_TLM = 0x20;
-    /**
-     * The size of an Eddystone-TLM frame.
-     */
-    static const uint8_t FRAME_SIZE_TLM = 14;
-
-    /**
-     * Eddystone-TLM version value.
-     */
-    uint8_t              tlmVersion;
-    /**
-     * Time since boot in milliseconds.
-     */
-    uint32_t             lastTimeSinceBootRead;
-    /**
-     * Eddystone-TLM Battery Voltage value.
-     */
-    uint16_t             tlmBatteryVoltage;
-    /**
-     * Eddystone-TLM Beacon temperature value.
-     */
-    uint16_t             tlmBeaconTemperature;
-    /**
-     * Eddystone-TLM Advertising PDU Count.
-     */
-    uint32_t             tlmPduCount;
-    /**
-     * Eddystone-TLM time since boot with 0.1 second resolution.
-     */
-    uint32_t             tlmTimeSinceBoot;
-};
-
-#endif  /* __TLMFRAME_H__ */
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TLMFRAME_H__
+#define __TLMFRAME_H__
+
+#include "EddystoneTypes.h"
+
+/**
+ * Class that encapsulates data that belongs to the Eddystone-TLM frame. For
+ * more information refer to https://github.com/google/eddystone/tree/master/eddystone-tlm.
+ */
+class TLMFrame
+{
+public:
+    /**
+     * Construct a new instance of this class.
+     *
+     * @param[in] tlmVersionIn
+     *              Eddystone-TLM version number to use.
+     * @param[in] tlmBatteryVoltageIn
+     *              Initial value for the Eddystone-TLM Battery Voltage.
+     * @param[in] tlmBeaconTemperatureIn
+     *              Initial value for the Eddystone-TLM Beacon Temperature.
+     * @param[in] tlmPduCountIn
+     *              Initial value for the Eddystone-TLM Advertising PDU Count.
+     * @param[in] tlmTimeSinceBootIn
+     *              Intitial value for the Eddystone-TLM time since boot timer.
+     8              This timer has a 0.1 second resolution.
+     */
+    TLMFrame(uint8_t  tlmVersionIn           = 0,
+             uint16_t tlmBatteryVoltageIn    = 0,
+             uint16_t tlmBeaconTemperatureIn = 0x8000,
+             uint32_t tlmPduCountIn          = 0,
+             uint32_t tlmTimeSinceBootIn     = 0);
+
+    /**
+     * Set the Eddystone-TLM version number.
+     */
+    void setTLMData(uint8_t tlmVersionIn = 0);
+
+    /**
+     * Construct the raw bytes of the Eddystone-TLM frame that will be directly
+     * used in the advertising packets.
+     *
+     * @param[in] rawFrame
+     *              Pointer to the location where the raw frame will be stored.
+     */
+    void constructTLMFrame(uint8_t *rawFrame);
+
+    /**
+     * Get the size of the Eddystone-TLM frame constructed with the
+     * current state of the TLMFrame object.
+     *
+     * @return The size in bytes of the Eddystone-TLM frame.
+     */
+    size_t getRawFrameSize(void) const;
+
+    /**
+     * Update the time since boot.
+     *
+     * @param[in] nowInMillis
+     *              The time since boot in milliseconds.
+     */
+    void updateTimeSinceBoot(uint32_t nowInMillis);
+
+    /**
+     * Update the Battery Voltage.
+     *
+     * @param[in] tlmBatteryVoltageIn
+     *              The new Battery Voltage value.
+     */
+    void updateBatteryVoltage(uint16_t tlmBatteryVoltageIn);
+
+    /**
+     * Update the Beacon Temperature.
+     *
+     * @param[in] tlmBeaconTemperatureIn
+     *              The new Beacon Temperature value.
+     */
+    void updateBeaconTemperature(uint16_t tlmBeaconTemperatureIn);
+
+    /**
+     * Increment the current PDU counter by 1.
+     */
+    void updatePduCount(void);
+
+    /**
+     * Get the current Battery Voltage.
+     *
+     * @return The Battery Voltage.
+     */
+    uint16_t getBatteryVoltage(void) const;
+
+    /**
+     * Get the current Beacon Temperature.
+     *
+     * @return The Beacon Temperature.
+     */
+    uint16_t getBeaconTemperature(void) const;
+
+    /**
+     * Get the current TLM Version number.
+     *
+     * @return The TLM Version number.
+     */
+    uint8_t getTLMVersion(void) const;
+
+private:
+    /**
+     * The byte ID of an Eddystone-TLM frame.
+     */
+    static const uint8_t FRAME_TYPE_TLM = 0x20;
+    /**
+     * The size of an Eddystone-TLM frame.
+     */
+    static const uint8_t FRAME_SIZE_TLM = 14;
+
+    /**
+     * Eddystone-TLM version value.
+     */
+    uint8_t              tlmVersion;
+    /**
+     * Time since boot in milliseconds.
+     */
+    uint32_t             lastTimeSinceBootRead;
+    /**
+     * Eddystone-TLM Battery Voltage value.
+     */
+    uint16_t             tlmBatteryVoltage;
+    /**
+     * Eddystone-TLM Beacon temperature value.
+     */
+    uint16_t             tlmBeaconTemperature;
+    /**
+     * Eddystone-TLM Advertising PDU Count.
+     */
+    uint32_t             tlmPduCount;
+    /**
+     * Eddystone-TLM time since boot with 0.1 second resolution.
+     */
+    uint32_t             tlmTimeSinceBoot;
+};
+
+#endif  /* __TLMFRAME_H__ */