Remote I/O Sensor bus with AT&T flow and M2X cloud

Dependencies:   DHT11 FXOS8700CQ MODSERIAL mbed

Fork of Avnet_ATT_Cellular_IOT by Avnet

Revision:
34:1a4498e3580e
Parent:
32:1e052a3e73fe
Child:
36:d4782eabff43
--- a/wnc_control.cpp	Fri Jul 22 17:12:26 2016 +0000
+++ b/wnc_control.cpp	Fri Jul 22 18:01:07 2016 +0000
@@ -331,13 +331,10 @@
 
 unsigned at_sockread_wnc(string * pS, unsigned n, unsigned retries = 0)
 {
-  unsigned i;
+  unsigned i, numBytes = 0;
   string * pRespStr;
   string cmd_str("AT@SOCKREAD=1,");
 
-  // Clean slate
-  pS->erase();
-
   if (n <= 1500)
   {
     char num2str[6];
@@ -355,10 +352,11 @@
       send_wnc_cmd(cmd_str.c_str(), &pRespStr, WNC_TIMEOUT_MS);
       size_t pos_start = pRespStr->find("\"")  + 1;
       size_t pos_end   = pRespStr->rfind("\"") - 1;
-      i = pos_end - pos_start + 1;
+      i = (pos_end - pos_start + 1);  // Num hex chars, 2 per byte
       if (i > 0)
       {
-        retries = 0;  // If any data found stop retrying
+        retries = 1;  // If any data found retry 1 more time to catch data that might be in another
+                      //  WNC payload
         string byte;
         while (pos_start < pos_end)
         {
@@ -366,9 +364,10 @@
           *pS += (char)strtol(byte.c_str(), NULL, 16);
           pos_start += 2;
         }
-        return i;
+        numBytes += i/2;
       }
     }
+    return numBytes;
   }
   else
     pc.puts("sockread Err, to many to read\r\n");