Example program for the Eddystone Beacon service.
Dependencies: BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1
Fork of BLE_EddystoneBeacon by
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.
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.
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.
Diff: ZipBeaconConfigService.h
- Revision:
- 14:5a2a104a21a8
- Parent:
- 13:91c356fa928e
- Child:
- 15:af8c24f34a9f
--- a/ZipBeaconConfigService.h Fri Jul 17 21:45:03 2015 +0000 +++ b/ZipBeaconConfigService.h Mon Jul 20 04:29:07 2015 +0000 @@ -35,7 +35,7 @@ static const uint8_t UUID_TX_POWER_MODE_CHAR[] = UUID_URI_BEACON(0x20, 0x87); static const uint8_t UUID_BEACON_PERIOD_CHAR[] = UUID_URI_BEACON(0x20, 0x88); static const uint8_t UUID_RESET_CHAR[] = UUID_URI_BEACON(0x20, 0x89); -static const uint8_t BEACON_UUID[] = {0xAA, 0xFE}; +static const uint8_t BEACON_EDDYSTONE[] = {0xAA, 0xFE}; /** * @class ZipBeaconConfigService @@ -60,7 +60,9 @@ typedef uint8_t Lock_t[16]; /* 128 bits */ typedef int8_t PowerLevels_t[NUM_POWER_MODES]; - + #define EDDYSTONE_MAX_FRAMETYPE 3 + void (*frames[EDDYSTONE_MAX_FRAMETYPE])(uint8_t *, uint32_t); + uint8_t frameIndex; static const int URI_DATA_MAX = 18; typedef uint8_t UriData_t[URI_DATA_MAX]; @@ -90,7 +92,7 @@ UIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B UIDInstanceID_t uidInstanceID; // UUID type, Instance ID, 6B }; - + /** * @param[ref] ble * BLEDevice object for the underlying controller. @@ -370,12 +372,50 @@ TlmTimeSinceBoot = timeSinceBoot; return; } + + /* + * Callback from onRadioNotification(), used to update the PDUCounter and maybe other stuff eventually? + * + * + */ + void pduCountCallback(){ + // Update Time and PDUCount + TlmPduCount++; + TlmTimeSinceBoot += 10; + + // Every 1 second switch the frame types + if((TlmPduCount % 10) == 1){ + frameIndex = frameIndex % EDDYSTONE_MAX_FRAMETYPE; + uint8_t serviceData[SERVICE_DATA_MAX]; + unsigned serviceDataLen = 0; + //switch payloads + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0]; + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1]; + switch(frameIndex){ + case 0: + constructTLMFrame(serviceData+serviceDataLen,20); + break; + case 1: + constructURLFrame(serviceData+serviceDataLen,20); + break; + case 2: + constructUIDFrame(serviceData+serviceDataLen,20); + break; + } + ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen); + } + //TODO: add bit to keep timer / update time + frameIndex++; + return; + } /* Helper function to switch to the non-connectible normal mode for ZipBeacon. This gets called after a timeout. */ void setupZipBeaconAdvertisements() { uint8_t serviceData[SERVICE_DATA_MAX]; unsigned serviceDataLen = 0; + // Initialize Frame transition + frameIndex = 0; /* Reinitialize the BLE stack. This will clear away the existing services and advertising state. */ ble.shutdown(); @@ -397,16 +437,26 @@ ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(beaconPeriod); ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); + ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_EDDYSTONE, sizeof(BEACON_EDDYSTONE)); + + setTLMFrameData(0x00,22,33,0,0); // Initialize TLM Data, for testing, remove for release + updateTlmPduCount(0); + updateTlmTimeSinceBoot(0); + + // Construct TLM Frame in initial advertising. + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0]; + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1]; + constructTLMFrame(serviceData+serviceDataLen,20); +// serviceData[serviceDataLen++] = FRAME_TYPE_URL | flags; +// serviceData[serviceDataLen++] = advPowerLevels[txPowerMode]; +// for (unsigned j = 0; j < uriDataLength; j++) { +// serviceData[serviceDataLen++] = uriData[j]; +// } - serviceData[serviceDataLen++] = BEACON_UUID[0]; - serviceData[serviceDataLen++] = BEACON_UUID[1]; - serviceData[serviceDataLen++] = FRAME_TYPE_URL | flags; - serviceData[serviceDataLen++] = advPowerLevels[txPowerMode]; - for (unsigned j = 0; j < uriDataLength; j++) { - serviceData[serviceDataLen++] = uriData[j]; - } + // attach callback to count number of sent packets + //TODO: ble.gap().onRadioNotification(pduCountCallback); ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen); + //callbackTick.attach(&pduCountCallback,2.0); // switch services every 2 seconds } private: @@ -565,6 +615,7 @@ BLEDevice &ble; Params_t ¶ms; + Ticker callbackTick; // Default value that is restored on reset size_t defaultUriDataLength; UriData_t defaultUriData;