Connect Wi-Fi
Dependencies: mbed
Diff: ESP8266.cpp
- Revision:
- 2:6738db3eb2ed
- Parent:
- 1:c0fbff97b740
- Child:
- 3:e1042768703b
--- a/ESP8266.cpp Sat Dec 09 20:43:11 2017 +0000 +++ b/ESP8266.cpp Sat Dec 09 22:20:18 2017 +0000 @@ -23,6 +23,28 @@ s[k + 1] = 0; } +void ESP8266::itoa(int n, char * s) { + char k = 0; + char r[11]; + + if(n == 0) { + s[0] = '0'; + s[1] = 0; + } else { + while(n != 0) { + r[k]= (n % 10) + '0'; + n = n / 10; + k++; + } + while(k > 0) { + s[n] = r[k - 1] + '0'; + n++; + k--; + } + s[n] = 0; + } +} + void ESP8266::SendCMD(char * s) { AddEOL(s); comm.printf("%s", s); @@ -82,9 +104,31 @@ SendCMD(cmd); } +void ESP8266::Check(char * con) { + char cmd[15]; + strcpy(cmd, "AT+CWJAP?"); + SendCMD(cmd); + RcvReply(con, 2000); +} + void ESP8266::GetIP(char * ip) { char cmd[15]; strcpy(cmd, "AT+CIFSR"); SendCMD(cmd); RcvReply(ip, 2000); } + +void ESP8266::SetMultiple(void) { + char rs[15]; + strcpy(rs, "AT+CIPMUX=1"); + SendCMD(rs); +} + +void ESP8266::StartServerMode(int port) { + char rs[25]; + char t[4]; + strcpy(rs, "AT+CIPSERVER=1,"); + itoa(port, t); + strcat(rs, t); + SendCMD(rs); +}