MultiTech mDot Test Application for Loriot.io LoRaWAN Cloud service

Dependencies:   libmDot mbed-rtos mbed-src

Fork of mDot_test by Semtech

Files at this revision

API Documentation at this revision

Comitter:
jknapp_smtc
Date:
Thu Jul 30 19:02:09 2015 +0000
Parent:
2:aadbdfb6d517
Child:
4:ee6bf074135c
Commit message:
Checking for SMTC System

Changed in this revision

libmDot.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 annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
--- a/libmDot.lib	Fri Jul 10 18:44:02 2015 +0000
+++ b/libmDot.lib	Thu Jul 30 19:02:09 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/MultiTech/code/libmDot/#0bfe6a650513
+http://developer.mbed.org/teams/MultiTech/code/libmDot/#390fc83d588d
--- a/main.cpp	Fri Jul 10 18:44:02 2015 +0000
+++ b/main.cpp	Thu Jul 30 19:02:09 2015 +0000
@@ -7,14 +7,34 @@
 
 using namespace mts;
 
-static std::string config_network_name = "";
-static std::string config_network_pass = "";
-static uint8_t config_frequency_sub_band = 1;
+static const uint8_t DEVKEY[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; // Normal
+static const uint8_t APPEUI[8]  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  }; // SMTC AppEUI
+                                        
+//static const uint8_t DEVKEY[16] = { 0x03, 0x24, 0x22, 0x60, 0xA6, 0xC6, 0x98, 0x5F, 0xD5, 0x02, 0x23, 0xD0, 0x53, 0x00, 0x49, 0xF6 }; // Normal
+//static const uint8_t APPEUI[8]  = { 0x00, 0x25, 0x0C, 0x00, 0x00, 0x01, 0x00, 0x01 }; // Senet AppEUI
+//static const uint8_t APPEUI[8]  = { 0x01, 0x00, 0x01, 0x00, 0x00, 0x0C, 0x25, 0x00 }; // Senet AppEUI Swapped
+
+static std::vector<uint8_t> AppKey (DEVKEY, DEVKEY + sizeof(DEVKEY)/sizeof(uint8_t) );
+static std::vector<uint8_t> AppEUI (APPEUI, APPEUI + sizeof(APPEUI)/sizeof(uint8_t) ); 
+static uint8_t              config_frequency_sub_band = 0; // 0 = Enable all channels, 1 = 1st eight channels
+
+InterruptIn button(PB_1);
+DigitalOut  drive_high(PB_0);
+DigitalIn   door_open(PA_7);
+
+volatile bool msg_rdy;
+
+void queue_message(){
+    msg_rdy = true;
+}
+    
 
 int main() {
     Serial debug(USBTX, USBRX);
     debug.baud(460800);
+    drive_high = 1;
     
+    msg_rdy = false;
     int32_t ret;
     int32_t next_tx;
     int32_t wait_time = 2;
@@ -25,30 +45,37 @@
     uint8_t recv_mismatch = 0;
     uint8_t send_failure = 0;
     uint8_t iterations = 50;
+    button.rise(&queue_message);
     
-    send_data.push_back(0x00);
-    send_data.push_back(0xFF);
-    send_data.push_back(0xFF);
-    send_data.push_back(0xFF);
-    send_data.push_back(0xFF);
-    send_data.push_back(0xFF);
-    send_data.push_back(0xFF);
-    send_data.push_back(0xFF);
+    send_data.push_back(0x01);
+    send_data.push_back(0x02);
 
     dot = mDot::getInstance();
 
     dot->resetConfig();
     
     dot->setLogLevel(MTSLog::TRACE_LEVEL);
-
+    //dot->setJoinByteOrder(1); // MSB
+    dot->setTxDataRate(mDot::SF_10);
+    //dot->setTxPower(20);
+    
     while ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
         logError("failed to set frequency sub band: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
     }
-    while ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
-        logError("failed to set network name: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
+    while ((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
+        logError("failed to set Public Network: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
     }
-    while ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
-        logError("failed to set network password: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
+    /** Set network ID
+     * for use with OTA & AUTO_OTA network join modes
+     * setting network ID via this function sets network name to empty
+     * @param id a vector of 8 bytes
+     * @returns MDOT_OK if success
+     */
+    while ((ret = dot->setNetworkId(AppEUI)) != mDot::MDOT_OK) {
+        logError("failed to set AppEUI: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
+    }
+    while ((ret = dot->setNetworkKey(AppKey)) != mDot::MDOT_OK) {
+        logError("failed to set AppEUI: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
     }
 
     logInfo("enabling activity LED");
@@ -61,8 +88,11 @@
     }
     logInfo("joined");
 
-    for (uint8_t i = 0; i < iterations; i++) {
-        send_data[0] = i;
+    dot->setAck(3); // Use Confirmed frames and try three times
+
+    while (1) {
+
+        send_data[0] = 192; //door_open;
         if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
             logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
             send_failure++;
@@ -72,22 +102,20 @@
                 logError("failed to recv: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
             } else {
                 logInfo("recv data: %s", Text::bin2hexString(recv_data).c_str());
-                if (recv_data == send_data) {
+                if (recv_data[0] == 0x80) {
                     recv++;
+                } else if (recv_data[0] == 0xFF) {
+                    goto END;
                 } else {
                     recv_mismatch++;
                 }
             }
             recv_data.clear();
         }
-        
-        next_tx = dot->getNextTxMs() + 1;
-        logInfo("waiting %ld ms to transmit again", next_tx);
-        wait_ms(next_tx);
-        logInfo("waiting another %d seconds", wait_time);
-        wait(wait_time);
+        msg_rdy = false;
+        while (!msg_rdy) wait(wait_time);
     }
-    
+END:    
     logInfo("Version: %s", dot->getId().c_str());
     logInfo("Recv: %d/%d", recv, iterations);
     logInfo("Recv Mismatch: %d/%d", recv_mismatch, iterations);
--- a/mbed-rtos.lib	Fri Jul 10 18:44:02 2015 +0000
+++ b/mbed-rtos.lib	Thu Jul 30 19:02:09 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#a21475017ae2
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5aed8bae1001
--- a/mbed-src.lib	Fri Jul 10 18:44:02 2015 +0000
+++ b/mbed-src.lib	Thu Jul 30 19:02:09 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-src/#61103edf8a92
+http://mbed.org/users/mbed_official/code/mbed-src/#6c996abb70b0