Bluetooth Low Energy / Mbed 2 deprecated BLE_EddystoneBeacon_Service Featured

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_EddystoneBeacon by URIBeacon

This example demonstrates how to set up and initialize a Eddystone Beacon. For more details on the Eddystone specification please see the Eddystone Github Page.

The Basics

An Eddystone Beacon is a Bluetooth Low Energy beacon, that means it does all of its data transfer in GAP advertising packets. Eddystone beacons, unlike other beacons, broadcast multiple types of data. Currently Eddystone beacons have 3 frame types (UID, URL, TLM) that will get swapped out periodically. This swapping of frame data allows Eddystone beacons to send many different types of data, thus increasing their usefulness over traditional beacons. Note that the UID frame type provides the same 16Bytes of UUID namespace that iBeacons do and the URL frame type provides the same functionality as a URIBeacon.

For more details see the Eddystone Specification.

Smartphone Apps

nRF Master Control Panel - this program recognizes Eddystone beacons and will display the data for all frame types.

iPhone Physical Web app

Android App

Walkthrough of Physical Web application

Technical Details

The Eddystone Specification looks like the following image. Please note that this may change over time and for up to date information the official spec should be referenced. /media/uploads/mbedAustin/scratch-1-.png

The Eddystone Frames get swapped in and out depending on what frames you have enabled. The only required frame type is the TLM frame, all others are optional and you can have any number enabled. To disable the UID or URL frames give their values a 'NULL' in the Eddystone constructor. The Eddystone spec recommends broadcasting 10 frames a second.

Note

  • The current Eddystone mbed example does not allow for combining the eddystone service with other services, this will be changes in a future update.
  • There is an Eddystone Config service that allows for updating beacons in the field. We are working on an example for this, so keep your eyes pealed for a future update.
Revision:
28:af37cebcb583
Parent:
27:29c6d1bb462e
Child:
29:dfb7fb5a971b
--- a/Eddystone.h	Fri Jul 24 03:00:57 2015 +0000
+++ b/Eddystone.h	Fri Jul 24 03:12:21 2015 +0000
@@ -23,7 +23,7 @@
 static const uint8_t BEACON_EDDYSTONE[] = {0xAA, 0xFE};
 
 //Debug is disabled by default
-#if 0
+#if 1
 #define DBG(x, ...)  printf("[EddyStone: DBG]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
 #define WARN(x, ...) printf("[EddyStone: WARN]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
 #define ERR(x, ...)  printf("[EddyStone: ERR]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
@@ -39,24 +39,16 @@
 * See https://github.com/google/eddystone
 *
 */
