project for eddystone

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_URIBeacon by Bluetooth Low Energy

Revision:
28:63be4e73d447
Parent:
26:a2396234b4a8
Child:
29:db32d8dae04c
--- a/main.cpp	Tue Aug 11 22:00:00 2015 +0000
+++ b/main.cpp	Fri Oct 30 10:01:54 2015 +0000
@@ -1,5 +1,5 @@
 /* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
+ * 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.
@@ -16,80 +16,69 @@
 
 #include "mbed.h"
 #include "ble/BLE.h"
-#include "ble/services/URIBeaconConfigService.h"
-#include "ble/services/DFUService.h"
-#include "ble/services/DeviceInformationService.h"
-#include "ConfigParamsPersistence.h"
+#include "ble/services/EddystoneService.h"
 
-BLE ble;
-URIBeaconConfigService *uriBeaconConfig;
+DigitalOut led1(LED1, 1);
 
-/**
- * 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 = 60;  // Duration after power-on that config service is available.
-Ticker configAdvertisementTimeoutTicker;
+static uint8_t UIDnamespace[] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA}; // 10Bytes for Namespace UUID
+static uint8_t UIDinstance[]  = {0xbb,0xcc,0xdd,0xee,0xff,0x00}; // 6Bytes for Instance UUID
+static char Url[] = "http://www.mbed.org";
+static int8_t radioTxPower = 20;
+static int8_t advTxPower = -20;
+static uint16_t beaconPeriodus = 1000;
+static uint8_t tlmVersion = 0x00;
 
-/**
- * Stop advertising the UriBeaconConfig Service after a delay; and switch to normal URIBeacon.
- */
-void timeout(void)
+static int battery = 0;
+static int temp = 0;
+
+EddystoneService *eddyBeaconPtr;
+
+void blinkCallback(void)
 {
-    Gap::GapState_t state;
-    state = ble.getGapState();
-    if (!state.connected) { /* don't switch if we're in a connected state. */
-        uriBeaconConfig->setupURIBeaconAdvertisements();
-        ble.startAdvertising();
-
-        configAdvertisementTimeoutTicker.detach(); /* disable the callback from the timeout Ticker. */
-    }
+    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
 }
 
-/**
- * Callback triggered upon a disconnection event. Needs to re-enable advertisements.
- */
-void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
-{
-    ble.startAdvertising();
+/* Optional Function to update Eddystone beacon TLM frame battery voltage */
+void tlmBatteryCallback(void){
+    /* add the function to get battery */
+    //battery = nordic_getbattery();
+    eddyBeaconPtr->updateTlmBatteryVoltage(battery);
+}
+
+/* Optional Function to update Eddystone beacon TLM frame temperature */
+void tlmTemperatureCallback(void){
+    /* add the function to get temperature*/
+    eddyBeaconPtr->updateTlmBeaconTemp(temp++);
 }
 
 int main(void)
 {
+//    minar::Scheduler::postCallback(blinkCallback).period(minar::milliseconds(500));
+    Ticker tickerBattery;
+    Ticker tickerTemp;
+    
+    BLE &ble = BLE::Instance();
     ble.init();
-    ble.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.
-     */
-    URIBeaconConfigService::Params_t params;
-    bool fetchedFromPersistentStorage = loadURIBeaconConfigParams(&params);
+    /* Setup Eddystone Service */
+    eddyBeaconPtr = new EddystoneService(ble, beaconPeriodus, radioTxPower);
 
-    /* Initialize a URIBeaconConfig service providing config params, default URI, and power levels. */
-    static URIBeaconConfigService::PowerLevels_t defaultAdvPowerLevels = {-20, -4, 0, 10}; // Values for ADV packets related to firmware levels
-    uriBeaconConfig = new URIBeaconConfigService(ble, params, !fetchedFromPersistentStorage, "http://uribeacon.org", defaultAdvPowerLevels);
-    if (!uriBeaconConfig->configuredSuccessfully()) {
-        error("failed to accommodate URI");
-    }
-    configAdvertisementTimeoutTicker.attach(timeout, CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS);
+    /* Set Eddystone Frame Data (TLM,UID,URI...etc) */
+    eddyBeaconPtr->setTLMFrameData(tlmVersion, 5.0);
+    eddyBeaconPtr->setURLFrameData(advTxPower, Url, 2.0);
+    eddyBeaconPtr->setUIDFrameData(advTxPower, UIDnamespace, UIDinstance, 3.0);
 
-    // 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.startAdvertising(); /* Set the whole thing in motion. After this call a GAP central can scan the URIBeaconConfig
-                             * service. This can then be switched to the normal URIBeacon functionality after a timeout. */
-
+    /* Callbacks for temperature / battery updates */
+//    minar::Scheduler::postCallback(tlmTemperatureCallback).period(minar::milliseconds(2000));
+//    minar::Scheduler::postCallback(tlmBatteryCallback).period(minar::milliseconds(1000));
+    tickerBattery.attach(tlmBatteryCallback, 1);
+    tickerTemp.attach(tlmTemperatureCallback,1);
+    /* Start Advertising the eddystone service. */
+    eddyBeaconPtr->start();
+    ble.gap().startAdvertising();
+    
     while (true) {
         ble.waitForEvent();
     }
+    
 }