Damien Frost / WiflyInterface

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Fork of WiflyInterface by Components

Revision:
31:2846355deb7e
Parent:
30:2c704a72d88a
Child:
32:ab206f7f5090
--- a/Wifly/Wifly.cpp	Wed May 04 22:09:22 2016 +0000
+++ b/Wifly/Wifly.cpp	Mon May 09 11:39:08 2016 +0000
@@ -587,14 +587,28 @@
 int Wifly::checkNetworkStatus(void){
     int status = 0;   
     char rcv[128];
+    unsigned int ConnectionReg;
     
-    if(!sendCommand("show c", NULL, rcv, 5000)){
+    if(!sendCommand("show c\r", NULL, rcv, 5000)){
         status = 0;
         // the sendCommand function quits command mode if there is an error
     }else{
         // check the response:
-        INFO("Wifly Check network response: %s; %d", rcv, rcv);
-        status = 1;
+        sscanf(rcv, "%x%*s", &ConnectionReg);
+        if(((ConnectionReg & CC_ASSOCIATION)>0) && ((ConnectionReg & CC_AUTHENTICATION)>0)){
+            // Associated and Authenticated:
+            status = 3;
+        }else if((ConnectionReg & CC_ASSOCIATION)>0){
+            // Associated:
+            status = 1;
+        }else if((ConnectionReg & CC_AUTHENTICATION)>0){
+            // Athenticated:
+            status = 2;
+        }else{
+            // Disconnected:
+            status = 0;
+        }
+        INFO("Wifly Check network response: 0x%x, Status: %d", ConnectionReg, status);
         exit(); // Quit command mode
     }