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:
67:11db02bb93e1
Parent:
66:b2425419b0cc
Child:
68:6e311c747045
--- a/wnc_control.cpp	Thu Aug 04 05:48:20 2016 +0000
+++ b/wnc_control.cpp	Thu Aug 04 16:24:13 2016 +0000
@@ -35,13 +35,13 @@
  // Temp put here to fix new boards needing init,
  //  the check for on the cellular network was preventing the PDNSET from happening!!!!
  {  
-    pc.puts("SET APN STRING!\r\n");
+    PUTS("SET APN STRING!\r\n");
     string * pRespStr;
     string cmd_str("AT%PDNSET=1,");
     cmd_str += MY_APN_STR;
     cmd_str += ",IP";
     at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, 4*WNC_TIMEOUT_MS); // Set APN, cmd seems to take a little longer sometimes
-    pc.puts(cmd_str.c_str());
+    PUTS(cmd_str.c_str());
  }   
 
   static bool reportStatus = true;
@@ -51,7 +51,7 @@
       {
           if (reportStatus == false)
           {
-              puts("Re-connected to cellular network!\n\r");
+              PUTS("Re-connected to cellular network!\n\r");
               reportStatus = true;
           }
     
@@ -71,12 +71,12 @@
       {
           if (reportStatus == true)
           {
-               puts("Not connected to cellular network!\n\r");
+               PUTS("Not connected to cellular network!\n\r");
                reportStatus = false;
           }
      // Atempt to re-register
 //     string * pRespStr;
-//     pc.puts("Force re-register!\r\n");
+//     PUTS("Force re-register!\r\n");
 //     at_send_wnc_cmd("AT+CFUN=0,0", &pRespStr, WNC_TIMEOUT_MS);
 //     wait_ms(31000);
 //     at_send_wnc_cmd("AT+CFUN=1,0", &pRespStr, WNC_TIMEOUT_MS);
@@ -98,7 +98,7 @@
       }
       else if (WNC_MDM_ERR == WNC_CMD_ERR)
       {
-        pc.puts("Bad URL!!!!!!\r\n");
+        PUTS("Bad URL!!!!!!\r\n");
       }
     } while (WNC_MDM_ERR != WNC_OK);
     
@@ -116,7 +116,7 @@
         software_init_mdm();
       }
       else if (WNC_MDM_ERR == WNC_CMD_ERR)
-        pc.puts("Socket open fail!!!!\r\n");
+        PUTS("Socket open fail!!!!\r\n");
       else
         socketOpen = 1;
     } while (WNC_MDM_ERR != WNC_OK);
@@ -132,18 +132,18 @@
       at_sockwrite_wnc(s);
       if (WNC_MDM_ERR == WNC_NO_RESPONSE)
       {
-        pc.puts("Sock write no response!\r\n");
+        PUTS("Sock write no response!\r\n");
         software_init_mdm();
       }
       else if (WNC_MDM_ERR == WNC_CMD_ERR)
       {
-        pc.puts("Socket Write fail!!!\r\n");
+        PUTS("Socket Write fail!!!\r\n");
         software_init_mdm();
       }
     } while (WNC_MDM_ERR != WNC_OK);
     }
     else
-      puts("Socket is closed for write!\r\n");
+      PUTS("Socket is closed for write!\r\n");
 }
 
 unsigned sockread_mdm(string * sockData, int len, int retries)
@@ -161,15 +161,15 @@
         if (n == 0)
             software_init_mdm();
         else
-            puts("Sock read partial data!!!\r\n");
+            PUTS("Sock read partial data!!!\r\n");
       }
       else if (WNC_MDM_ERR == WNC_CMD_ERR)
-        puts("Sock read fail!!!!\r\n");
+        PUTS("Sock read fail!!!!\r\n");
     } while (WNC_MDM_ERR == WNC_NO_RESPONSE);
     }
     else
     {
-      puts("Socket is closed for read\r\n");
+      PUTS("Socket is closed for read\r\n");
       sockData->erase();
     }
       
@@ -191,7 +191,7 @@
         software_init_mdm();
       }
       else if (WNC_MDM_ERR == WNC_CMD_ERR)
-        puts("Sock close fail!!!\r\n");
+        PUTS("Sock close fail!!!\r\n");
     } while (WNC_MDM_ERR != WNC_OK);
 }
 
@@ -242,7 +242,7 @@
     int cmdRes1, cmdRes2;
 
 #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-    pc.puts("<-------- Begin Cell Status ------------\r\n");
+    PUTS("<-------- Begin Cell Status ------------\r\n");
 #endif
     cmdRes1 = at_send_wnc_cmd("AT+CSQ", &pRespStr, WNC_TIMEOUT_MS);       // Check RSSI,BER
     cmdRes2 = at_send_wnc_cmd("AT+CPIN?", &pRespStr, WNC_TIMEOUT_MS);      // Check if SIM locked
@@ -250,7 +250,7 @@
     if ((cmdRes1 != 0) && (cmdRes2 != 0))
     {
 #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-        pc.puts("------------ WNC No Response! --------->\r\n");
+        PUTS("------------ WNC No Response! --------->\r\n");
 #endif
         return (-2);      
     }
