Example program for the Eddystone Beacon service.

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:
11:73ea4ef7f5a4
Parent:
10:b5d19bcf23cf
Child:
12:ced5e837c511
--- a/ZipBeaconConfigService.h	Fri Jul 17 19:02:54 2015 +0000
+++ b/ZipBeaconConfigService.h	Fri Jul 17 21:06:30 2015 +0000
@@ -60,18 +60,23 @@
     typedef uint8_t Lock_t[16];               /* 128 bits */
     typedef int8_t PowerLevels_t[NUM_POWER_MODES];
 
+    
     static const int URI_DATA_MAX = 18;
     typedef uint8_t  UriData_t[URI_DATA_MAX];
     
+    // UID Frame Type subfields
     static const int UID_NAMESPACEID_SIZE = 10;
-    typedef uint8_t  UIDNamespaceID_t[UUID_NAMESPACEID_SIZE];
-    
+    typedef uint8_t  UIDNamespaceID_t[UID_NAMESPACEID_SIZE];
     static const int UID_INSTANCEID_SIZE = 6;
-    typedef uint8_t  UIDInstanceID_t[UUID_INSTANCEID_SIZE];
+    typedef uint8_t  UIDInstanceID_t[UID_INSTANCEID_SIZE];
 
+    // Eddystone Frame Type ID
     static const uint8_t FRAME_TYPE_UID = 0x00;
     static const uint8_t FRAME_TYPE_URL = 0x10;
     static const uint8_t FRAME_TYPE_TLM = 0x20;
+    
+    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;
@@ -82,8 +87,8 @@
         uint8_t       txPowerMode;    // Firmware power levels used with setTxPower()
         uint16_t      beaconPeriod;
         uint8_t       tlmVersion;     // version of TLM packet
-        UUIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B
-        UUIDInstanceID_t  uidInstanceID;  // UUID type, Instance ID,  6B
+        UIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B
+        UIDInstanceID_t  uidInstanceID;  // UUID type, Instance ID,  6B
     };
 
     /**
@@ -207,12 +212,40 @@
     *  @param RFU         2B of RFU, initialized to 0x0000 and not broadcast, included for future reference. 
     *
     */
