From a429e8c42652ce9fc9940614f828a0d249422cf5 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 9 Feb 2016 09:39:48 +0000 Subject: [PATCH 01/10] Refactor Eddystone PersistentStorageHelper The PersistentStorageHelper is modified to easily allow other implementations for non-nRF51 devices to be added to this example. --- .../ConfigParamsPersistence.cpp | 45 +++++++++++++++++++ .../ConfigParamsPersistence.h | 6 +-- .../nrfConfigParamsPersistence.cpp | 2 +- BLE_EddystoneService/source/main.cpp | 11 +---- 4 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.cpp rename BLE_EddystoneService/source/{nrfPersistentStorageHelper => PersistentStorageHelper}/ConfigParamsPersistence.h (93%) rename BLE_EddystoneService/source/{ => PersistentStorageHelper}/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp (99%) diff --git a/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.cpp b/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.cpp new file mode 100644 index 00000000000..851047e852b --- /dev/null +++ b/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.cpp @@ -0,0 +1,45 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2015 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ConfigParamsPersistence.h" + +#ifndef TARGET_NRF51822 /* Persistent storage supported on nrf51 platforms */ + /** + * When not using an nRF51-based target then persistent storage is not available. + */ + #warning "EddystoneService is not configured to store configuration data in non-volatile memory" + + bool loadEddystoneServiceConfigParams(EddystoneService::EddystoneParams_t *paramsP) + { + /* Avoid compiler warnings */ + (void) paramsP; + + /* + * Do nothing and let the main program set Eddystone params to + * defaults + */ + return false; + } + + void saveEddystoneServiceConfigParams(const EddystoneService::EddystoneParams_t *paramsP) + { + /* Avoid compiler warnings */ + (void) paramsP; + + /* Do nothing... */ + return; + } +#endif /* #ifdef TARGET_NRF51822 */ diff --git a/BLE_EddystoneService/source/nrfPersistentStorageHelper/ConfigParamsPersistence.h b/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h similarity index 93% rename from BLE_EddystoneService/source/nrfPersistentStorageHelper/ConfigParamsPersistence.h rename to BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h index af59b9eb016..3a7bb62d40a 100644 --- a/BLE_EddystoneService/source/nrfPersistentStorageHelper/ConfigParamsPersistence.h +++ b/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h @@ -14,12 +14,10 @@ * limitations under the License. */ -#ifdef TARGET_NRF51822 /* Persistent storage supported on nrf51 platforms */ - #ifndef __BLE_CONFIG_PARAMS_PERSISTENCE_H__ #define __BLE_CONFIG_PARAMS_PERSISTENCE_H__ -#include "../EddystoneService.h" +#include "EddystoneService.h" /** * Generic API to load the Eddystone Service configuration parameters from persistent @@ -53,5 +51,3 @@ bool loadEddystoneServiceConfigParams(EddystoneService::EddystoneParams_t *param void saveEddystoneServiceConfigParams(const EddystoneService::EddystoneParams_t *paramsP); #endif /* #ifndef __BLE_CONFIG_PARAMS_PERSISTENCE_H__*/ - -#endif /* #ifdef TARGET_NRF51822 */ diff --git a/BLE_EddystoneService/source/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp b/BLE_EddystoneService/source/PersistentStorageHelper/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp similarity index 99% rename from BLE_EddystoneService/source/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp rename to BLE_EddystoneService/source/PersistentStorageHelper/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp index 732b8661882..4c34a10ce08 100644 --- a/BLE_EddystoneService/source/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp +++ b/BLE_EddystoneService/source/PersistentStorageHelper/nrfPersistentStorageHelper/nrfConfigParamsPersistence.cpp @@ -21,7 +21,7 @@ extern "C" { } #include "nrf_error.h" -#include "ConfigParamsPersistence.h" +#include "../../EddystoneService.h" /** * Nordic specific structure used to store params persistently. diff --git a/BLE_EddystoneService/source/main.cpp b/BLE_EddystoneService/source/main.cpp index 3beb04e9380..a74991b1480 100644 --- a/BLE_EddystoneService/source/main.cpp +++ b/BLE_EddystoneService/source/main.cpp @@ -18,9 +18,7 @@ #include "ble/BLE.h" #include "EddystoneService.h" -#ifdef TARGET_NRF51822 - #include "nrfPersistentStorageHelper/ConfigParamsPersistence.h" -#endif +#include "PersistentStorageHelper/ConfigParamsPersistence.h" EddystoneService *eddyServicePtr; @@ -68,11 +66,9 @@ static void timeout(void) state = BLE::Instance().gap().getState(); if (!state.connected) { /* don't switch if we're in a connected state. */ eddyServicePtr->startBeaconService(); -#ifdef TARGET_NRF51822 EddystoneService::EddystoneParams_t params; eddyServicePtr->getEddystoneParams(params); saveEddystoneServiceConfigParams(¶ms); -#endif } else { minar::Scheduler::postCallback(timeout).delay(minar::milliseconds(CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS * 1000)); } @@ -112,17 +108,12 @@ static void bleInitComplete(BLE::InitializationCompleteCallbackContext* initCont ble.gap().onDisconnection(disconnectionCallback); -#ifdef TARGET_NRF51822 EddystoneService::EddystoneParams_t params; if (loadEddystoneServiceConfigParams(¶ms)) { eddyServicePtr = new EddystoneService(ble, params, radioPowerLevels, advConfigInterval); } else { initializeEddystoneToDefaults(ble); } -#else - #warning "EddystoneService is not configured to store configuration data in non-volatile memory" - initializeEddystoneToDefaults(ble); -#endif /* * Set the custom device name. The device name is not stored in persistent From 44895c25d13e634aca327a47598e752017b9e309 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 9 Feb 2016 09:42:10 +0000 Subject: [PATCH 02/10] Add yotta config options to Eddystone example The new yotta config allow a user to change the default values for: * URL * URL frame interval * UID frame interval * TLM frame interval * BLE Device Name * Eddystone-URL configuration service advertising interval Note that these values can still be overwritten by code in main.cpp --- BLE_EddystoneService/config.json | 8 +++++++ .../source/EddystoneService.h | 24 +++++++++++++++---- BLE_EddystoneService/source/EddystoneTypes.h | 12 ++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/BLE_EddystoneService/config.json b/BLE_EddystoneService/config.json index a90578ed869..b300209f56c 100644 --- a/BLE_EddystoneService/config.json +++ b/BLE_EddystoneService/config.json @@ -4,5 +4,13 @@ }, "mbed": { "max-filehandles": 4 + }, + "eddystone": { + "default-device-name": "\"EDDYSTONE CONFIG\"", + "default-url": "\"https://www.mbed.com/\"", + "default-url-frame-interval": 700, + "default-uid-frame-interval": 300, + "default-tlm-frame-interval": 2000, + "default-eddystone-url-config-adv-interval": 1000 } } diff --git a/BLE_EddystoneService/source/EddystoneService.h b/BLE_EddystoneService/source/EddystoneService.h index b668590d4df..819162d484d 100644 --- a/BLE_EddystoneService/source/EddystoneService.h +++ b/BLE_EddystoneService/source/EddystoneService.h @@ -31,6 +31,22 @@ #include "CircularBuffer.h" #endif +#ifndef YOTTA_CFG_DEFAULT_URL_FRAME_INTERVAL + #define YOTTA_CFG_DEFAULT_URL_FRAME_INTERVAL 700 +#endif + +#ifndef YOTTA_CFG_DEFAULT_UID_FRAME_INTERVAL + #define YOTTA_CFG_DEFAULT_UID_FRAME_INTERVAL 300 +#endif + +#ifndef YOTTA_CFG_DEFAULT_TLM_FRAME_INTERVAL + #define YOTTA_CFG_DEFAULT_TLM_FRAME_INTERVAL 2000 +#endif + +#ifndef YOTTA_CFG_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL + #define YOTTA_CFG_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL 1000 +#endif + /** * This class implements the Eddystone-URL Config Service and the Eddystone * Protocol Specification as defined in the publicly available specification at @@ -49,22 +65,22 @@ class EddystoneService * Default interval for advertising packets for the Eddystone-URL * Configuration Service. */ - static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = 1000; + static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = YOTTA_CFG_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL; /** * Recommended interval for advertising packets containing Eddystone URL * frames. */ - static const uint16_t DEFAULT_URL_FRAME_PERIOD_MSEC = 700; + static const uint16_t DEFAULT_URL_FRAME_PERIOD_MSEC = YOTTA_CFG_DEFAULT_URL_FRAME_INTERVAL; /** * Recommended interval for advertising packets containing Eddystone UID * frames. */ - static const uint16_t DEFAULT_UID_FRAME_PERIOD_MSEC = 300; + static const uint16_t DEFAULT_UID_FRAME_PERIOD_MSEC = YOTTA_CFG_DEFAULT_UID_FRAME_INTERVAL; /** * Recommended interval for advertising packets containing Eddystone TLM * frames. */ - static const uint16_t DEFAULT_TLM_FRAME_PERIOD_MSEC = 2000; + static const uint16_t DEFAULT_TLM_FRAME_PERIOD_MSEC = YOTTA_CFG_DEFAULT_TLM_FRAME_INTERVAL; /** * Enumeration that defines the various operation modes of the diff --git a/BLE_EddystoneService/source/EddystoneTypes.h b/BLE_EddystoneService/source/EddystoneTypes.h index 1dd36d6e536..73deabafbc9 100644 --- a/BLE_EddystoneService/source/EddystoneTypes.h +++ b/BLE_EddystoneService/source/EddystoneTypes.h @@ -20,6 +20,14 @@ #include #include +#ifndef YOTTA_CONFIG_EDDYSTONE_DEFAULT_DEVICE_NAME + #define YOTTA_CONFIG_EDDYSTONE_DEFAULT_DEVICE_NAME "EDDYSTONE CONFIG" +#endif + +#ifndef YOTTA_CONFIG_EDDYSTONE_DEFAULT_URL + #define YOTTA_CONFIG_EDDYSTONE_DEFAULT_URL "https://www.mbed.com/" +#endif + /** * Macro to expand a 16-bit Eddystone UUID to 128-bit UUID. */ @@ -86,12 +94,12 @@ const uint8_t UUID_RESET_CHAR[] = UUID_URL_BEACON(0x20, 0x89); /** * Default name for the BLE Device Name characteristic. */ -const char DEFAULT_DEVICE_NAME[] = "EDDYSTONE CONFIG"; +const char DEFAULT_DEVICE_NAME[] = YOTTA_CONFIG_EDDYSTONE_DEFAULT_DEVICE_NAME; /** * Default URL used by EddystoneService. */ -const char DEFAULT_URL[] = "http://www.mbed.com/"; +const char DEFAULT_URL[] = YOTTA_CONFIG_EDDYSTONE_DEFAULT_URL; /** * Enumeration that defines the Eddystone power levels for the Eddystone-URL From d578e5adfeb905464642cd6a20f03ab858cce0df Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 9 Feb 2016 09:44:58 +0000 Subject: [PATCH 03/10] Add Eddystone API to stop any BLE service running --- .../source/EddystoneService.cpp | 23 +++++++++++++++++ .../source/EddystoneService.h | 25 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/BLE_EddystoneService/source/EddystoneService.cpp b/BLE_EddystoneService/source/EddystoneService.cpp index ce95ad21b94..bde143524da 100644 --- a/BLE_EddystoneService/source/EddystoneService.cpp +++ b/BLE_EddystoneService/source/EddystoneService.cpp @@ -165,6 +165,29 @@ EddystoneService::EddystoneError_t EddystoneService::startBeaconService(void) return EDDYSTONE_ERROR_NONE; } +EddystoneService::EddystoneError_t EddystoneService::stopCurrentService(void) +{ + switch (operationMode) { + case EDDYSTONE_MODE_NONE: + return EDDYSTONE_ERROR_INVALID_STATE; + case EDDYSTONE_MODE_CONFIG: + ble.shutdown(); + stopBeaconService(); + break; + case EDDYSTONE_MODE_BEACON: + ble.shutdown(); + freeConfigCharacteristics(); + break; + default: + /* Some error occurred */ + error("Invalid EddystonService mode"); + break; + } + operationMode = EDDYSTONE_MODE_NONE; + + return EDDYSTONE_ERROR_NONE; +} + ble_error_t EddystoneService::setCompleteDeviceName(const char *deviceNameIn) { /* Make sure the device name is safe */ diff --git a/BLE_EddystoneService/source/EddystoneService.h b/BLE_EddystoneService/source/EddystoneService.h index 819162d484d..5f4d7cab0f4 100644 --- a/BLE_EddystoneService/source/EddystoneService.h +++ b/BLE_EddystoneService/source/EddystoneService.h @@ -231,7 +231,12 @@ class EddystoneService * - Gap::getMinAdvertisingInterval() * - Gap::getMaxAdvertisingInterval() */ - EDDYSTONE_ERROR_INVALID_ADVERTISING_INTERVAL + EDDYSTONE_ERROR_INVALID_ADVERTISING_INTERVAL, + /** + * The result of executing a call when the the EddystoneService is in + * the incorrect operation mode. + */ + EDDYSTONE_ERROR_INVALID_STATE }; /** @@ -421,6 +426,20 @@ class EddystoneService */ EddystoneError_t startBeaconService(void); + /** + * Change the EddystoneService OperationMode to EDDYSTONE_MODE_NONE. + * + * @retval EDDYSTONE_ERROR_NONE if the operation succeeded. + * @retval EDDYSTONE_ERROR_INVALID_STATE if the state of the + * EddystoneService already is EDDYSTONE_MODE_NONE. + * + * @note If EddystoneService was previously in EDDYSTONE_MODE_CONFIG or + * EDDYSTONE_MODE_BEACON, then the resources allocated to that mode + * of operation such as memory are freed and the BLE instance + * shutdown before the new operation mode is configured. + */ + EddystoneError_t stopCurrentService(void); + /** * Set the Comple Local Name for the BLE device. This not only updates * the value of the Device Name Characteristic, it also updates the scan @@ -569,6 +588,10 @@ class EddystoneService /** * Free the resources acquired by a call to setupBeaconService() and * cancel all pending callbacks that operate the radio and frame queue. + * + * @note This call will not modify the current state of the BLE device. + * EddystoneService::stopBeaconService should only be called after + * a call to BLE::shutdown(). */ void stopBeaconService(void); From ec53bdda34db7072be85d9e15f6a111139b804a9 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 9 Feb 2016 09:51:11 +0000 Subject: [PATCH 04/10] Change Eddystone example to use default yotta config values rather than data from main --- BLE_EddystoneService/source/main.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/BLE_EddystoneService/source/main.cpp b/BLE_EddystoneService/source/main.cpp index a74991b1480..608cdfdb000 100644 --- a/BLE_EddystoneService/source/main.cpp +++ b/BLE_EddystoneService/source/main.cpp @@ -32,20 +32,11 @@ static const UIDInstanceID_t uidInstanceID = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0x /* Default version in TLM frame */ static const uint8_t tlmVersion = 0x00; -/* Default configuration advertising interval */ -static const uint32_t advConfigInterval = 500; - -/* Default URL */ -static const char defaultUrl[] = "http://mbed.org"; - /* Values for ADV packets related to firmware levels, calibrated based on measured values at 1m */ static const PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13}; /* Values for radio power levels, provided by manufacturer. */ static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4}; -/* Custom device name for this application */ -static const char deviceName[] = "mbed Eddystone"; - DigitalOut led(LED1, 1); /** @@ -88,10 +79,9 @@ static void onBleInitError(BLE::InitializationCompleteCallbackContext* initConte static void initializeEddystoneToDefaults(BLE &ble) { /* Set everything to defaults */ - eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels, advConfigInterval); + eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels); /* Set default URL, UID and TLM frame data if not initialized through the config service */ - eddyServicePtr->setURLData(defaultUrl); eddyServicePtr->setUIDData(uidNamespaceID, uidInstanceID); eddyServicePtr->setTLMData(tlmVersion); } @@ -110,17 +100,11 @@ static void bleInitComplete(BLE::InitializationCompleteCallbackContext* initCont EddystoneService::EddystoneParams_t params; if (loadEddystoneServiceConfigParams(¶ms)) { - eddyServicePtr = new EddystoneService(ble, params, radioPowerLevels, advConfigInterval); + eddyServicePtr = new EddystoneService(ble, params, radioPowerLevels); } else { initializeEddystoneToDefaults(ble); } - /* - * Set the custom device name. The device name is not stored in persistent - * storage, so we need to set it manually every time the device is reset - */ - eddyServicePtr->setCompleteDeviceName(deviceName); - /* Start Eddystone in config mode */ eddyServicePtr->startConfigService(); From 9bb15fac20c886d0b34f783cee9c1cdf38e4b08f Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 9 Feb 2016 09:55:05 +0000 Subject: [PATCH 05/10] Change wrong include path in Eddystone example --- .../source/PersistentStorageHelper/ConfigParamsPersistence.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h b/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h index 3a7bb62d40a..3f2b2e6fc24 100644 --- a/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h +++ b/BLE_EddystoneService/source/PersistentStorageHelper/ConfigParamsPersistence.h @@ -17,7 +17,7 @@ #ifndef __BLE_CONFIG_PARAMS_PERSISTENCE_H__ #define __BLE_CONFIG_PARAMS_PERSISTENCE_H__ -#include "EddystoneService.h" +#include "../EddystoneService.h" /** * Generic API to load the Eddystone Service configuration parameters from persistent From 378fb5b60da26ad663037edf5032d0a96f8c7b31 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 9 Feb 2016 14:42:37 +0000 Subject: [PATCH 06/10] Fix yotta_cfg references --- .../source/EddystoneService.h | 24 +++++++++---------- BLE_EddystoneService/source/EddystoneTypes.h | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/BLE_EddystoneService/source/EddystoneService.h b/BLE_EddystoneService/source/EddystoneService.h index 5f4d7cab0f4..2fa5602ce44 100644 --- a/BLE_EddystoneService/source/EddystoneService.h +++ b/BLE_EddystoneService/source/EddystoneService.h @@ -31,20 +31,20 @@ #include "CircularBuffer.h" #endif -#ifndef YOTTA_CFG_DEFAULT_URL_FRAME_INTERVAL - #define YOTTA_CFG_DEFAULT_URL_FRAME_INTERVAL 700 +#ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_URL_FRAME_INTERVAL + #define YOTTA_CFG_EDDYSTONE_DEFAULT_URL_FRAME_INTERVAL 700 #endif -#ifndef YOTTA_CFG_DEFAULT_UID_FRAME_INTERVAL - #define YOTTA_CFG_DEFAULT_UID_FRAME_INTERVAL 300 +#ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_UID_FRAME_INTERVAL + #define YOTTA_CFG_EDDYSTONE_DEFAULT_UID_FRAME_INTERVAL 300 #endif -#ifndef YOTTA_CFG_DEFAULT_TLM_FRAME_INTERVAL - #define YOTTA_CFG_DEFAULT_TLM_FRAME_INTERVAL 2000 +#ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_TLM_FRAME_INTERVAL + #define YOTTA_CFG_EDDYSTONE_DEFAULT_TLM_FRAME_INTERVAL 2000 #endif -#ifndef YOTTA_CFG_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL - #define YOTTA_CFG_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL 1000 +#ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL + #define YOTTA_CFG_EDDYSTONE_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL 1000 #endif /** @@ -65,22 +65,22 @@ class EddystoneService * Default interval for advertising packets for the Eddystone-URL * Configuration Service. */ - static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = YOTTA_CFG_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL; + static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL; /** * Recommended interval for advertising packets containing Eddystone URL * frames. */ - static const uint16_t DEFAULT_URL_FRAME_PERIOD_MSEC = YOTTA_CFG_DEFAULT_URL_FRAME_INTERVAL; + static const uint16_t DEFAULT_URL_FRAME_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_URL_FRAME_INTERVAL; /** * Recommended interval for advertising packets containing Eddystone UID * frames. */ - static const uint16_t DEFAULT_UID_FRAME_PERIOD_MSEC = YOTTA_CFG_DEFAULT_UID_FRAME_INTERVAL; + static const uint16_t DEFAULT_UID_FRAME_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_UID_FRAME_INTERVAL; /** * Recommended interval for advertising packets containing Eddystone TLM * frames. */ - static const uint16_t DEFAULT_TLM_FRAME_PERIOD_MSEC = YOTTA_CFG_DEFAULT_TLM_FRAME_INTERVAL; + static const uint16_t DEFAULT_TLM_FRAME_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_TLM_FRAME_INTERVAL; /** * Enumeration that defines the various operation modes of the diff --git a/BLE_EddystoneService/source/EddystoneTypes.h b/BLE_EddystoneService/source/EddystoneTypes.h index 73deabafbc9..1ddbd388437 100644 --- a/BLE_EddystoneService/source/EddystoneTypes.h +++ b/BLE_EddystoneService/source/EddystoneTypes.h @@ -20,12 +20,12 @@ #include #include -#ifndef YOTTA_CONFIG_EDDYSTONE_DEFAULT_DEVICE_NAME - #define YOTTA_CONFIG_EDDYSTONE_DEFAULT_DEVICE_NAME "EDDYSTONE CONFIG" +#ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_DEVICE_NAME + #define YOTTA_CFG_EDDYSTONE_DEFAULT_DEVICE_NAME "EDDYSTONE CONFIG" #endif -#ifndef YOTTA_CONFIG_EDDYSTONE_DEFAULT_URL - #define YOTTA_CONFIG_EDDYSTONE_DEFAULT_URL "https://www.mbed.com/" +#ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_URL + #define YOTTA_CFG_EDDYSTONE_DEFAULT_URL "https://www.mbed.com/" #endif /** @@ -94,12 +94,12 @@ const uint8_t UUID_RESET_CHAR[] = UUID_URL_BEACON(0x20, 0x89); /** * Default name for the BLE Device Name characteristic. */ -const char DEFAULT_DEVICE_NAME[] = YOTTA_CONFIG_EDDYSTONE_DEFAULT_DEVICE_NAME; +const char DEFAULT_DEVICE_NAME[] = YOTTA_CFG_EDDYSTONE_DEFAULT_DEVICE_NAME; /** * Default URL used by EddystoneService. */ -const char DEFAULT_URL[] = YOTTA_CONFIG_EDDYSTONE_DEFAULT_URL; +const char DEFAULT_URL[] = YOTTA_CFG_EDDYSTONE_DEFAULT_URL; /** * Enumeration that defines the Eddystone power levels for the Eddystone-URL From 418a202b917726fe1a94a3aa6ed4284b65ea6d0c Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 9 Feb 2016 15:09:28 +0000 Subject: [PATCH 07/10] Fix URL broadcasting again --- BLE_EddystoneService/source/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BLE_EddystoneService/source/main.cpp b/BLE_EddystoneService/source/main.cpp index 608cdfdb000..1192f273f0d 100644 --- a/BLE_EddystoneService/source/main.cpp +++ b/BLE_EddystoneService/source/main.cpp @@ -82,6 +82,8 @@ static void initializeEddystoneToDefaults(BLE &ble) eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels); /* Set default URL, UID and TLM frame data if not initialized through the config service */ + const char* url = YOTTA_CFG_EDDYSTONE_DEFAULT_URL; + eddyServicePtr->setURLData(url); eddyServicePtr->setUIDData(uidNamespaceID, uidInstanceID); eddyServicePtr->setTLMData(tlmVersion); } From 0dae8666deca1c89a33f5876805426a273f0d066 Mon Sep 17 00:00:00 2001 From: Jonathan Austin Date: Fri, 12 Feb 2016 17:10:57 +0000 Subject: [PATCH 08/10] Fix logic for starting/stoping beacon service In the original patch to allow the user to start/stop the beacon and config services the logic was the wrong way around. Fix this --- BLE_EddystoneService/source/EddystoneService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BLE_EddystoneService/source/EddystoneService.cpp b/BLE_EddystoneService/source/EddystoneService.cpp index bde143524da..939b65cfeb5 100644 --- a/BLE_EddystoneService/source/EddystoneService.cpp +++ b/BLE_EddystoneService/source/EddystoneService.cpp @@ -170,11 +170,11 @@ EddystoneService::EddystoneError_t EddystoneService::stopCurrentService(void) switch (operationMode) { case EDDYSTONE_MODE_NONE: return EDDYSTONE_ERROR_INVALID_STATE; - case EDDYSTONE_MODE_CONFIG: + case EDDYSTONE_MODE_BEACON: ble.shutdown(); stopBeaconService(); break; - case EDDYSTONE_MODE_BEACON: + case EDDYSTONE_MODE_CONFIG: ble.shutdown(); freeConfigCharacteristics(); break; From d9a7469acde580c6cde0ab08f6a1fdc042db0293 Mon Sep 17 00:00:00 2001 From: Jonathan Austin Date: Fri, 12 Feb 2016 17:12:35 +0000 Subject: [PATCH 09/10] Check whether the BLE device is up when starting services With the addition of the stopCurrentService command, it is possible to bring up the services without BLE having been initialised. Without this, only the second time you bring up a service results in working broadcasting. --- BLE_EddystoneService/source/EddystoneService.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BLE_EddystoneService/source/EddystoneService.cpp b/BLE_EddystoneService/source/EddystoneService.cpp index 939b65cfeb5..121e93e4372 100644 --- a/BLE_EddystoneService/source/EddystoneService.cpp +++ b/BLE_EddystoneService/source/EddystoneService.cpp @@ -126,6 +126,9 @@ EddystoneService::EddystoneError_t EddystoneService::startConfigService(void) if (operationMode == EDDYSTONE_MODE_BEACON) { ble.shutdown(); stopBeaconService(); + } + + if (!ble.hasInitialized()) { operationMode = EDDYSTONE_MODE_CONFIG; ble.init(this, &EddystoneService::bleInitComplete); /* Set the device name once more */ @@ -152,6 +155,9 @@ EddystoneService::EddystoneError_t EddystoneService::startBeaconService(void) ble.shutdown(); /* Free unused memory */ freeConfigCharacteristics(); + } + + if (!ble.hasInitialized()) { operationMode = EDDYSTONE_MODE_BEACON; ble.init(this, &EddystoneService::bleInitComplete); /* Set the device name once more */ From 44138745772826cb1f633ada3a8fb576f91a344f Mon Sep 17 00:00:00 2001 From: Jonathan Austin Date: Fri, 12 Feb 2016 18:00:09 +0000 Subject: [PATCH 10/10] Workaround BLE being required for low power sleep On nrf51822 at the moment, sleeping without an initialised BLE object causes a busy (power-consumptive!) sleep. This patch works around this by ensuring we always have ble init'd even when we're not actually being a beacon/advertising. Once this has been fixed, this patch can safely be removed --- BLE_EddystoneService/source/EddystoneService.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BLE_EddystoneService/source/EddystoneService.cpp b/BLE_EddystoneService/source/EddystoneService.cpp index 121e93e4372..8481ae49596 100644 --- a/BLE_EddystoneService/source/EddystoneService.cpp +++ b/BLE_EddystoneService/source/EddystoneService.cpp @@ -190,6 +190,11 @@ EddystoneService::EddystoneError_t EddystoneService::stopCurrentService(void) break; } operationMode = EDDYSTONE_MODE_NONE; + /* Currently on some platforms, the BLE stack handles power management, + * so we should bring it up again, but not configure it. + * Once the system sleep without BLE initialised is fixed, remove this + */ + ble.init(this, &EddystoneService::bleInitComplete); return EDDYSTONE_ERROR_NONE; } @@ -286,6 +291,9 @@ void EddystoneService::bleInitComplete(BLE::InitializationCompleteCallbackContex case EDDYSTONE_MODE_BEACON: setupBeaconService(); break; + case EDDYSTONE_MODE_NONE: + /* We don't need to do anything here, but it isn't an error */ + break; default: /* Some error occurred */ error("Invalid EddystonService mode");