Button initiated config service

Dependencies:   BLE_API_EddystoneConfigService_2 mbed nRF51822

Fork of BLE_EddystoneBeaconConfigService_3 by URIBeacon

Files at this revision

API Documentation at this revision

Comitter:
mbedAustin
Date:
Fri Jul 24 04:07:34 2015 +0000
Parent:
29:dfb7fb5a971b
Commit message:
[[Working]] Updated main program to periodically update the temperature and battery voltage.

Changed in this revision

Eddystone.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Eddystone.h	Fri Jul 24 03:36:45 2015 +0000
+++ b/Eddystone.h	Fri Jul 24 04:07:34 2015 +0000
@@ -23,15 +23,19 @@
 static const uint8_t BEACON_EDDYSTONE[] = {0xAA, 0xFE};
 
 //Debug is disabled by default
-#if 1
+#if 0
 #define DBG(x, ...)  printf("[EddyStone: DBG]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
 #define WARN(x, ...) printf("[EddyStone: WARN]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
 #define ERR(x, ...)  printf("[EddyStone: ERR]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
-#define INFO(x, ...)  printf("[EddyStone: INFO]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
 #else
 #define DBG(x, ...) //wait_us(10);
 #define WARN(x, ...) //wait_us(10);
 #define ERR(x, ...)
+#endif
+
+#if 1
+#define INFO(x, ...)  printf("[EddyStone: INFO]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
+#else
 #define INFO(x, ...)
 #endif
 
@@ -254,11 +258,11 @@
     bool updateAdvPacket(uint8_t serviceData[], unsigned serviceDataLen) {
         // Fields from the Service
         DBG("Updating AdvFrame: %d", serviceDataLen);
-        printf("\r\n");
-        for(int x = 0; x<serviceDataLen; x++) {
-            printf("%2.2x:",serviceData[x]);
-        }
-        printf("\r\n");
+//        printf("\r\n");
+//        for(int x = 0; x<serviceDataLen; x++) {
+//            printf("%2.2x:",serviceData[x]);
+//        }
+//        printf("\r\n");
         ble.clearAdvertisingPayload();
         ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
         ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_EDDYSTONE, sizeof(BEACON_EDDYSTONE));
@@ -284,8 +288,8 @@
         switch(frameIndex) {
             case 1:
                 // URL Frame
-                INFO("Swaping URL Frame: %d",urlIsSet);
                 if(urlIsSet) {
+                    INFO("Swapping in URL Frame: Power: %d",defaultUrlPower);
                     serviceDataLen += constructURLFrame(serviceData+serviceDataLen,20);
                     DBG("\t Swapping in URL Frame: len=%d ",serviceDataLen);
                     updateAdvPacket(serviceData,serviceDataLen);
@@ -295,8 +299,8 @@
                 }
             case 2:
                 // UID Frame
-                INFO("Swaping UID Frame: %d",uidIsSet);
                 if(uidIsSet) {
+                    INFO("Swapping in UID Frame: Power: %d",defaultUidPower);
                     serviceDataLen += constructUIDFrame(serviceData+serviceDataLen,20);
                     DBG("\t Swapping in UID Frame: len=%d",serviceDataLen);
                     updateAdvPacket(serviceData,serviceDataLen);
@@ -306,7 +310,7 @@
                 }
             default:
                 // TLM frame
-                INFO("Swaping TLM Frame:");
+                INFO("Swapping in TLM Frame: version=%x, Batt=%d, Temp = %d, PDUCnt = %d, TimeSinceBoot=%d",TlmVersion, TlmBatteryVoltage, TlmBeaconTemp, TlmPduCount, TlmTimeSinceBoot);
                 serviceDataLen += constructTLMFrame(serviceData+serviceDataLen,20);
                 DBG("\t Swapping in TLM Frame: len=%d",serviceDataLen);
                 updateAdvPacket(serviceData,serviceDataLen);
--- a/main.cpp	Fri Jul 24 03:36:45 2015 +0000
+++ b/main.cpp	Fri Jul 24 04:07:34 2015 +0000
@@ -21,12 +21,34 @@
 BLE ble;
 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";
+char Url[] = "http://www.mbed.org";
+int8_t txPower = -18;
+uint16_t beaconPeriodus = 1000;
+
+//Callbacks for temperature / battery updates
+Ticker tlmBattery;
+Ticker tlmTemperature;
+int battery = 0;
+int temp = 0;
+
+// Start the Eddystone beacon here
+EddystoneService eddyBeacon(ble, beaconPeriodus, txPower ,UIDnamespace, UIDinstance, Url, sizeof(Url));
+
+// Function to update beacon battery voltage
+void tlmBatteryCallback(void){
+    eddyBeacon.updateTlmBatteryVoltage(battery++);
+}
+
+// Function to update Beacon Temperature
+void tlmTemperatureCallback(void){
+    eddyBeacon.updateTlmBeaconTemp(temp++);
+}
 
 int main(void)
 {
     printf("Starting Example\r\n");
-    EddystoneService eddyBeacon(ble, 1000, 10,UIDnamespace, UIDinstance, "http://www.mbed.org", sizeof("http://www.mbed.org"));
+    tlmTemperature.attach(tlmTemperatureCallback,2.0f);
+    tlmBattery.attach(tlmBatteryCallback, 1.0f);
     printf("Running...\r\n");
     while (true) {
         ble.waitForEvent();