ESP8266
Dependencies: mbed
Revision 1:edcfe804de99, committed 2017-12-10
- Comitter:
- chanagan2540
- Date:
- Sun Dec 10 08:08:29 2017 +0000
- Parent:
- 0:3222c85ebd43
- Commit message:
- ???;
Changed in this revision
diff -r 3222c85ebd43 -r edcfe804de99 ESP8266.cpp --- a/ESP8266.cpp Sun Dec 10 06:10:50 2017 +0000 +++ b/ESP8266.cpp Sun Dec 10 08:08:29 2017 +0000 @@ -91,19 +91,23 @@ RcvReply(l, 5000); // Needs big timeout because it takes long to start replying } -void ESP8266::Join(char * id) { +void ESP8266::Join(char * id, char * pwd) { char cmd[255]; strcpy(cmd, "AT+CWJAP="); AddChar(cmd, 0x22); strcat(cmd, id); + AddChar(cmd, 0x22); + AddChar(cmd, 0x2C); + AddChar(cmd, 0x22); + strcat(cmd, pwd); + AddChar(cmd, 0x22); SendCMD(cmd); } -void ESP8266::Check(char * con) { - char cmd[15]; - strcpy(cmd, "AT+CWJAP?"); - SendCMD(cmd); - RcvReply(con, 2000); +void ESP8266::look(void) { + char rs[10]; + strcpy(rs, "AT+CWSAP?"); + SendCMD(rs); } void ESP8266::GetIP(char * ip) { @@ -119,11 +123,19 @@ SendCMD(cmd); } -void ESP8266::SetPath(int path) { - char rs[25]; - char t[4]; - strcpy(rs, "AT+CIPSERVER='TCP','192.168.4.1',"); - itoa(path, t); - strcat(rs, t); - SendCMD(rs); +void ESP8266::SetPath(char * t, char * o, char * v) { + char cmd[255]; + strcpy(cmd, "AT+CIPSTART="); + AddChar(cmd, 0x22); + strcat(cmd, t); + AddChar(cmd, 0x22); + AddChar(cmd, 0x2C); + AddChar(cmd, 0x22); + strcat(cmd, o); + AddChar(cmd, 0x22); + AddChar(cmd, 0x2C); + AddChar(cmd, 0x22); + strcat(cmd, v); + AddChar(cmd, 0x22); + SendCMD(cmd); }
diff -r 3222c85ebd43 -r edcfe804de99 ESP8266.h --- a/ESP8266.h Sun Dec 10 06:10:50 2017 +0000 +++ b/ESP8266.h Sun Dec 10 08:08:29 2017 +0000 @@ -20,14 +20,16 @@ * ESP8266 destructor */ ~ESP8266(); - -void SetPath(int path); + +void check(void); +void look(void); +void SetPath(char * t, char* o, char * v); void Check(char * con); void SendCMD(char * s); void Reset(void); void RcvReply(char * r, int to); void GetList(char * l); -void Join(char * id); +void Join(char * id, char * pwd); void GetIP(char * ip); void SetMode(char mode); void Quit(void);
diff -r 3222c85ebd43 -r edcfe804de99 main.cpp --- a/main.cpp Sun Dec 10 06:10:50 2017 +0000 +++ b/main.cpp Sun Dec 10 08:08:29 2017 +0000 @@ -33,16 +33,17 @@ pc.printf("%s", rcv); pc.printf("Connecting to AP\r\n"); - esp.Join("ESP_FED007"); + esp.Join("Mind", "00000000"); // Replace MyAP and MyPasswd with your SSID and password esp.RcvReply(rcv, 1000); pc.printf("%s", rcv); + wait(8); + + pc.printf("Check Connected\r\n"); + esp.look(); + esp.RcvReply(rcv, 400); + pc.printf("%s", rcv); wait(2); - pc.printf("Check Connect\r\n"); - esp.Check(rcv); - esp.RcvReply(rcv, 200); - pc.printf("%s", rcv); - pc.printf("Getting IP\r\n"); esp.GetIP(rcv); pc.printf("%s", rcv); @@ -54,8 +55,13 @@ wait(4); pc.printf("Connect to Server\r\n"); - esp.SetPath(9999); + esp.SetPath("TCP", "172.20.10.3", "9999"); esp.RcvReply(rcv, 1000); pc.printf("%s", rcv); wait(4); + + pc.printf("Check Connected To Server\r\n"); + esp.check(); + esp.RcvReply(rcv, 400); + pc.printf("%s", rcv); } \ No newline at end of file