@@ -259,7 +259,7 @@
     if (pRespStr->find("CPIN: READY") == string::npos)
     {
 #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-        pc.puts("------------ WNC SIM Problem! --------->\r\n");
+        PUTS("------------ WNC SIM Problem! --------->\r\n");
 #endif
         return (-1);
     }
@@ -276,14 +276,14 @@
         if ((regSts != 1) && (regSts != 5))
         {
 #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-            pc.puts("------------ WNC Cell Link Down! ------>\r\n");
+            PUTS("------------ WNC Cell Link Down! ------>\r\n");
 #endif
             return (-2);
         }
     }
 
 #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-    pc.puts("------------ WNC Ready ---------------->\r\n");
+    PUTS("------------ WNC Ready ---------------->\r\n");
 #endif
   
     return (0);
@@ -299,16 +299,16 @@
      static string noRespStr;
 
 #ifdef WNC_CMD_DEBUG_ON
-     pc.puts("FAIL send cmd: ");
+     PUTS("FAIL send cmd: ");
      #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-     pc.puts(s);
+     PUTS(s);
      #else
      string truncStr(s, 50);
      truncStr += "\r\n";
-     pc.puts(truncStr.c_str());
+     PUTS(truncStr.c_str());
      #endif
 #else
-     pc.puts("FAIL send cmd!\r\n");
+     PUTS("FAIL send cmd!\r\n");
 #endif
 
      WNC_MDM_ERR = WNC_CELL_LINK_DOWN;
@@ -319,12 +319,12 @@
 
 #ifdef WNC_CMD_DEBUG_ON
   #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-  pc.puts("[---------- Network Status -------------\r\n");
+  PUTS("[---------- Network Status -------------\r\n");
   #endif
   string * pRespStr;
   at_send_wnc_cmd("AT@SOCKDIAL?", &pRespStr, 5000);
   #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-  pc.puts("---------------------------------------]\r\n");
+  PUTS("---------------------------------------]\r\n");
   #endif
 #endif
 
@@ -370,19 +370,19 @@
   {
 
 #ifdef WNC_CMD_DEBUG_ON   
-      pc.puts("[");
+      PUTS("[");
       #ifdef WNC_CMD_DEBUG_ON_VERBOSE
-      pc.puts(wncStr.c_str());
-      pc.puts("]\r\n");
+      PUTS(wncStr.c_str());
+      PUTS("]\r\n");
       #else
       if (wncStr.size() < 51)
-          pc.puts(wncStr.c_str());
+          PUTS(wncStr.c_str());
       else
       {
           string truncStr = wncStr.substr(0,50) + "...";
-          pc.puts(truncStr.c_str());
+          PUTS(truncStr.c_str());
       }
-      pc.puts("]\r\n");
+      PUTS("]\r\n");
       #endif
 #endif
 
@@ -393,7 +393,7 @@
   }
   else
   {
-      pc.puts("No response from WNC!\n\r");
+      PUTS("No response from WNC!\n\r");
       return -2;
   }
 }
@@ -415,13 +415,13 @@
   
   if (hardReset == true)
   {
-      pc.puts("Hard Reset!\r\n");
+      PUTS("Hard Reset!\r\n");
       pdnSet = false;
       intSet = false;
       sockDialSet = false;
   }
   
-  pc.puts("Start AT init of WNC:\r\n");
+  PUTS("Start AT init of WNC:\r\n");
   // Quick commands below do not need to check cellular connectivity
   cmdRes = at_send_wnc_cmd("AT", &pRespStr, WNC_TIMEOUT_MS);             // Heartbeat?
   cmdRes += at_send_wnc_cmd("ATE0", &pRespStr, WNC_TIMEOUT_MS);           // Echo Off
@@ -467,7 +467,7 @@
   else
     return ;
   
-  pc.puts("SUCCESS: AT init of WNC!\r\n");
+  PUTS("SUCCESS: AT init of WNC!\r\n");
 }
 
 void at_sockopen_wnc(const string & ipStr, const char * port )
@@ -506,13 +506,13 @@
           return 1;
         }
         else
-          pc.puts("URL Resolve fail, substr Err\r\n");
+          PUTS("URL Resolve fail, substr Err\r\n");
     }
     else
-      pc.puts("URL Resolve fail, no quotes\r\n");
+      PUTS("URL Resolve fail, no quotes\r\n");
   }
   else
-    pc.puts("URL Resolve fail, WNC cmd fail\r\n");
+    PUTS("URL Resolve fail, WNC cmd fail\r\n");
   
   *ipStr = "192.168.0.1";
   
@@ -546,7 +546,7 @@
     send_wnc_cmd(cmd_str.c_str(), &pRespStr, 120000);
   }
   else
-    pc.puts("sockwrite Err, string to long\r\n");
+    PUTS("sockwrite Err, string to long\r\n");
 }
 
 unsigned at_sockread_wnc(string * pS, unsigned n, unsigned retries = 0)
@@ -599,7 +599,7 @@
     }
   }
   else
-    pc.puts("sockread Err, to many to read\r\n");
+    PUTS("sockread Err, to many to read\r\n");
   
   return (numBytes);
 }