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 10:04:38 2015 +0000
Revision:
3:d0f3e00cbfdf
Parent:
2:378323d1b4d9
Child:
4:2dd4bacf1cb8
Update example to use new Eddystone implementation NOT included 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 3:d0f3e00cbfdf 19 #include "EddystoneService.h"
mbedAustin 0:f528fb53a9ef 20
andresag 3:d0f3e00cbfdf 21 EddystoneService *eddyServicePtr;
mbedAustin 0:f528fb53a9ef 22
mbedAustin 0:f528fb53a9ef 23 /**
mbedAustin 0:f528fb53a9ef 24 * URIBeaconConfig service can operate in two modes: a configuration mode which
mbedAustin 0:f528fb53a9ef 25 * allows a user to update settings over a connection; and normal URIBeacon mode
mbedAustin 0:f528fb53a9ef 26 * which involves advertising a URI. Constructing an object from URIBeaconConfig
mbedAustin 0:f528fb53a9ef 27 * service sets up advertisements for the configuration mode. It is then up to
mbedAustin 0:f528fb53a9ef 28 * the application to switch to URIBeacon mode based on some timeout.
mbedAustin 0:f528fb53a9ef 29 *
mbedAustin 0:f528fb53a9ef 30 * The following help with this switch.
mbedAustin 0:f528fb53a9ef 31 */
mbedAustin 0:f528fb53a9ef 32 static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 30; // Duration after power-on that config service is available.
mbedAustin 0:f528fb53a9ef 33
mbedAustin 0:f528fb53a9ef 34 Ticker configAdvertisementTimeout;
mbedAustin 0:f528fb53a9ef 35
mbedAustin 0:f528fb53a9ef 36 /**
mbedAustin 0:f528fb53a9ef 37 * Stop advertising the Config Service after a delay; and switch to a non-connectable advertising mode only beacon.
mbedAustin 0:f528fb53a9ef 38 */
mbedAustin 0:f528fb53a9ef 39 void timeout(void)
mbedAustin 0:f528fb53a9ef 40 {
mbedAustin 0:f528fb53a9ef 41 Gap::GapState_t state;
andresag 3:d0f3e00cbfdf 42 state = BLE::Instance(BLE::DEFAULT_INSTANCE).getGapState();
mbedAustin 0:f528fb53a9ef 43 if (!state.connected) { /* don't switch if we're in a connected state. */
mbedAustin 0:f528fb53a9ef 44 configAdvertisementTimeout.detach(); /* disable the callback from the timeout Ticker. */
andresag 3:d0f3e00cbfdf 45 eddyServicePtr->startBeaconService(5, 5, 5);
mbedAustin 0:f528fb53a9ef 46 }
mbedAustin 0:f528fb53a9ef 47 }
mbedAustin 0:f528fb53a9ef 48
mbedAustin 0:f528fb53a9ef 49 /**
mbedAustin 0:f528fb53a9ef 50 * Callback triggered upon a disconnection event.
mbedAustin 0:f528fb53a9ef 51 */
mbedAustin 1:5b266d95731f 52 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *cbParams)
mbedAustin 0:f528fb53a9ef 53 {
andresag 3:d0f3e00cbfdf 54 (void) cbParams;
andresag 3:d0f3e00cbfdf 55 BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
andresag 3:d0f3e00cbfdf 56 }
andresag 3:d0f3e00cbfdf 57
andresag 3:d0f3e00cbfdf 58 void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext)
andresag 3:d0f3e00cbfdf 59 {
andresag 3:d0f3e00cbfdf 60 /* Initialization error handling goes here... */
andresag 3:d0f3e00cbfdf 61 (void) initContext;
andresag 3:d0f3e00cbfdf 62 }
andresag 3:d0f3e00cbfdf 63
andresag 3:d0f3e00cbfdf 64 void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext)
andresag 3:d0f3e00cbfdf 65 {
andresag 3:d0f3e00cbfdf 66 BLE &ble = initContext->ble;
andresag 3:d0f3e00cbfdf 67 ble_error_t error = initContext->error;
andresag 3:d0f3e00cbfdf 68
andresag 3:d0f3e00cbfdf 69 if (error != BLE_ERROR_NONE) {
andresag 3:d0f3e00cbfdf 70 onBleInitError(initContext);
andresag 3:d0f3e00cbfdf 71 return;
mbedAustin 0:f528fb53a9ef 72 }
andresag 3:d0f3e00cbfdf 73
andresag 3:d0f3e00cbfdf 74 ble.gap().onDisconnection(disconnectionCallback);
andresag 3:d0f3e00cbfdf 75
andresag 3:d0f3e00cbfdf 76 /* Set UID and TLM frame data */
andresag 3:d0f3e00cbfdf 77 const UIDNamespaceID_t uidNamespaceID = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99};
andresag 3:d0f3e00cbfdf 78 const UIDInstanceID_t uidInstanceID = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
andresag 3:d0f3e00cbfdf 79 uint8_t tlmVersion = 0x00;
andresag 3:d0f3e00cbfdf 80
andresag 3:d0f3e00cbfdf 81 /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */
andresag 3:d0f3e00cbfdf 82 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 3:d0f3e00cbfdf 83 static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; // Values for radio power levels, provided by manufacturer.
andresag 3:d0f3e00cbfdf 84
andresag 3:d0f3e00cbfdf 85 /* Set everything to defaults */
andresag 3:d0f3e00cbfdf 86 eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels, 500);
andresag 3:d0f3e00cbfdf 87
andresag 3:d0f3e00cbfdf 88 /* Set default URL, UID and TLM frame data if not initialized through the config service */
andresag 3:d0f3e00cbfdf 89 eddyServicePtr->setURLData("http://mbed.org");
andresag 3:d0f3e00cbfdf 90 eddyServicePtr->setUIDData(&uidNamespaceID, &uidInstanceID);
andresag 3:d0f3e00cbfdf 91 eddyServicePtr->setTLMData(tlmVersion);
andresag 3:d0f3e00cbfdf 92
andresag 3:d0f3e00cbfdf 93 /* Start Eddystone in config mode */
andresag 3:d0f3e00cbfdf 94 eddyServicePtr->startConfigService();
andresag 3:d0f3e00cbfdf 95
andresag 3:d0f3e00cbfdf 96 configAdvertisementTimeout.attach(timeout, CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS);
mbedAustin 0:f528fb53a9ef 97 }
mbedAustin 0:f528fb53a9ef 98
mbedAustin 0:f528fb53a9ef 99 int main(void)
mbedAustin 0:f528fb53a9ef 100 {
andresag 3:d0f3e00cbfdf 101 BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
andresag 3:d0f3e00cbfdf 102 ble.init(bleInitComplete);
mbedAustin 0:f528fb53a9ef 103
andresag 3:d0f3e00cbfdf 104 /* SpinWait for initialization to complete. This is necessary because the
andresag 3:d0f3e00cbfdf 105 * BLE object is used in the main loop below. */
andresag 3:d0f3e00cbfdf 106 while (ble.hasInitialized() == false) { /* spin loop */ }
mbedAustin 0:f528fb53a9ef 107
mbedAustin 0:f528fb53a9ef 108 while (true) {
andresag 3:d0f3e00cbfdf 109 ble.waitForEvent(); /* this will return upon any system event (such as an interrupt or a ticker wakeup) */
mbedAustin 0:f528fb53a9ef 110 }
mbedAustin 0:f528fb53a9ef 111 }