Mdot control and communication for the exosonde

Dependencies:   libmDot-mbed5 mbed

Revision:
6:f3407f58f521
Parent:
3:805c0c2f82d3
Child:
7:42e738547cb2
--- a/main.cpp	Mon Sep 04 02:58:01 2017 +0000
+++ b/main.cpp	Tue Sep 26 13:32:45 2017 +0000
@@ -14,9 +14,11 @@
 lora::ChannelPlan* plan = NULL;
 mDot* dot = NULL;
 
-static std::string config_network_name = "UQ_St_Lucia";
-static std::string config_network_pass = "L0raStLucia";
-static uint8_t config_frequency_sub_band = 7;
+//static std::string config_network_name = "UQ_St_Lucia";
+//static std::string config_network_pass = "L0raStLucia";
+const std::uint8_t *appEui = "70B3D57ED00074FE";
+const std::uint8_t *appKey = "35AC3CD8615D97F43B82E2B350626ACA";
+static uint8_t config_frequency_sub_band = 2;
 
 int32_t ret;
 
@@ -75,7 +77,10 @@
 }
 
 void sendpacket(){
-    std::vector<uint8_t> payload;       
+    std::vector<uint8_t> payload;
+    std::vector<uint8_t> dummypayload;
+    std::string dummystring = "hello";
+    std::copy(dummystring.begin(),dummystring.end(),std::back_inserter(dummypayload));      
     for (int i = 0; i < PARAMSNUM; i++){
         int j = 0;
         payload.push_back((uint8_t)identifiers[i]);
@@ -100,15 +105,15 @@
             debugger.printf("joined successfully\r\n");
         }
     }
-    if (dot->getNetworkJoinStatus()) {
+    // (dot->getNetworkJoinStatus()) {
         // send the data
-        // ACKs are enabled by default, so we're expecting to get one back
-        if ((ret = dot->send(payload)) != mDot::MDOT_OK) {
+        if ((ret = dot->send(dummypayload)) != mDot::MDOT_OK) {
             debugger.printf("\r\nFailed send, code: %s\r\n",mDot::getReturnCodeString(ret).c_str());
         } else {
             debugger.printf("\r\n data sent\r\n");
         }
-    }
+        
+    //}
     
 }
 
@@ -116,14 +121,14 @@
     if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
         debugger.printf("Could not set FSB\r\n");
     }
-    if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
-        debugger.printf("Could not set network name\r\n");
+    if ((ret = dot->setAppEUI(appEui)) != mDot::MDOT_OK) {
+        debugger.printf("Could not set network EUI\r\n");
     }
-    if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
-        debugger.printf("Could not set network passcode\r\n");
+    if ((ret = dot->setAppKey(appKey)) != mDot::MDOT_OK) {
+        debugger.printf("Could not set network key\r\n");
     }
     // in the 915 (US) frequency band, spreading factors 7 - 10 are available
-    if ((ret = dot->setTxDataRate(mDot::SF_7)) != mDot::MDOT_OK) {
+    if ((ret = dot->setTxDataRate(mDot::DR0))!= mDot::MDOT_OK){
         debugger.printf("Could not set spread factor\r\n");
     }
     //set the number of retries for each sub band before giving up
@@ -131,11 +136,11 @@
         debugger.printf("Could not set retries\r\n");
     }
     // request receive confirmation of packets from the gateway
-    if ((ret = dot->setAck(8)) != mDot::MDOT_OK) {
+    if ((ret = dot->setAck(0)) != mDot::MDOT_OK) {
         debugger.printf("Could not set ACK\r\n");
     }
     // set join mode 
-    if ((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
+    if ((ret = dot->setJoinMode(mDot::OTA)) != mDot::MDOT_OK) {
         debugger.printf("Could not set join mode\r\n");
     }   
 }
@@ -148,12 +153,12 @@
     Loraconfig();
     while(1){
         wait(0.5);
-        getsondedata(&device, &debugger);
-        if(!checkforcomma(&debugger)){
-            setcommadelim(&device);
-            continue;    
-        }
-        parsesondedata();
+        //getsondedata(&device, &debugger);
+        //if(!checkforcomma(&debugger)){
+            //setcommadelim(&device);
+            //continue;    
+        //}
+        //parsesondedata();
         sendpacket();
     }
 }