-class Eddystone
+class EddystoneService
 {
 public:
     /**
      * @brief Transmission Power Modes for UriBeacon
      */
-    static const uint8_t TX_POWER_MODE_LOWEST = 0; /*!< Lowest TX power mode */
-    static const uint8_t TX_POWER_MODE_LOW    = 1; /*!< Low TX power mode */
-    static const uint8_t TX_POWER_MODE_MEDIUM = 2; /*!< Medium TX power mode */
-    static const uint8_t TX_POWER_MODE_HIGH   = 3; /*!< High TX power mode */
-    static const unsigned int NUM_POWER_MODES = 4; /*!< Number of Power Modes defined */
 
     static const int ADVERTISING_INTERVAL_MSEC = 1000;  // Advertising interval for config service.
     static const int SERVICE_DATA_MAX = 31;             // Maximum size of service data in ADV packets
 
-    typedef uint8_t Lock_t[16];               /* 128 bits */
-    typedef int8_t PowerLevels_t[NUM_POWER_MODES];
-
     // There are currently 3 subframes defined, URI, UID, and TLM
 #define EDDYSTONE_MAX_FRAMETYPE 3
     void (*frames[EDDYSTONE_MAX_FRAMETYPE])(uint8_t *, uint32_t);
@@ -78,22 +70,6 @@
     static const uint8_t FRAME_SIZE_TLM = 14; // TLM frame is a constant 14Bytes
     static const uint8_t FRAME_SIZE_UID = 20; // includes RFU bytes
 
-    struct Params_t {
-        Lock_t        lock;
-        uint8_t       uriDataLength;
-        UriData_t     uriData;
-        uint8_t       flags;
-        PowerLevels_t advPowerLevels; // Current value of AdvertisedPowerLevels
-        uint8_t       txPowerMode;    // Firmware power levels used with setTxPower()
-        uint16_t      beaconPeriod;
-        uint8_t       tlmVersion;     // version of TLM packet
-        UIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B
-        UIDInstanceID_t  uidInstanceID;  // UUID type, Instance ID,  6B
-        int(*tlmGetBatt(void)); // Function Pointers for user provided functions that return the Temp and Battery Voltage data for the TLM field.
-        int(*tlmGetTemp(void)); // ^^
-    };
-
-
     /*
     *  Set Eddystone UID Frame information.
     *  @param[in] power   TX Power in dB measured at 0 meters from the device. Range of -100 to +20 dB.
@@ -352,13 +328,13 @@
             // state machine to control which packet is being sent
             switch(frameIndex) {
                 case 0: // TLM Frame
-                    switchFrame.attach_us(this, &Eddystone::swapOutFrames, EDDYSTONE_SWAPFRAME_DELAYMS);
+                    switchFrame.attach_us(this, &EddystoneService::swapOutFrames, EDDYSTONE_SWAPFRAME_DELAYMS);
                     switchFlag = true;
                     break;
                 case 1: // URL Frame
                     // switch out packets
                     if(switchFlag) {
-                        switchFrame.attach_us(this, &Eddystone::swapOutFrames, EDDYSTONE_SWAPFRAME_DELAYMS);
+                        switchFrame.attach_us(this, &EddystoneService::swapOutFrames, EDDYSTONE_SWAPFRAME_DELAYMS);
                         switchFlag = false;
                     } else {
                         if((TlmPduCount % 10) == 0) { // every 10 adv packets switch the frame
@@ -369,7 +345,7 @@
                 case 2: // UIDFrame
                     // switch out packets
                     if(switchFlag ) {
-                        switchFrame.attach_us(this, &Eddystone::swapOutFrames, EDDYSTONE_SWAPFRAME_DELAYMS);
+                        switchFrame.attach_us(this, &EddystoneService::swapOutFrames, EDDYSTONE_SWAPFRAME_DELAYMS);
                         switchFlag = false;
                     } else {
                         if((TlmPduCount % 10) == 0) { // every 10 adv packets switch the frame
@@ -397,7 +373,7 @@
     *   @param tlmVersion version of telemetry data field to use (default to 0x00)
     *
     */
-    Eddystone(BLEDevice       &bleIn,
+    EddystoneService(BLEDevice       &bleIn,
               uint16_t        beaconPeriodus = 100,
               uint8_t         txPowerLevel = 0,
               uint8_t *       uidNamespaceID = NULL,
@@ -449,8 +425,8 @@
 
         updateAdvPacket(serviceData, serviceDataLen);
         ble.gap().startAdvertising();
-        ble.gap().onRadioNotification(this,&Eddystone::radioNotificationCallback);
-        timeSinceBootTick.attach(this,&Eddystone::tsbCallback,0.1); // incriment the TimeSinceBoot ticker every 0.1s
+        ble.gap().onRadioNotification(this,&EddystoneService::radioNotificationCallback);
+        timeSinceBootTick.attach(this,&EddystoneService::tsbCallback,0.1); // incriment the TimeSinceBoot ticker every 0.1s
 
     }
 
@@ -458,7 +434,6 @@
 
 
     BLEDevice           &ble;
-    Params_t            &params;
     Ticker              timeSinceBootTick;
     Timeout             switchFrame;
 // Default value that is restored on reset
@@ -471,11 +446,6 @@
     uint16_t            uidRFU;
     bool                uidIsSet;
     bool                urlIsSet;
-// Default value that is restored on reset
-    PowerLevels_t       &defaultAdvPowerLevels;
-    uint8_t             lockedState;
-    bool                initSucceeded;
-    uint8_t             resetFlag;
     bool switchFlag;
 
 // Private Variables for Telemetry Data