Damien Frost / WiflyInterface

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Fork of WiflyInterface by Components

Revision:
36:8774837f5a78
Parent:
35:ce3afc021ec2
--- a/Wifly/Wifly.cpp	Fri Aug 05 13:31:37 2016 +0000
+++ b/Wifly/Wifly.cpp	Fri Aug 05 16:13:33 2016 +0000
@@ -21,7 +21,7 @@
 #include <string>
 #include <algorithm>
 
-#define DEBUG
+//#define DEBUG
 #define INFOMESSAGES
 #define WARNMESSAGES
 #define ERRMESSAGES
@@ -66,6 +66,7 @@
     if(baudrate > 0){
         serial_baudrate = baudrate;
     }
+    DBG("Setting wifi shield baudrate to: %d.", serial_baudrate);
     // This sets the baud rate 'instantly'
     sprintf(cmd, "set u i %d\r", serial_baudrate);
     // This one sets it some other way that does not work
@@ -183,7 +184,9 @@
         exit();
 
         state.associated = true;
-        INFO("\r\nssid: %s\r\nphrase: %s\r\nsecurity: %s\r\n\r\n", this->ssid, this->phrase, getStringSecurity());
+        INFO("ssid: %s", this->ssid);
+        INFO("phrase: %s", this->phrase);
+        INFO("security: %s", getStringSecurity());
 
         return true;
     }
@@ -333,7 +336,12 @@
     }
     if (send(cmd, strlen(cmd), ack, res, timeout) == -1) {
         ERR("sendCommand: cannot (%s)", cmd);
-        exit();
+        if(strcmp(cmd, "exit") != 0){
+            exit();
+        }else{
+            WARN("Manually setting cmd_mode to false.");
+            state.cmd_mode = false;
+        }
         return false;
     }
     return true;
@@ -377,11 +385,16 @@
 
 void Wifly::reset()
 {
+    
     reset_pin = 0;
+    wifi.baud(9600);
+    flush();
+    state.cmd_mode = false;
     wait(0.5);
     reset_pin = 1;
+    // Set the serial port baud rate back to default:
     wait(0.5);
-    DBG("Wifi Shield Reset");
+    INFO("Wifi Shield Reset");
     setBaud(-1);
     DBG("Baud Rate updated from Reset.");
 }