WIFI

Dependencies:   mbed

Fork of SerialPassthroughcjsESP8266 by chris stevens

Files at this revision

API Documentation at this revision

Comitter:
wadh4587
Date:
Wed Jun 15 14:47:19 2016 +0000
Parent:
9:b1344ca3497d
Commit message:
WIFI ESP8266 & KL25Z

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Jun 08 10:07:11 2016 +0000
+++ b/main.cpp	Wed Jun 15 14:47:19 2016 +0000
@@ -5,12 +5,11 @@
 */
 #include "mbed.h"
 
-RawSerial  pc(USBTX, USBRX); // serial terminal for the pc connection
-//RawSerial dev(PTE0,PTE1);  // for KL25Z... asuming one can't use the PTA1 version which is the stdio
-RawSerial  dev(p28,p27); // serial uart for connecting to the esp8266 tx,rx NB mbed tx must connect ot esp rx and vice versa
-DigitalOut led1(LED1); // twp leds  
-DigitalOut led4(LED4); // to allow visual check of bidirectional comms
-DigitalOut rst(p26); // single digital pin to drive the esp8266 reset line
+Serial pc(USBTX, USBRX); // serial terminal for the pc connection
+Serial dev(PTE0,PTE1);  // for KL25Z... asuming one can't use the PTA1 version which is the stdio
+DigitalOut led1(LED1); // twp leds
+DigitalOut led4(LED2); // to allow visual check of bidirectional comms
+DigitalOut rst(PTD7); // single digital pin to drive the esp8266 reset line
 
 // subroutine to run anytime a serial interrupt arrives from the device
 // this basically passes everything thatthe device produces on to the pc terminal screen
@@ -19,11 +18,11 @@
     led1 = !led1;
     while(dev.readable()) {
         pc.putc(dev.getc());
-        //wait_us(1);
+        wait_us(1);
     }
 }
 // subroutine to service the serial interrupt on the pc connection
-// this is a bit more complex - it takes what the use sends on the pc and copies it on to the device 
+// this is a bit more complex - it takes what the use sends on the pc and copies it on to the device
 // the esp should echo these straight back to the the pc if all is well
 // this also detects the end of command character which is ascii 13 (0x0d) adn adds a linefeed after it =asscii 10 (0x0a)
 void pc_recv()
@@ -31,33 +30,34 @@
     char c;
     led4 = !led4;
     while(pc.readable()) {
-        c=pc.getc();
+        c = pc.getc();
         dev.putc(c);
-        //pc.putc(c); // echo back
-        if(c==13) {dev.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc
-        pc.putc(10);
-            }
+        //  pc.putc(c); // echo back
+        if(c==13) {
+            dev.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc
+            pc.putc(10);
+        }
     }
 }
 
 int main()
 {
+    pc.baud(115200);
+    dev.baud(115200);
     rst=0;
     wait(1);
-    rst=1; // send the esp8266 reset
+    rst = 1; // send the esp8266 reset
     wait(1);
-    pc.printf("ok off we go....\n\r");
-    
-    pc.baud(115200); // NB maybe this should go before this
-    dev.baud(115200);
 
     pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services
     dev.attach(&dev_recv, Serial::RxIrq);
-    
-    
-int i=0;
+    pc.printf("ok off we go....\n\r");
+//    wait(10);
+//    pc.printf("AT+RST\n\r");
+//    wait(20);
+//        pc.printf("AT+CWJAP="CWMWIFI","CWM2016TT""\n\r);
+
     while(1) {
-        
-       (i++)%10; // THIS USED TO BE A SLEEP COMMAND BUT IT WAS CAUSING SOME TROUBLE.
+//        (i++)%10; // THIS USED TO BE A SLEEP COMMAND BUT IT WAS CAUSING SOME TROUBLE.
     }
-}
+}
\ No newline at end of file