-    void setUIDFrameData(int8_t power, UIDNamespaceID_t namespaceID, UIDInstanceID_t instanceID, uint8_t RFU[2] = [0x00,0x00])
+    void setUIDFrameData(int8_t power, UIDNamespaceID_t namespaceID, UIDInstanceID_t instanceID, uint16_t RFU = 0x00)
+    {
+        defaultUidPower = power;
+        memcpy(defaultUidNamespaceID, namespaceID, UID_NAMESPACEID_SIZE);
+        memcpy(defaultUidInstanceID,  instanceID,  UID_INSTANCEID_SIZE);
+        uidRFU = (uint16_t)RFU; // this is probably bad form, but it doesnt really matter yet. 
+        return;
+    }
+    
+    /*
+    *  Construct UID frame from private variables
+    *  @param[in/out] Data pointer to array to store constructed frame in
+    *  @param[in] maxSize number of bytes left in array, effectively how much emtpy space is available to write to
+    *  @return number of bytes used. negative number indicates error message. 
+    */
+    int constructUIDFrame(uint8_t * Data, uint8_t maxSize)
     {
-        defaultUidNamespaceID = namespaceID;
-        defaultUidInstanceID = instanceID;
-        uidRFU = (uint16_t)RFU;
-        return;
+        if(maxSize < FRAME_SIZE_UID){
+            return -1; // not enough space to encode UIDframe in advertising packet. 
+        }
+        int index = 0;
+        Data[index++] = FRAME_TYPE_UID;                     // 1B  Type
+        Data[index++] = defaultUidPower;                    // 1B  Power @ 0meter
+        for(int x = 0; x < UID_NAMESPACEID_SIZE; x++){      // 10B Namespce ID
+            Data[index++] = defaultUidNamespaceID[x];
+            } 
+        for(int x = 0; x< UID_INSTANCEID_SIZE; x++){        // 6B  Instance ID
+            Data[index++] = defaultUidInstanceID[x];
+            }
+        if(0x00 != uidRFU){                                 // 2B RFU, include if non-zero, otherwise ignore
+            Data[index++] = (uint8_t)(uidRFU >> 8);
+            Data[index++] = (uint8_t)uidRFU;
+        }
+        return index;
     }
     
     /*
@@ -223,11 +256,32 @@
     */
     bool setURLFrameData(int8_t power, const char * url)
     {
-        encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting
+        defaultUrlPower = power;
+        encodeURI(url, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting
         if (defaultUriDataLength > URI_DATA_MAX) {
             return true; // error, URL is too big
         }
-        
+        return false;
+    }
+    
+    /*
+    *  Construct URL frame from private variables
+    *  @param[in/out] Data pointer to array to store constructed frame in
+    *  @param[in] maxSize number of bytes left in array, effectively how much emtpy space is available to write to
+    *  @return number of bytes used. negative number indicates error message. 
+    */
+    int constructURLFrame(uint8_t * Data, uint8_t maxSize)
+    {
+        if(maxSize < (2 + defaultUriDataLength)){
+            return -1; // not enough space to encode URL frame in advertising packet. 
+        }
+        int index = 0;
+        Data[index++] = FRAME_TYPE_URL;                     // 1B  Type
+        Data[index++] = defaultUrlPower;                    // 1B  TX Power
+        for(int x = 0; x < defaultUriDataLength; x++){      // 18B of URL Prefix + encoded URL 
+            Data[index++] = defaultUriData[x];
+        }
+        return index;        
     }
     
     /*
@@ -246,6 +300,36 @@
         TlmTimeSinceBoot = timeSinceBoot; // reset
         return;        
     }
+    
+    /*
+    *  Construct TLM frame from private variables
+    *  @param[in/out] Data pointer to array to store constructed frame in
+    *  @param[in] maxSize number of bytes left in array, effectively how much emtpy space is available to write to
+    *  @return number of bytes used. negative number indicates error message. 
+    */
+    int constructTLMFrame(uint8_t * Data, uint8_t maxSize)
+    {
+        if(maxSize < FRAME_SIZE_TLM){       // error, not enough space to add TLM frame. 14B, every time
+            return -1;
+        }
+        int index = 0;
+        Data[index++] = FRAME_TYPE_TLM;                    // Eddystone frame type = Telemetry
+        Data[index++] = TlmVersion;                        // TLM Version Number
+        Data[index++] = (uint8_t)(TlmBatteryVoltage>>0);   // Battery Voltage[0]
+        Data[index++] = (uint8_t)(TlmBatteryVoltage>>8);   // Battery Voltage[1]
+        Data[index++] = (uint8_t)(TlmBeaconTemp>>0);       // Beacon Temp[0]
+        Data[index++] = (uint8_t)(TlmBeaconTemp>>8);       // Beacon Temp[1]
+        Data[index++] = (uint8_t)(TlmPduCount>>0);         // PDU Count [0]
+        Data[index++] = (uint8_t)(TlmPduCount>>8);         // PDU Count [1]
+        Data[index++] = (uint8_t)(TlmPduCount>>16);        // PDU Count [2]
+        Data[index++] = (uint8_t)(TlmPduCount>>24);        // PDU Count [3]
+        Data[index++] = (uint8_t)(TlmTimeSinceBoot>>0);    // Time Since Boot [0]
+        Data[index++] = (uint8_t)(TlmTimeSinceBoot>>8);    // Time Since Boot [1]
+        Data[index++] = (uint8_t)(TlmTimeSinceBoot>>16);   // Time Since Boot [2]
+        Data[index++] = (uint8_t)(TlmTimeSinceBoot>>24);   // Time Since Boot [3]
+        
+        return index;
+    }
 
     /* Helper function to switch to the non-connectible normal mode for ZipBeacon. This gets called after a timeout. */
     void setupZipBeaconAdvertisements()
@@ -445,6 +529,8 @@
     UriData_t           defaultUriData;
     UIDNamespaceID_t    defaultUidNamespaceID;
     UIDInstanceID_t     defaultUidInstanceID;
+    int8_t              defaultUidPower;
+    int8_t              defaultUrlPower;
     uint16_t            uidRFU;
     // Default value that is restored on reset
     PowerLevels_t       &defaultAdvPowerLevels;