PIR + LoRa

Dependencies:   BLE_API LMiC SX1276Lib mbed nRF51822 nrf51_rtc

Fork of BLE_PhysicalWeb by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
janjongboom
Date:
Thu Sep 24 08:32:32 2015 +0000
Parent:
11:bbe4157401e2
Commit message:
Initial commit

Changed in this revision

LMiC.lib 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
mbed-rtos.lib Show diff for this revision Revisions of this file
diff -r bbe4157401e2 -r 940eb88a2104 LMiC.lib
--- a/LMiC.lib	Mon Aug 03 13:18:24 2015 +0000
+++ b/LMiC.lib	Thu Sep 24 08:32:32 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Semtech/code/LMiC/#d3b7bde3995c
+https://developer.mbed.org/users/janjongboom/code/LMiC/#002940b52fb4
diff -r bbe4157401e2 -r 940eb88a2104 main.cpp
--- a/main.cpp	Mon Aug 03 13:18:24 2015 +0000
+++ b/main.cpp	Thu Sep 24 08:32:32 2015 +0000
@@ -29,7 +29,7 @@
  * When set to 1 the application uses the Over-the-Air activation procedure
  * When set to 0 the application uses the Personalization activation procedure
  */
-#define OVER_THE_AIR_ACTIVATION                     0
+#define OVER_THE_AIR_ACTIVATION                     1
 
 #if( OVER_THE_AIR_ACTIVATION == 0 )
 
@@ -41,7 +41,7 @@
 /*!
  * Defines the device address when using personalization activation procedure
  */
-#define LORAWAN_DEV_ADDR                            ( uint32_t )0x73318881
+#define LORAWAN_DEV_ADDR                            ( uint32_t )0x73318891
 
 #endif
 
@@ -83,8 +83,10 @@
 
 // application router ID (LSBF)
 static const uint8_t AppEui[8] =
-{
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+{ // 13-37-aa-bb-cc-dd-ee-ff
+    0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x37, 0x13
+    // so its read rtl in the NS so when creating need to flip it in server
+    // compared to here. Really weird.
 };
 
 // unique device ID (LSBF)
@@ -94,25 +96,23 @@
 };
 
 // device-specific AES key (derived from device EUI)
-static const uint8_t DevKey[16] = 
+static const uint8_t DevKey[16] =
 {
-    0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
-    0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+    0xC1, 0x20, 0x2B, 0xB0, 0xAE, 0x97, 0x20, 0xC8,
+    0x18, 0xA3, 0x0F, 0xFA, 0x05, 0x14, 0xC5, 0x4F
 };
 
 #if( OVER_THE_AIR_ACTIVATION == 0 )
 // network session key
-static uint8_t NwkSKey[] = 
-{ 
-    0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
-    0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+static uint8_t NwkSKey[] =
+{
+    0x50, 0x12, 0x78, 0x26, 0x23, 0x9A, 0x5E, 0x39,
+    0x86, 0x8A, 0xCA, 0x7B, 0xDE, 0x16, 0xE1, 0x32
 };
-
-// application session key
-static uint8_t ArtSKey[] = 
-{ 
-    0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
-    0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+static uint8_t ArtSKey[] =
+{
+    0x54, 0xEB, 0x54, 0x4B, 0x07, 0x0C, 0x10, 0x69,
+    0xB1, 0x44, 0x94, 0x44, 0xF1, 0xCC, 0x13, 0xDA
 };
 
 #endif
@@ -320,11 +320,13 @@
     {
     // network joined, session established
     case EV_JOINED:
+        pc.printf("Joined, ID=%d\n", LMIC.netid);
         debug_val( "Net ID = ", LMIC.netid );
         txOn = true;
         break;
     // scheduled data sent (optionally data received)
     case EV_TXCOMPLETE:
+        pc.printf("TXComplete, datarate=%d\n", LMIC.datarate);
         debug_val( "Datarate = ", LMIC.datarate );
         // Check if we have a downlink on either Rx1 or Rx2 windows
         if( ( LMIC.txrxFlags & ( TXRX_DNW1 | TXRX_DNW2 ) ) != 0 )
@@ -388,25 +390,18 @@
     pc.printf("Current state %d, last_rise %d\r\n", rise_state, rtc.time() - last_rise);
 }
 
-int main(void)
-{    
-    Ticker ticker;
-    ticker.attach(&lastRiseCallback, 10);
-
-    motion.rise(&riseHandler);
-    motion.fall(&fallHandler);
-//
+void run_ble() {
     ble.init();
     ble.onDisconnection(disconnectionCallback);
 
-    uriBeaconConfig = new URIBeaconConfigService(ble, "http://goo.gl/kFE6eY");
+    uriBeaconConfig = new URIBeaconConfigService(ble, "http://goo.gl/H9YK6O");
     if (!uriBeaconConfig->configuredSuccessfully()) {
         error("failed to accommodate URI");
     }
     /* optional use of the API offered by URIBeaconConfigService */
     const int8_t powerLevels[] = {-20, -4, 0, 10};
     uriBeaconConfig->setTxPowerLevels(powerLevels);
-    uriBeaconConfig->setTxPowerMode(URIBeaconConfigService::TX_POWER_MODE_LOW);
+    uriBeaconConfig->setTxPowerMode(URIBeaconConfigService::TX_POWER_MODE_HIGH);
 
     static const uint8_t BEACON_UUID[] = {0xD8, 0xFE};
     static const uint8_t urldata[] = {
@@ -422,12 +417,12 @@
         'g',
         'l',
         '/',
-        'k',
-        'F',
-        'E',
+        'H',
+        '9',
+        'Y',
+        'K',
         '6',
-        'e',
-        'Y',
+        'O',
     };
 
     ble.clearAdvertisingPayload();
@@ -435,16 +430,39 @@
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, urldata, sizeof(urldata));
 
     ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
-    ble.setAdvertisingInterval(1600); /* 1s; in multiples of 0.625ms. */
+    ble.setAdvertisingInterval(800); /* .5s; in multiples of 0.625ms. */
     ble.startAdvertising();
-    
-    osjob_t initjob;
+}
+
+int main(void)
+{    
+    Ticker ticker;
+    ticker.attach(&lastRiseCallback, 10);
 
-    // initialize runtime env
-    os_init( );
-    // setup initial job
-    os_setCallback( &initjob, onInit );
-    // execute scheduled jobs and events
-    os_runloop( );
+    motion.rise(&riseHandler);
+    motion.fall(&fallHandler);
+    
+    run_ble();
+    
+//    run_ble();
+    
+//    osjob_t initjob;
+////
+//    // initialize runtime env
+//    os_init( );
+//    // setup initial job
+//    os_setCallback( &initjob, onInit );
+//    
+//    os_runloop();
+
+    while (true) {
+        // execute scheduled jobs and events
+//        os_inner_loop();
+        ble.waitForEvent();
+    }
+
+
+    
+//    os_runloop( );
     // (not reached)
 }
diff -r bbe4157401e2 -r 940eb88a2104 mbed-rtos.lib
--- a/mbed-rtos.lib	Mon Aug 03 13:18:24 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#5aed8bae1001