Button initiated config service
Dependencies: BLE_API_EddystoneConfigService_2 mbed nRF51822
Fork of BLE_EddystoneBeaconConfigService_3 by
Diff: main.cpp
- Revision:
- 26:2896fbdd0450
- Parent:
- 24:8edfe6730cc2
- Child:
- 28:af37cebcb583
--- a/main.cpp Fri Jul 24 02:06:57 2015 +0000 +++ b/main.cpp Fri Jul 24 02:59:41 2015 +0000 @@ -16,81 +16,17 @@ #include "mbed.h" #include "BLE.h" -#include "EddystoneConfigService.h" -#include "DFUService.h" -#include "DeviceInformationService.h" -#include "ConfigParamsPersistence.h" +#include "Eddystone.h" BLE ble; -EddystoneConfigService *EddystoneBeaconConfig; -Ticker test; -//InterruptIn button(p17); - -/** - * URIBeaconConfig service can operate in two modes: a configuration mode which - * allows a user to update settings over a connection; and normal URIBeacon mode - * which involves advertising a URI. Constructing an object from URIBeaconConfig - * service sets up advertisements for the configuration mode. It is then up to - * the application to switch to URIBeacon mode based on some timeout. - * - * The following help with this switch. - */ -static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 5; // Duration after power-on that config service is available. -Ticker configAdvertisementTimeout; - -/** - * Stop advertising the Config Service after a delay; and switch to a non-connectable advertising mode only beacon. - */ -void timeout(void) -{ - Gap::GapState_t state; - state = ble.getGapState(); - if (!state.connected) { /* don't switch if we're in a connected state. */ - EddystoneBeaconConfig->setupEddystoneAdvertisements(); - configAdvertisementTimeout.detach(); /* disable the callback from the timeout Ticker. */ - printf("removing config service\r\n"); - } -} - -/** - * Callback triggered upon a disconnection event. Needs to re-enable advertisements. - */ -void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) -{ - ble.gap().startAdvertising(); - printf("disconnect CB\r\n"); -} +uint8_t UIDnamespace[] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA}; // 10Bytes for Namespace UUID +uint8_t UIDinstance[] = {0xbb,0xcc,0xdd,0xee,0xff,0x00}; // 6Bytes for Instance UUID + char Url[] = "www.mbed.org"; int main(void) { printf("Starting Example\r\n"); - ble.init(); - ble.gap().onDisconnection(disconnectionCallback); - - /* - * Load parameters from (platform specific) persistent storage. Parameters - * can be set to non-default values while the URIBeacon is in configuration - * mode (within the first 60 seconds of power-up). Thereafter, parameters - * get copied out to persistent storage before switching to normal URIBeacon - * operation. - */ - EddystoneConfigService::Params_t params; - bool fetchedFromPersistentStorage = loadURIBeaconConfigParams(¶ms); - - /* Initialize a EddystoneBeaconConfig service providing config params, default URI, and power levels. */ - static EddystoneConfigService::PowerLevels_t defaultAdvPowerLevels = {-20, -4, 0, 10}; // Values for ADV packets related to firmware levels - EddystoneBeaconConfig = new EddystoneConfigService(ble, params, !fetchedFromPersistentStorage, "http://mbed.org", defaultAdvPowerLevels); - if (!EddystoneBeaconConfig->configuredSuccessfully()) { - error("failed to accommodate URI"); - } - configAdvertisementTimeout.attach(timeout, CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS); - - // Setup auxiliary services to allow over-the-air firmware updates, etc - DFUService dfu(ble); - DeviceInformationService deviceInfo(ble, "ARM", "UriBeacon", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); - - ble.gap().startAdvertising(); /* Set the whole thing in motion. After this call a GAP central can scan the EddystoneBeaconConfig - * service. This can then be switched to the normal URIBeacon functionality after a timeout. */ + Eddystone eddyBeacon(ble, 100, 10,UIDnamespace, UIDinstance, Url, sizeof(Url)); printf("Running...\r\n"); while (true) { ble.waitForEvent();