The eddystone config service allows you to configure the eddystone frame data over BLE for a set period of time and then starts an eddystone beacon. This example defaults to 30 seconds of config time.

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_EddystoneBeaconConfigServiceRelease by Austin Blackstone

This is the eddystone config service. This code starts up and for a user configured time period (default 30 seconds) will advertise the configuration service.

The configuration service allows for modifying various frames of the eddystone specification.

For more details on the Configuration Service please see : https://github.com/google/eddystone/blob/master/eddystone-url/docs/config-service-spec.md

Committer:
andresag
Date:
Tue Nov 24 11:56:20 2015 +0000
Revision:
5:fbd10ac20d91
Parent:
4:2dd4bacf1cb8
Child:
6:321047f0190a
Revert changes to old Eddystone implementation in ble/services.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 0:f528fb53a9ef 1 /* mbed Microcontroller Library
mbedAustin 0:f528fb53a9ef 2 * Copyright (c) 2006-2013 ARM Limited
mbedAustin 0:f528fb53a9ef 3 *
mbedAustin 0:f528fb53a9ef 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbedAustin 0:f528fb53a9ef 5 * you may not use this file except in compliance with the License.
mbedAustin 0:f528fb53a9ef 6 * You may obtain a copy of the License at
mbedAustin 0:f528fb53a9ef 7 *
mbedAustin 0:f528fb53a9ef 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 0:f528fb53a9ef 9 *
mbedAustin 0:f528fb53a9ef 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 0:f528fb53a9ef 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbedAustin 0:f528fb53a9ef 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 0:f528fb53a9ef 13 * See the License for the specific language governing permissions and
mbedAustin 0:f528fb53a9ef 14 * limitations under the License.
mbedAustin 0:f528fb53a9ef 15 */
mbedAustin 0:f528fb53a9ef 16
mbedAustin 0:f528fb53a9ef 17 #include "mbed.h"
mbedAustin 0:f528fb53a9ef 18 #include "ble/BLE.h"
andresag 5:fbd10ac20d91 19 #include "ble/services/EddystoneConfigService.h"
andresag 5:fbd10ac20d91 20 #include "ConfigParamsPersistence.h"
andresag 5:fbd10ac20d91 21
andresag 5:fbd10ac20d91 22 BLE ble;
andresag 5:fbd10ac20d91 23 EddystoneConfigService *EddystoneBeaconConfig;
andresag 5:fbd10ac20d91 24 EddystoneConfigService::Params_t params;
mbedAustin 0:f528fb53a9ef 25
andresag 5:fbd10ac20d91 26 /**
andresag 5:fbd10ac20d91 27 * URIBeaconConfig service can operate in two modes: a configuration mode which
andresag 5:fbd10ac20d91 28 * allows a user to update settings over a connection; and normal URIBeacon mode
andresag 5:fbd10ac20d91 29 * which involves advertising a URI. Constructing an object from URIBeaconConfig
andresag 5:fbd10ac20d91 30 * service sets up advertisements for the configuration mode. It is then up to
andresag 5:fbd10ac20d91 31 * the application to switch to URIBeacon mode based on some timeout.
andresag 5:fbd10ac20d91 32 *
andresag 5:fbd10ac20d91 33 * The following help with this switch.
andresag 5:fbd10ac20d91 34 */
andresag 5:fbd10ac20d91 35 static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 30; // Duration after power-on that config service is available.
mbedAustin 0:f528fb53a9ef 36
mbedAustin 0:f528fb53a9ef 37 Ticker configAdvertisementTimeout;
mbedAustin 0:f528fb53a9ef 38
mbedAustin 0:f528fb53a9ef 39 /**
mbedAustin 0:f528fb53a9ef 40 * Stop advertising the Config Service after a delay; and switch to a non-connectable advertising mode only beacon.
mbedAustin 0:f528fb53a9ef 41 */
mbedAustin 0:f528fb53a9ef 42 void timeout(void)
mbedAustin 0:f528fb53a9ef 43 {
mbedAustin 0:f528fb53a9ef 44 Gap::GapState_t state;
andresag 5:fbd10ac20d91 45 state = ble.getGapState();
mbedAustin 0:f528fb53a9ef 46 if (!state.connected) { /* don't switch if we're in a connected state. */
mbedAustin 0:f528fb53a9ef 47 configAdvertisementTimeout.detach(); /* disable the callback from the timeout Ticker. */
andresag 5:fbd10ac20d91 48 EddystoneBeaconConfig->setupEddystoneAdvertisements();
mbedAustin 0:f528fb53a9ef 49 }
mbedAustin 0:f528fb53a9ef 50 }
mbedAustin 0:f528fb53a9ef 51
mbedAustin 0:f528fb53a9ef 52 /**
mbedAustin 0:f528fb53a9ef 53 * Callback triggered upon a disconnection event.
mbedAustin 0:f528fb53a9ef 54 */
mbedAustin 1:5b266d95731f 55 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *cbParams)
mbedAustin 0:f528fb53a9ef 56 {
andresag 5:fbd10ac20d91 57 if (true == params.isConfigured){
andresag 5:fbd10ac20d91 58 // end advertising, the beacon is configured
andresag 5:fbd10ac20d91 59 timeout();
mbedAustin 0:f528fb53a9ef 60 }
andresag 5:fbd10ac20d91 61 else{
andresag 5:fbd10ac20d91 62 // eddystone is not configured, continue advertising
andresag 5:fbd10ac20d91 63 ble.gap().startAdvertising();
andresag 5:fbd10ac20d91 64 }
mbedAustin 0:f528fb53a9ef 65 }
mbedAustin 0:f528fb53a9ef 66
mbedAustin 0:f528fb53a9ef 67 int main(void)
mbedAustin 0:f528fb53a9ef 68 {
andresag 5:fbd10ac20d91 69 ble.init();
andresag 5:fbd10ac20d91 70 ble.gap().onDisconnection(disconnectionCallback);
mbedAustin 0:f528fb53a9ef 71
andresag 5:fbd10ac20d91 72 /*
andresag 5:fbd10ac20d91 73 * Load parameters from (platform specific) persistent storage. Parameters
andresag 5:fbd10ac20d91 74 * can be set to non-default values while the URIBeacon is in configuration
andresag 5:fbd10ac20d91 75 * mode (within the first 60 seconds of power-up). Thereafter, parameters
andresag 5:fbd10ac20d91 76 * get copied out to persistent storage before switching to normal URIBeacon
andresag 5:fbd10ac20d91 77 * operation.
andresag 5:fbd10ac20d91 78 */
andresag 5:fbd10ac20d91 79 bool fetchedFromPersistentStorage = loadURIBeaconConfigParams(&params);
andresag 5:fbd10ac20d91 80
andresag 5:fbd10ac20d91 81 // Set UID and TLM frame data
andresag 5:fbd10ac20d91 82 EddystoneConfigService::UIDNamespaceID_t uidNamespaceID = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; // 10Byte Namespace UUID
andresag 5:fbd10ac20d91 83 EddystoneConfigService::UIDInstanceID_t uidInstanceID = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; // 6Byte Instance ID
andresag 5:fbd10ac20d91 84 uint8_t tlmVersion = 0x00;
andresag 5:fbd10ac20d91 85
andresag 5:fbd10ac20d91 86 /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */
andresag 5:fbd10ac20d91 87 static EddystoneConfigService::PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13}; // Values for ADV packets related to firmware levels, calibrated based on measured values at 1m
andresag 5:fbd10ac20d91 88 static EddystoneConfigService::PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; // Values for radio power levels, provided by manufacturer.
mbedAustin 0:f528fb53a9ef 89
andresag 5:fbd10ac20d91 90 // Create Eddystone Config Service object
andresag 5:fbd10ac20d91 91 EddystoneBeaconConfig = new EddystoneConfigService(ble, params, defaultAdvPowerLevels, radioPowerLevels);
andresag 5:fbd10ac20d91 92
andresag 5:fbd10ac20d91 93 // Set default URI, UID and TLM frame data if not initialized through the config service
andresag 5:fbd10ac20d91 94 EddystoneBeaconConfig->setDefaultURIFrameData("http://mbed.net/bcn",2);
andresag 5:fbd10ac20d91 95 EddystoneBeaconConfig->setDefaultUIDFrameData(&uidNamespaceID, &uidInstanceID,5);
andresag 5:fbd10ac20d91 96 EddystoneBeaconConfig->setDefaultTLMFrameData(tlmVersion,10);
andresag 5:fbd10ac20d91 97
andresag 5:fbd10ac20d91 98 // start the config service
andresag 5:fbd10ac20d91 99 EddystoneBeaconConfig->start(!fetchedFromPersistentStorage);
andresag 5:fbd10ac20d91 100
andresag 5:fbd10ac20d91 101 if (!EddystoneBeaconConfig->initSuccessfully()) {
andresag 5:fbd10ac20d91 102 error("failed to accommodate URI");
andresag 5:fbd10ac20d91 103 }
andresag 5:fbd10ac20d91 104 configAdvertisementTimeout.attach(timeout, CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS);
andresag 5:fbd10ac20d91 105
andresag 5:fbd10ac20d91 106 ble.gap().startAdvertising(); /* Set the whole thing in motion. After this call a GAP central can scan the EddystoneBeaconConfig
andresag 5:fbd10ac20d91 107 * service. This can then be switched to the normal URIBeacon functionality after a timeout. */
mbedAustin 0:f528fb53a9ef 108 while (true) {
andresag 5:fbd10ac20d91 109 ble.waitForEvent();
mbedAustin 0:f528fb53a9ef 110 }
andresag 5:fbd10ac20d91 111 }