Damien Frost / WiflyInterface

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Fork of WiflyInterface by Components

Revision:
35:ce3afc021ec2
Parent:
34:a22a6343e3d4
Child:
36:8774837f5a78
--- a/Wifly/Wifly.cpp	Sun Jul 10 11:13:33 2016 +0000
+++ b/Wifly/Wifly.cpp	Fri Aug 05 13:31:37 2016 +0000
@@ -21,7 +21,7 @@
 #include <string>
 #include <algorithm>
 
-//#define DEBUG
+#define DEBUG
 #define INFOMESSAGES
 #define WARNMESSAGES
 #define ERRMESSAGES
@@ -35,6 +35,9 @@
 Wifly::Wifly(   PinName tx, PinName rx, PinName _reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec):
     wifi(tx, rx), reset_pin(_reset), tcp_status(tcp_status), buf_wifly(1024)
 {
+    // Set the default baud rate:
+    serial_baudrate = 9600;
+    
     memset(&state, 0, sizeof(state));
     state.sec = sec;
 
@@ -53,21 +56,25 @@
     inst = this;
     attach_rx(false);
     state.cmd_mode = false;
+    DBG("Wifly Constructed");
 }
 
-
 void Wifly::setBaud(int baudrate)
 {
     char cmd[28];
+    // Save the baudrate:
+    if(baudrate > 0){
+        serial_baudrate = baudrate;
+    }
     // This sets the baud rate 'instantly'
-    sprintf(cmd, "set u i %d\r", baudrate);
+    sprintf(cmd, "set u i %d\r", serial_baudrate);
     // This one sets it some other way that does not work
     //sprintf(cmd, "set u b %d\r", baudrate);
     // Set baud rate of wifly:
     sendCommand(cmd, NULL);
     wait(0.5);
     // Set baud rate of UART:
-    wifi.baud(baudrate);
+    wifi.baud(serial_baudrate);
     wait(0.5);
     exit();
 }
@@ -371,9 +378,12 @@
 void Wifly::reset()
 {
     reset_pin = 0;
-    wait(0.2);
+    wait(0.5);
     reset_pin = 1;
-    wait(0.2);
+    wait(0.5);
+    DBG("Wifi Shield Reset");
+    setBaud(-1);
+    DBG("Baud Rate updated from Reset.");
 }
 
 bool Wifly::reboot()