Wifi module configuration for GR_Peach

Dependencies:   mbed

Revision:
1:e5ef21ebff5f
Parent:
0:7d24b78f9a5e
Child:
2:19bd6403dc75
--- a/Wifi.cpp	Tue Dec 06 05:13:39 2016 +0000
+++ b/Wifi.cpp	Tue Dec 06 14:14:51 2016 +0000
@@ -1,24 +1,78 @@
 #include "mbed.h"
- 
+#include <string>
+
+
+
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
-uint8_t data;
+string data;
 uint8_t wifi_ack;
 Serial pc(USBTX, USBRX);
-Serial Wifi(P2_14,P2_15);
+//Serial Wifi(P2_14,P2_15);
+Serial Wifi(P2_14, P2_15);
+bool i = true;
+bool j = false;
+char MSB;
+char LSB;
+
  
 void call() {
     // Note: you need to actually read from the serial to clear the RX interrupt
-    data = pc.getc();
-    printf("%c\n", data);
-    led2 = !led2;
+    data = Wifi.getc();
+    pc.printf("%c\n", data);
+    // Wifi.printf("%c",data);
 }
  
 int main() {
     
     //pc.attach(&call);
-    Wifi.baud(9600);
-    Wifi.printf("AT");
-    wifi_ack = Wifi.getc();
-    pc.printf("%s\n", wifi_ack);
-    }
\ No newline at end of file
+    pc.baud(9600);
+    Wifi.baud(115200);
+    //Wifi.attach(&call);
+    /*while(1){
+        //Wifi.printf("AT\n");
+        //pc.printf("done!\n");
+        
+        if(pc.readable()) {
+            pc.putc(pc.getc());
+            led1 = ~led1;
+        }
+        if(Wifi.readable()) {
+            pc.putc(Wifi.getc());
+            led2 = ~led2;
+        }
+        
+            
+        //wifi_ack = Wifi.getc();
+        //pc.printf("%c\n", wifi_ack);
+        //wait(5);
+    }*/
+    
+    while (1)
+    {
+          if(Wifi.readable()) // check if the esp is sending a message 
+              {
+                while(Wifi.readable())
+                {
+                  // The esp has data so display its output to the serial window 
+                  char c = Wifi.getc(); // read the next character.
+                  pc.putc(c);
+                  //pc.printf("%c", c);
+                  i=~i;
+                }  
+              }
+            if(pc.readable()) // check if the esp is sending a message 
+              {
+                while(pc.readable())
+                {
+                  // The esp has data so display its output to the serial window 
+                  char d = pc.getc(); // read the next character.
+                  Wifi.putc(d);
+                  //pc.printf("%c", c);
+                  j=~j;
+                }
+              }
+            led1=i;
+            led2=j;
+        }
+}
\ No newline at end of file