Da ka xi tong.

Dependencies:   libmDot mbed-rtos mbed

Fork of mDot_Connect_IoTClub_one_wire_4ch_8_24 by wireless sensor

Revision:
12:b31e43c9fb15
Parent:
11:1ecd1cdca9ef
Child:
13:5d050b414f16
--- a/main.cpp	Mon Aug 15 03:02:36 2016 +0000
+++ b/main.cpp	Mon Aug 15 14:48:41 2016 +0000
@@ -39,6 +39,7 @@
     char _header[] = "PH Sensors";
     char dataBuf[11];
     int  i, k;
+    int send_failed;
 
     // get a mDot handle
     dot = mDot::getInstance();
@@ -120,7 +121,7 @@
   logInfo("%s", _header);
 #endif 
     while (true) {
-        
+        send_failed = 0;
         // Read the PH values
         for(k=0; k<NUM_OF_CH; k++){
            switch(k){
@@ -150,18 +151,24 @@
             // send the data to the gateway
             if ((ret = dot->send(data)) != mDot::MDOT_OK) {
                logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());
-               // attempt to join the network
-               logInfo("rejoin network");
-               if ((ret = dot->joinNetworkOnce()) != mDot::MDOT_OK) {
-                  logError("failed to re-join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
-                  // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
-                  //osDelay(std::max((uint32_t)2000, (uint32_t)dot->getNextTxMs()));
-               }           
-            } else {
-            logInfo("successfully sent data to gateway");
+               send_failed++;
+               osDelay(5000);         
+            } else {            
+                logInfo("successfully sent data to gateway");
             }
           #endif
-        } //for
+        } 
+        //for
+        if(send_failed>=3){
+           // attempt to rejoin the network
+           logInfo("Attemp to rejoin network....");
+           if ((ret = dot->joinNetworkOnce()) != mDot::MDOT_OK) {
+                logError("Failed to rejoin network!"); // %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+           }else{
+                logInfo("Rejoin network successfully!");    
+           } 
+           osDelay(5000);
+        }
         //printf("++++++++++++++++++++++\t"); 
         // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
      #ifndef NO_MULTITECH_GATEWAY