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
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
main.cpp@8:f53d48e5d64f, 2016-09-20 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Tue Sep 20 14:21:04 2016 +0100
- Revision:
- 8:f53d48e5d64f
- Parent:
- 6:321047f0190a
Update libraries and add support of ST shield.
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:321047f0190a | 19 | #include "EddystoneService.h" |
mbedAustin | 0:f528fb53a9ef | 20 | |
andresag | 6:321047f0190a | 21 | EddystoneService *eddyServicePtr; |
andresag | 6:321047f0190a | 22 | |
andresag | 6:321047f0190a | 23 | /* Duration after power-on that config service is available. */ |
andresag | 6:321047f0190a | 24 | static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 30; |
mbedAustin | 0:f528fb53a9ef | 25 | |
mbedAustin | 0:f528fb53a9ef | 26 | Ticker configAdvertisementTimeout; |
mbedAustin | 0:f528fb53a9ef | 27 | |
mbedAustin | 0:f528fb53a9ef | 28 | /** |
mbedAustin | 0:f528fb53a9ef | 29 | * Stop advertising the Config Service after a delay; and switch to a non-connectable advertising mode only beacon. |
mbedAustin | 0:f528fb53a9ef | 30 | */ |
mbedAustin | 0:f528fb53a9ef | 31 | void timeout(void) |
mbedAustin | 0:f528fb53a9ef | 32 | { |
mbedAustin | 0:f528fb53a9ef | 33 | Gap::GapState_t state; |
andresag | 6:321047f0190a | 34 | state = BLE::Instance(BLE::DEFAULT_INSTANCE).gap().getState(); |
mbedAustin | 0:f528fb53a9ef | 35 | if (!state.connected) { /* don't switch if we're in a connected state. */ |
mbedAustin | 0:f528fb53a9ef | 36 | configAdvertisementTimeout.detach(); /* disable the callback from the timeout Ticker. */ |
andresag | 6:321047f0190a | 37 | eddyServicePtr->startBeaconService(5, 5, 5); |
mbedAustin | 0:f528fb53a9ef | 38 | } |
mbedAustin | 0:f528fb53a9ef | 39 | } |
mbedAustin | 0:f528fb53a9ef | 40 | |
mbedAustin | 0:f528fb53a9ef | 41 | /** |
mbedAustin | 0:f528fb53a9ef | 42 | * Callback triggered upon a disconnection event. |
mbedAustin | 0:f528fb53a9ef | 43 | */ |
mbedAustin | 1:5b266d95731f | 44 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *cbParams) |
mbedAustin | 0:f528fb53a9ef | 45 | { |
andresag | 6:321047f0190a | 46 | (void) cbParams; |
andresag | 6:321047f0190a | 47 | BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising(); |
andresag | 6:321047f0190a | 48 | } |
andresag | 6:321047f0190a | 49 | |
andresag | 6:321047f0190a | 50 | void onBleInitError(BLE::InitializationCompleteCallbackContext* initContext) |
andresag | 6:321047f0190a | 51 | { |
andresag | 6:321047f0190a | 52 | /* Initialization error handling goes here... */ |
andresag | 6:321047f0190a | 53 | (void) initContext; |
andresag | 6:321047f0190a | 54 | } |
andresag | 6:321047f0190a | 55 | |
andresag | 6:321047f0190a | 56 | void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext) |
andresag | 6:321047f0190a | 57 | { |
andresag | 6:321047f0190a | 58 | BLE &ble = initContext->ble; |
andresag | 6:321047f0190a | 59 | ble_error_t error = initContext->error; |
andresag | 6:321047f0190a | 60 | |
andresag | 6:321047f0190a | 61 | if (error != BLE_ERROR_NONE) { |
andresag | 6:321047f0190a | 62 | onBleInitError(initContext); |
andresag | 6:321047f0190a | 63 | return; |
mbedAustin | 0:f528fb53a9ef | 64 | } |
andresag | 6:321047f0190a | 65 | |
andresag | 6:321047f0190a | 66 | ble.gap().onDisconnection(disconnectionCallback); |
andresag | 6:321047f0190a | 67 | |
andresag | 6:321047f0190a | 68 | /* Set UID and TLM frame data */ |
andresag | 6:321047f0190a | 69 | const UIDNamespaceID_t uidNamespaceID = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; |
andresag | 6:321047f0190a | 70 | const UIDInstanceID_t uidInstanceID = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; |
andresag | 6:321047f0190a | 71 | uint8_t tlmVersion = 0x00; |
andresag | 6:321047f0190a | 72 | |
andresag | 6:321047f0190a | 73 | /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */ |
andresag | 6:321047f0190a | 74 | 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 | 6:321047f0190a | 75 | static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; // Values for radio power levels, provided by manufacturer. |
andresag | 6:321047f0190a | 76 | |
andresag | 6:321047f0190a | 77 | /* Set everything to defaults */ |
andresag | 6:321047f0190a | 78 | eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels, 500); |
andresag | 6:321047f0190a | 79 | |
andresag | 6:321047f0190a | 80 | /* Set default URL, UID and TLM frame data if not initialized through the config service */ |
andresag | 6:321047f0190a | 81 | eddyServicePtr->setURLData("http://mbed.org"); |
andresag | 6:321047f0190a | 82 | eddyServicePtr->setUIDData(&uidNamespaceID, &uidInstanceID); |
andresag | 6:321047f0190a | 83 | eddyServicePtr->setTLMData(tlmVersion); |
andresag | 6:321047f0190a | 84 | |
andresag | 6:321047f0190a | 85 | /* Start Eddystone in config mode */ |
andresag | 6:321047f0190a | 86 | eddyServicePtr->startConfigService(); |
andresag | 6:321047f0190a | 87 | |
andresag | 6:321047f0190a | 88 | configAdvertisementTimeout.attach(timeout, CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS); |
mbedAustin | 0:f528fb53a9ef | 89 | } |
mbedAustin | 0:f528fb53a9ef | 90 | |
mbedAustin | 0:f528fb53a9ef | 91 | int main(void) |
mbedAustin | 0:f528fb53a9ef | 92 | { |
andresag | 6:321047f0190a | 93 | BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); |
andresag | 6:321047f0190a | 94 | ble.init(bleInitComplete); |
mbedAustin | 0:f528fb53a9ef | 95 | |
andresag | 6:321047f0190a | 96 | /* SpinWait for initialization to complete. This is necessary because the |
andresag | 6:321047f0190a | 97 | * BLE object is used in the main loop below. */ |
andresag | 6:321047f0190a | 98 | while (ble.hasInitialized() == false) { /* spin loop */ } |
mbedAustin | 0:f528fb53a9ef | 99 | |
andresag | 6:321047f0190a | 100 | while (true) { |
andresag | 6:321047f0190a | 101 | ble.waitForEvent(); /* this will return upon any system event (such as an interrupt or a ticker wakeup) */ |
andresag | 5:fbd10ac20d91 | 102 | } |
andresag | 6:321047f0190a | 103 | } |