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.
Committer:
Vincent Coubard
Date:
Tue Sep 20 14:13:43 2016 +0100
Revision:
36:17b4a0ff9abb
Parent:
34:f6d4a699a1ea
Update libraries and add support of the ST shield.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:c04d932e96c9 1 /* mbed Microcontroller Library
mbedAustin 32:41840b78597e 2 * Copyright (c) 2006-2013 ARM Limited
screamer 0:c04d932e96c9 3 *
screamer 0:c04d932e96c9 4 * Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:c04d932e96c9 5 * you may not use this file except in compliance with the License.
screamer 0:c04d932e96c9 6 * You may obtain a copy of the License at
screamer 0:c04d932e96c9 7 *
screamer 0:c04d932e96c9 8 * http://www.apache.org/licenses/LICENSE-2.0
screamer 0:c04d932e96c9 9 *
screamer 0:c04d932e96c9 10 * Unless required by applicable law or agreed to in writing, software
screamer 0:c04d932e96c9 11 * distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:c04d932e96c9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:c04d932e96c9 13 * See the License for the specific language governing permissions and
screamer 0:c04d932e96c9 14 * limitations under the License.
screamer 0:c04d932e96c9 15 */
screamer 0:c04d932e96c9 16
screamer 0:c04d932e96c9 17 #include "mbed.h"
andresag 34:f6d4a699a1ea 18 #include "ble/BLE.h"
andresag 34:f6d4a699a1ea 19 #include "EddystoneService.h"
andresag 34:f6d4a699a1ea 20
andresag 34:f6d4a699a1ea 21 EddystoneService *eddyServicePtr;
screamer 0:c04d932e96c9 22
andresag 34:f6d4a699a1ea 23 void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext)
andresag 34:f6d4a699a1ea 24 {
andresag 34:f6d4a699a1ea 25 /* Initialization error handling goes here... */
andresag 34:f6d4a699a1ea 26 (void) initContext;
andresag 34:f6d4a699a1ea 27 }
mbedAustin 30:6c2db8bf5b17 28
andresag 34:f6d4a699a1ea 29 /*
andresag 34:f6d4a699a1ea 30 * Update TLM frame battery voltage value.
andresag 34:f6d4a699a1ea 31 */
andresag 34:f6d4a699a1ea 32 uint16_t tlmBatteryVoltageCallback(uint16_t prevBatteryVoltage)
andresag 34:f6d4a699a1ea 33 {
andresag 34:f6d4a699a1ea 34 prevBatteryVoltage++;
andresag 34:f6d4a699a1ea 35 return prevBatteryVoltage;
andresag 34:f6d4a699a1ea 36 }
mbedAustin 30:6c2db8bf5b17 37
andresag 34:f6d4a699a1ea 38 /*
andresag 34:f6d4a699a1ea 39 * Update TLM frame beacon temperature value.
andresag 34:f6d4a699a1ea 40 */
andresag 34:f6d4a699a1ea 41 uint16_t tlmBeaconTemperatureCallback(uint16_t prevBeaconTemperature)
andresag 34:f6d4a699a1ea 42 {
andresag 34:f6d4a699a1ea 43 prevBeaconTemperature++;
andresag 34:f6d4a699a1ea 44 return prevBeaconTemperature;
mbedAustin 30:6c2db8bf5b17 45 }
mbedAustin 30:6c2db8bf5b17 46
andresag 34:f6d4a699a1ea 47 void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext)
andresag 34:f6d4a699a1ea 48 {
andresag 34:f6d4a699a1ea 49 BLE &ble = initContext->ble;
andresag 34:f6d4a699a1ea 50 ble_error_t error = initContext->error;
andresag 34:f6d4a699a1ea 51
andresag 34:f6d4a699a1ea 52 if (error != BLE_ERROR_NONE) {
andresag 34:f6d4a699a1ea 53 onBleInitError(initContext);
andresag 34:f6d4a699a1ea 54 return;
andresag 34:f6d4a699a1ea 55 }
andresag 34:f6d4a699a1ea 56
andresag 34:f6d4a699a1ea 57 /* Set UID and TLM frame data */
andresag 34:f6d4a699a1ea 58 const UIDNamespaceID_t uidNamespaceID = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99};
andresag 34:f6d4a699a1ea 59 const UIDInstanceID_t uidInstanceID = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
andresag 34:f6d4a699a1ea 60 uint8_t tlmVersion = 0x00;
andresag 34:f6d4a699a1ea 61
andresag 34:f6d4a699a1ea 62 /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */
andresag 34:f6d4a699a1ea 63 static const PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13}; // Values for ADV packets related to firmware levels, calibrated based on measured values at 1m
andresag 34:f6d4a699a1ea 64 static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; // Values for radio power levels, provided by manufacturer.
andresag 34:f6d4a699a1ea 65
andresag 34:f6d4a699a1ea 66 /* Set everything to defaults */
andresag 34:f6d4a699a1ea 67 eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels);
andresag 34:f6d4a699a1ea 68
andresag 34:f6d4a699a1ea 69 /* Set default URL, UID and TLM frame data if not initialized through the config service */
andresag 34:f6d4a699a1ea 70 eddyServicePtr->setURLData("http://mbed.org");
andresag 34:f6d4a699a1ea 71 eddyServicePtr->setUIDData(&uidNamespaceID, &uidInstanceID);
andresag 34:f6d4a699a1ea 72 eddyServicePtr->setTLMData(tlmVersion);
andresag 34:f6d4a699a1ea 73
andresag 34:f6d4a699a1ea 74 /* Set battery voltage and temperature callbacks */
andresag 34:f6d4a699a1ea 75 eddyServicePtr->onTLMBatteryVoltageUpdate(tlmBatteryVoltageCallback);
andresag 34:f6d4a699a1ea 76 eddyServicePtr->onTLMBeaconTemperatureUpdate(tlmBeaconTemperatureCallback);
andresag 34:f6d4a699a1ea 77
andresag 34:f6d4a699a1ea 78 /* Start Eddystone in config mode */
andresag 34:f6d4a699a1ea 79 eddyServicePtr->startBeaconService(5, 5, 5);
mbedAustin 30:6c2db8bf5b17 80 }
screamer 0:c04d932e96c9 81
screamer 0:c04d932e96c9 82 int main(void)
screamer 0:c04d932e96c9 83 {
andresag 34:f6d4a699a1ea 84 BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
andresag 34:f6d4a699a1ea 85 ble.init(bleInitComplete);
andresag 34:f6d4a699a1ea 86
andresag 34:f6d4a699a1ea 87 /* SpinWait for initialization to complete. This is necessary because the
andresag 34:f6d4a699a1ea 88 * BLE object is used in the main loop below. */
andresag 34:f6d4a699a1ea 89 while (ble.hasInitialized() == false) { /* spin loop */ }
mbedAustin 32:41840b78597e 90
screamer 0:c04d932e96c9 91 while (true) {
andresag 34:f6d4a699a1ea 92 ble.waitForEvent(); /* this will return upon any system event (such as an interrupt or a ticker wakeup) */
screamer 0:c04d932e96c9 93 }
screamer 0:c04d932e96c9 94 }