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:
53:dcccf2881fa0
Parent:
46:da9d788f5d5a
Child:
62:73c564e883e9
--- a/wnc_control.cpp	Sun Jul 24 22:10:12 2016 +0000
+++ b/wnc_control.cpp	Tue Jul 26 20:32:00 2016 +0000
@@ -5,6 +5,12 @@
 #include "SerialBuffered.h"
 #include "wnc_control.h"
 
+// Outputs detailed WNC command info
+#define WNC_CMD_DEBUG_ON
+
+// Full debug output, longer cmds and extra cellular status checking
+#undef WNC_CMD_DEBUG_ON_VERBOSE
+
 extern Serial pc;
 extern Serial mdm;
 extern string MyServerIpAddress;
@@ -225,21 +231,26 @@
     int regSts;
     int cmdRes1, cmdRes2;
 
+#ifdef WNC_CMD_DEBUG_ON_VERBOSE
     pc.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
     
     if ((cmdRes1 != 0) && (cmdRes2 != 0))
     {
+#ifdef WNC_CMD_DEBUG_ON_VERBOSE
         pc.puts("------------ WNC No Response! --------->\r\n");
+#endif
         return (-2);      
     }
   
     // If SIM Card not ready don't bother with commands!
     if (pRespStr->find("CPIN: READY") == string::npos)
     {
+#ifdef WNC_CMD_DEBUG_ON_VERBOSE
         pc.puts("------------ WNC SIM Problem! --------->\r\n");
+#endif
         return (-1);
     }
   
@@ -254,12 +265,16 @@
         // 1 - registered home, 5 - registered roaming
         if ((regSts != 1) && (regSts != 5))
         {
+#ifdef WNC_CMD_DEBUG_ON_VERBOSE
             pc.puts("------------ WNC Cell Link Down! ------>\r\n");
+#endif
             return (-2);
         }
     }
 
+#ifdef WNC_CMD_DEBUG_ON_VERBOSE
     pc.puts("------------ WNC Ready ---------------->\r\n");
+#endif
   
     return (0);
 }
@@ -272,16 +287,37 @@
   if (check_wnc_ready() < 0)
   {
      static string noRespStr;
-     string truncStr(s, 50);
+
+#ifdef WNC_CMD_DEBUG_ON
      pc.puts("FAIL send cmd: ");
+     #ifdef WNC_CMD_DEBUG_ON_VERBOSE
+     pc.puts(s);
+     #else
+     string truncStr(s, 50);
+     truncStr += "\r\n";
      pc.puts(truncStr.c_str());
-     pc.puts("\r\n");
+     #endif
+#else
+     pc.puts("FAIL send cmd!\r\n");
+#endif
+
      WNC_MDM_ERR = WNC_CELL_LINK_DOWN;
      noRespStr.erase();
      *r = &noRespStr;
      return (-3);
   }
-  
+
+#ifdef WNC_CMD_DEBUG_ON
+  #ifdef WNC_CMD_DEBUG_ON_VERBOSE
+  pc.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");
+  #endif
+#endif
+
   // If WNC ready, send user command
   cmdRes = at_send_wnc_cmd(s, r, ms_timeout);
   
@@ -301,6 +337,11 @@
 {
   static const char * rsp_lst[] = { "OK", "ERROR", NULL };
   int len;
+
+#ifdef WNC_CMD_DEBUG_ON
+  #ifdef WNC_CMD_DEBUG_ON_VERBOSE
+  
+  #else
   if (strlen(s) > 60)
   {
       string truncStr(s,57);
@@ -308,14 +349,22 @@
       pc.printf("Send: <<%s>>\r\n",truncStr.c_str());
   }
   else
+  #endif
       pc.printf("Send: <<%s>>\r\n",s);
-    
+#endif
+
   int res = mdm_sendAtCmdRsp(s, rsp_lst, ms_timeout, &wncStr, &len);
   *r = &wncStr;   // Return a pointer to the static string
       
   if (res >= 0)
-  {   
+  {
+
+#ifdef WNC_CMD_DEBUG_ON   
       pc.puts("[");
+      #ifdef WNC_CMD_DEBUG_ON_VERBOSE
+      pc.puts(wncStr.c_str());
+      pc.puts("]\r\n");
+      #else
       if (wncStr.size() < 51)
           pc.puts(wncStr.c_str());
       else
@@ -323,7 +372,9 @@
           string truncStr = wncStr.substr(0,50) + "...";
           pc.puts(truncStr.c_str());
       }
-      pc.puts("]\n\r");
+      pc.puts("]\r\n");
+      #endif
+#endif
 
       if (res > 0)
           return -1;