ESP8266

Dependencies:   mbed

Fork of Client-ESP8266 by Digital dog

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <string>
00003 #include "ESP8266.h"
00004 
00005 ESP8266 esp(D8, D2, 115200);
00006 Serial pc(D1, D0, 115200);
00007 
00008 char snd[255], rcv[1000];
00009 
00010 int main() {   
00011     pc.printf("Hello!! \n");
00012         
00013     pc.printf("Reset ESP\r\n");
00014     esp.Reset();
00015     esp.RcvReply(rcv, 400);
00016     pc.printf("%s", rcv);
00017     wait(2);
00018     
00019     pc.printf("Sending AT\r\n");
00020     strcpy(snd, "AT");
00021     esp.SendCMD(snd);
00022     esp.RcvReply(rcv, 400);
00023     pc.printf("%s", rcv);
00024     wait(2);
00025     
00026     pc.printf("Set mode to AP\r\n");
00027     esp.SetMode(1);
00028     esp.RcvReply(rcv, 1000);
00029     pc.printf("%s", rcv);
00030     wait(2);
00031     
00032 //    pc.printf("Receiving Wifi List\r\n");
00033 //    esp.GetList(rcv);
00034 //    pc.printf("%s", rcv);
00035     
00036     pc.printf("Connecting to AP\r\n");
00037     esp.Join("Mind", "mmmmmmmm"); // Replace MyAP and MyPasswd with your SSID and password
00038     esp.RcvReply(rcv, 5000);
00039     pc.printf("%s", rcv);
00040     wait(8);
00041 
00042     pc.printf("Check Connected\r\n");
00043     esp.look();
00044     esp.RcvReply(rcv, 400);
00045     pc.printf("%s", rcv);
00046     wait(2);
00047     
00048     pc.printf("Getting IP\r\n");
00049     esp.GetIP(rcv);
00050     pc.printf("%s", rcv);
00051         
00052 //    pc.printf("Set transfer mode\r\n");
00053 //    esp.transfer();
00054 //    esp.RcvReply(rcv, 1000);
00055 //    pc.printf("%s", rcv);
00056 //    wait(2);
00057             
00058     pc.printf("Setting single connections\r\n");
00059     esp.SetSingle();
00060     esp.RcvReply(rcv, 1000);
00061     pc.printf("%s", rcv);
00062     wait(4);
00063     
00064     pc.printf("Connect to Server\r\n");
00065     esp.SetPath("TCP", "172.20.10.2", "80");
00066     esp.RcvReply(rcv, 5000);
00067     pc.printf("%s", rcv);
00068     wait(4);
00069     
00070     //pc.printf("Sent Data\r\n");
00071 //    esp.SendData("hello");
00072 //    esp.RcvReply(rcv, 1000);
00073 //    pc.printf("%s", rcv);
00074 //    wait(4);
00075     
00076     while(1) {
00077         esp.RcvReply(rcv, 5000);
00078         pc.printf("%s", rcv);
00079         wait(2);
00080         
00081         pc.printf("Check Data\r\n");
00082         esp.check();
00083         esp.RcvReply(rcv, 400);
00084         pc.printf("%s", rcv);
00085         wait(2);
00086     }
00087 }