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:
- 10:b5d19bcf23cf
- Parent:
- 7:e9800c45e065
- Child:
- 11:73ea4ef7f5a4
--- a/ZipBeaconConfigService.h Thu Jul 02 08:42:21 2015 +0000 +++ b/ZipBeaconConfigService.h Fri Jul 17 19:02:54 2015 +0000 @@ -62,6 +62,12 @@ static const int URI_DATA_MAX = 18; typedef uint8_t UriData_t[URI_DATA_MAX]; + + static const int UID_NAMESPACEID_SIZE = 10; + typedef uint8_t UIDNamespaceID_t[UUID_NAMESPACEID_SIZE]; + + static const int UID_INSTANCEID_SIZE = 6; + typedef uint8_t UIDInstanceID_t[UUID_INSTANCEID_SIZE]; static const uint8_t FRAME_TYPE_UID = 0x00; static const uint8_t FRAME_TYPE_URL = 0x10; @@ -75,6 +81,9 @@ 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 + UUIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B + UUIDInstanceID_t uidInstanceID; // UUID type, Instance ID, 6B }; /** @@ -116,7 +125,7 @@ beaconPeriodChar(UUID_BEACON_PERIOD_CHAR, ¶ms.beaconPeriod), resetChar(UUID_RESET_CHAR, &resetFlag) { - encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); + encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting if (defaultUriDataLength > URI_DATA_MAX) { return; } @@ -165,7 +174,7 @@ * afterwards. */ void setupZipBeaconConfigAdvertisements() { - const char DEVICE_NAME[] = "zipBeacon Config"; + const char DEVICE_NAME[] = "eddystone Config"; ble.clearAdvertisingPayload(); @@ -189,6 +198,54 @@ ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADVERTISING_INTERVAL_MSEC)); } + + /* + * 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. + * @param namespaceID 10B namespace ID + * @param instanceID 6B instance ID + * @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]) + { + defaultUidNamespaceID = namespaceID; + defaultUidInstanceID = instanceID; + uidRFU = (uint16_t)RFU; + return; + } + + /* + * Set Eddystone URL Frame information. + * @param[in] power TX Power in dB measured at 0 meters from the device. + * @param url URL to encode + * @return false on success, true on failure. + */ + bool setURLFrameData(int8_t power, const char * url) + { + encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting + if (defaultUriDataLength > URI_DATA_MAX) { + return true; // error, URL is too big + } + + } + + /* + * Set Eddystone TLM Frame information. + * @param[in] Version of the TLM beacon data format + * @param batteryVoltage in milivolts + * @param beaconTemp in 8.8 floating point notation + * + */ + void setTLMFrameData(uint8_t version, uint16_t batteryVoltage, uint16_t beaconTemp, uint32_t pduCount = 0, uint32_t timeSinceBoot = 0) + { + TlmVersion = version; + TlmBatteryVoltage = batteryVoltage; + TlmBeaconTemp = beaconTemp; + TlmPduCount = pduCount; // reset + TlmTimeSinceBoot = timeSinceBoot; // reset + return; + } /* Helper function to switch to the non-connectible normal mode for ZipBeacon. This gets called after a timeout. */ void setupZipBeaconAdvertisements() @@ -296,6 +353,8 @@ memcpy(params.advPowerLevels, defaultAdvPowerLevels, sizeof(PowerLevels_t)); params.txPowerMode = TX_POWER_MODE_LOW; params.beaconPeriod = 1000; + memcpy(params.uidNamespaceID, defaultUidNamespaceID, UID_NAMESPACEID_SIZE); + memcpy(params.uidInstanceID, defaultUidInstanceID, UID_INSTANCEID_SIZE); updateCharacteristicValues(); } @@ -379,16 +438,26 @@ } } - BLEDevice &ble; - Params_t ¶ms; + BLEDevice &ble; + Params_t ¶ms; + // Default value that is restored on reset + size_t defaultUriDataLength; + UriData_t defaultUriData; + UIDNamespaceID_t defaultUidNamespaceID; + UIDInstanceID_t defaultUidInstanceID; + uint16_t uidRFU; // Default value that is restored on reset - size_t defaultUriDataLength; - UriData_t defaultUriData; - // Default value that is restored on reset - PowerLevels_t &defaultAdvPowerLevels; - uint8_t lockedState; - bool initSucceeded; - uint8_t resetFlag; + PowerLevels_t &defaultAdvPowerLevels; + uint8_t lockedState; + bool initSucceeded; + uint8_t resetFlag; + + // Private Variables for Telemetry Data + uint8_t TlmVersion; + uint16_t TlmBatteryVoltage; + uint16_t TlmBeaconTemp; + uint32_t TlmPduCount; + uint32_t TlmTimeSinceBoot; ReadOnlyGattCharacteristic<uint8_t> lockedStateChar; WriteOnlyGattCharacteristic<Lock_t> lockChar;