Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of SerialPassthroughcjsESP8266 by
main.cpp
00001 /* Simpler prog based on the serial passthrough code to enable a command line driven test of esp8266 00002 * wifi modules. 00003 * NB this uses the mbed sleep() command to form a low power system but on some MCUs this is a problem 00004 * this works fine on an lpc1768 but not as yet on the KL25Z 00005 */ 00006 #include "mbed.h" 00007 00008 Serial pc(USBTX, USBRX); // serial terminal for the pc connection 00009 Serial dev(PTE0,PTE1); // for KL25Z... asuming one can't use the PTA1 version which is the stdio 00010 DigitalOut led1(LED1); // twp leds 00011 DigitalOut led4(LED2); // to allow visual check of bidirectional comms 00012 DigitalOut rst(PTD7); // single digital pin to drive the esp8266 reset line 00013 00014 // subroutine to run anytime a serial interrupt arrives from the device 00015 // this basically passes everything thatthe device produces on to the pc terminal screen 00016 void dev_recv() 00017 { 00018 led1 = !led1; 00019 while(dev.readable()) { 00020 pc.putc(dev.getc()); 00021 wait_us(1); 00022 } 00023 } 00024 // subroutine to service the serial interrupt on the pc connection 00025 // this is a bit more complex - it takes what the use sends on the pc and copies it on to the device 00026 // the esp should echo these straight back to the the pc if all is well 00027 // this also detects the end of command character which is ascii 13 (0x0d) adn adds a linefeed after it =asscii 10 (0x0a) 00028 void pc_recv() 00029 { 00030 char c; 00031 led4 = !led4; 00032 while(pc.readable()) { 00033 c = pc.getc(); 00034 dev.putc(c); 00035 // pc.putc(c); // echo back 00036 if(c==13) { 00037 dev.putc(10); // send the linefeed to complement the carriage return generated by return key on the pc 00038 pc.putc(10); 00039 } 00040 } 00041 } 00042 00043 int main() 00044 { 00045 pc.baud(115200); 00046 dev.baud(115200); 00047 rst=0; 00048 wait(1); 00049 rst = 1; // send the esp8266 reset 00050 wait(1); 00051 00052 pc.attach(&pc_recv, Serial::RxIrq); // attach the two interrupt services 00053 dev.attach(&dev_recv, Serial::RxIrq); 00054 pc.printf("ok off we go....\n\r"); 00055 // wait(10); 00056 // pc.printf("AT+RST\n\r"); 00057 // wait(20); 00058 // pc.printf("AT+CWJAP="CWMWIFI","CWM2016TT""\n\r); 00059 00060 while(1) { 00061 // (i++)%10; // THIS USED TO BE A SLEEP COMMAND BUT IT WAS CAUSING SOME TROUBLE. 00062 } 00063 }
Generated on Fri Jul 22 2022 10:10:24 by
1.7.2
