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:
rgrover1
Date:
Sat Jun 20 23:49:59 2015 +0000
Revision:
8:1a21308e5008
Parent:
7:e9800c45e065
Child:
14:5a2a104a21a8
update to the newer APIs; rename BLEDevice with BLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:c04d932e96c9 1 /* mbed Microcontroller Library
screamer 0:c04d932e96c9 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"
rgrover1 7:e9800c45e065 18 #include "BLE.h"
screamer 0:c04d932e96c9 19 #include "ZipBeaconConfigService.h"
screamer 0:c04d932e96c9 20 #include "DFUService.h"
screamer 0:c04d932e96c9 21 #include "DeviceInformationService.h"
rgrover1 2:8020d6d4455a 22 #include "ConfigParamsPersistence.h"
screamer 0:c04d932e96c9 23
rgrover1 8:1a21308e5008 24 BLE ble;
screamer 0:c04d932e96c9 25 ZipBeaconConfigService *zipBeaconConfig;
screamer 0:c04d932e96c9 26
screamer 0:c04d932e96c9 27 /**
screamer 0:c04d932e96c9 28 * URIBeaconConfig service can operate in two modes: a configuration mode which
screamer 0:c04d932e96c9 29 * allows a user to update settings over a connection; and normal URIBeacon mode
screamer 0:c04d932e96c9 30 * which involves advertising a URI. Constructing an object from URIBeaconConfig
screamer 0:c04d932e96c9 31 * service sets up advertisements for the configuration mode. It is then up to
screamer 0:c04d932e96c9 32 * the application to switch to URIBeacon mode based on some timeout.
screamer 0:c04d932e96c9 33 *
screamer 0:c04d932e96c9 34 * The following help with this switch.
screamer 0:c04d932e96c9 35 */
rgrover1 2:8020d6d4455a 36 static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 60; // Duration after power-on that config service is available.
screamer 0:c04d932e96c9 37 Ticker configAdvertisementTimeoutTicker;
screamer 0:c04d932e96c9 38
screamer 0:c04d932e96c9 39 /**
screamer 0:c04d932e96c9 40 * Stop advertising the UriBeaconConfig Service after a delay; and switch to normal URIBeacon.
screamer 0:c04d932e96c9 41 */
screamer 0:c04d932e96c9 42 void timeout(void)
screamer 0:c04d932e96c9 43 {
screamer 0:c04d932e96c9 44 Gap::GapState_t state;
screamer 0:c04d932e96c9 45 state = ble.getGapState();
screamer 0:c04d932e96c9 46 if (!state.connected) { /* don't switch if we're in a connected state. */
screamer 0:c04d932e96c9 47 zipBeaconConfig->setupZipBeaconAdvertisements();
rgrover1 8:1a21308e5008 48 ble.gap().startAdvertising();
screamer 0:c04d932e96c9 49
screamer 0:c04d932e96c9 50 configAdvertisementTimeoutTicker.detach(); /* disable the callback from the timeout Ticker. */
screamer 0:c04d932e96c9 51 }
screamer 0:c04d932e96c9 52 }
screamer 0:c04d932e96c9 53
screamer 0:c04d932e96c9 54 /**
screamer 0:c04d932e96c9 55 * Callback triggered upon a disconnection event. Needs to re-enable advertisements.
screamer 0:c04d932e96c9 56 */
screamer 0:c04d932e96c9 57 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
screamer 0:c04d932e96c9 58 {
rgrover1 8:1a21308e5008 59 ble.gap().startAdvertising();
screamer 0:c04d932e96c9 60 }
screamer 0:c04d932e96c9 61
screamer 0:c04d932e96c9 62 int main(void)
screamer 0:c04d932e96c9 63 {
screamer 0:c04d932e96c9 64 ble.init();
rgrover1 8:1a21308e5008 65 ble.gap().onDisconnection(disconnectionCallback);
screamer 0:c04d932e96c9 66
screamer 0:c04d932e96c9 67 /*
screamer 0:c04d932e96c9 68 * Load parameters from (platform specific) persistent storage. Parameters
screamer 0:c04d932e96c9 69 * can be set to non-default values while the URIBeacon is in configuration
screamer 0:c04d932e96c9 70 * mode (within the first 60 seconds of power-up). Thereafter, parameters
screamer 0:c04d932e96c9 71 * get copied out to persistent storage before switching to normal URIBeacon
screamer 0:c04d932e96c9 72 * operation.
screamer 0:c04d932e96c9 73 */
screamer 0:c04d932e96c9 74 ZipBeaconConfigService::Params_t params;
rgrover1 2:8020d6d4455a 75 bool fetchedFromPersistentStorage = loadURIBeaconConfigParams(&params);
screamer 0:c04d932e96c9 76
screamer 0:c04d932e96c9 77 /* Initialize a zipBeaconConfig service providing config params, default URI, and power levels. */
screamer 0:c04d932e96c9 78 static ZipBeaconConfigService::PowerLevels_t defaultAdvPowerLevels = {-20, -4, 0, 10}; // Values for ADV packets related to firmware levels
rgrover1 2:8020d6d4455a 79 zipBeaconConfig = new ZipBeaconConfigService(ble, params, !fetchedFromPersistentStorage, "http://uribeacon.org", defaultAdvPowerLevels);
screamer 0:c04d932e96c9 80 if (!zipBeaconConfig->configuredSuccessfully()) {
screamer 0:c04d932e96c9 81 error("failed to accommodate URI");
screamer 0:c04d932e96c9 82 }
screamer 0:c04d932e96c9 83 configAdvertisementTimeoutTicker.attach(timeout, CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS);
screamer 0:c04d932e96c9 84
screamer 0:c04d932e96c9 85 // Setup auxiliary services to allow over-the-air firmware updates, etc
screamer 0:c04d932e96c9 86 DFUService dfu(ble);
screamer 0:c04d932e96c9 87 DeviceInformationService deviceInfo(ble, "ARM", "UriBeacon", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
screamer 0:c04d932e96c9 88
rgrover1 8:1a21308e5008 89 ble.gap().startAdvertising(); /* Set the whole thing in motion. After this call a GAP central can scan the zipBeaconConfig
rgrover1 8:1a21308e5008 90 * service. This can then be switched to the normal URIBeacon functionality after a timeout. */
screamer 0:c04d932e96c9 91
screamer 0:c04d932e96c9 92 while (true) {
screamer 0:c04d932e96c9 93 ble.waitForEvent();
screamer 0:c04d932e96c9 94 }
screamer 0:c04d932e96c9 95 }