Austin Blackstone / Mbed 2 deprecated BLE_URIBeacon_ScavengerHunt

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_URIBeacon by Bluetooth Low Energy

Revision:
20:8f63cbf19f7f
Parent:
18:569257e0af4e
Child:
21:3c518a637de6
diff -r 982bbbc3fc96 -r 8f63cbf19f7f main.cpp
--- a/main.cpp	Mon Mar 23 16:36:46 2015 +0000
+++ b/main.cpp	Thu Apr 16 05:30:24 2015 +0000
@@ -15,6 +15,7 @@
  */
 
 #include "mbed.h"
+#include <string>
 #include "BLEDevice.h"
 #include "URIBeaconConfigService.h"
 #include "DFUService.h"
@@ -33,7 +34,7 @@
  *
  * The following help with this switch.
  */
-static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 60;  // Duration after power-on that config service is available.
+static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 5;  // Duration after power-on that config service is available.
 Ticker configAdvertisementTimeoutTicker;
 
 /**
@@ -64,6 +65,30 @@
     ble.init();
     ble.onDisconnection(disconnectionCallback);
 
+    uint8_t mac[6] = {};
+    ble.getAddress(0,mac);
+
+    printf("MAC Address = ");
+    for(int x =0; x<7; x++) {
+        printf("%x",mac[x]);
+    }
+    printf("\n\r");
+
+//    string url = "http://snurl.com/29ukhla" ;
+    string url = "http://snurl.com/ub?q=" ;
+    url += (mac[0]%(122-32))+32;
+    url += (mac[1]%(122-32))+32;
+    url += (mac[2]%(122-32))+32;
+    url += (mac[3]%(122-32))+32;
+    url += (mac[4]%(122-32))+32;
+    url += ((mac[5]%(122-32))+32);
+
+    for(int y=0; y<6; y++) {
+        printf("\n\rmac[%d]=0x%x, d%d, c%c,mod=%c",y,mac[y],mac[y],mac[y],((mac[y]%(122-32))+32));
+    }
+//    printf("\n\r0x%x->%c, 0x%x->%c\n\r%s\n\r",mac[4],(mac[4]%(122-32))+32,mac[5],(mac[5]%(122-32))+32,url);
+    printf("\n\rurl = %s\n\r",url);
+
     /*
      * Load parameters from (platform specific) persistent storage. Parameters
      * can be set to non-default values while the URIBeacon is in configuration
@@ -76,7 +101,7 @@
 
     /* 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);
+    uriBeaconConfig = new URIBeaconConfigService(ble, params, !fetchedFromPersistentStorage, (const char*)&url[0], defaultAdvPowerLevels);
     if (!uriBeaconConfig->configuredSuccessfully()) {
         error("failed to accommodate URI");
     }
@@ -89,6 +114,7 @@
     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. */
 
+
     while (true) {
         ble.waitForEvent();
     }