Chanagan Kanokwattananon
/
Server
Connect Wi-Fi
Fork of Server-ESP8266 by
main.cpp@1:c0fbff97b740, 2017-12-09 (annotated)
- Committer:
- chanagan2540
- Date:
- Sat Dec 09 20:43:11 2017 +0000
- Revision:
- 1:c0fbff97b740
- Parent:
- 0:3c8c53e45689
- Child:
- 2:6738db3eb2ed
esp8266
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chanagan2540 | 0:3c8c53e45689 | 1 | #include "mbed.h" |
chanagan2540 | 1:c0fbff97b740 | 2 | #include <string> |
chanagan2540 | 1:c0fbff97b740 | 3 | #include "ESP8266.h" |
chanagan2540 | 1:c0fbff97b740 | 4 | |
chanagan2540 | 1:c0fbff97b740 | 5 | ESP8266 esp(D8, D2, 9600); |
chanagan2540 | 1:c0fbff97b740 | 6 | Serial pc(D1, D0, 115200); |
chanagan2540 | 1:c0fbff97b740 | 7 | |
chanagan2540 | 1:c0fbff97b740 | 8 | char snd[255], rcv[1000]; |
chanagan2540 | 0:3c8c53e45689 | 9 | |
chanagan2540 | 1:c0fbff97b740 | 10 | int main() { |
chanagan2540 | 1:c0fbff97b740 | 11 | pc.printf("Hello!! \n"); |
chanagan2540 | 1:c0fbff97b740 | 12 | |
chanagan2540 | 1:c0fbff97b740 | 13 | pc.printf("Reset ESP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 14 | esp.Reset(); |
chanagan2540 | 1:c0fbff97b740 | 15 | esp.RcvReply(rcv, 400); |
chanagan2540 | 1:c0fbff97b740 | 16 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 17 | wait(2); |
chanagan2540 | 0:3c8c53e45689 | 18 | |
chanagan2540 | 1:c0fbff97b740 | 19 | pc.printf("Sending AT\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 20 | strcpy(snd, "AT"); |
chanagan2540 | 1:c0fbff97b740 | 21 | esp.SendCMD(snd); |
chanagan2540 | 1:c0fbff97b740 | 22 | esp.RcvReply(rcv, 400); |
chanagan2540 | 1:c0fbff97b740 | 23 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 24 | wait(2); |
chanagan2540 | 1:c0fbff97b740 | 25 | |
chanagan2540 | 1:c0fbff97b740 | 26 | pc.printf("Set mode to AP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 27 | esp.SetMode(3); |
chanagan2540 | 1:c0fbff97b740 | 28 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 1:c0fbff97b740 | 29 | pc.printf("%s", rcv); |
chanagan2540 | 0:3c8c53e45689 | 30 | |
chanagan2540 | 1:c0fbff97b740 | 31 | pc.printf("Receiving Wifi List\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 32 | esp.GetList(rcv); |
chanagan2540 | 1:c0fbff97b740 | 33 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 34 | |
chanagan2540 | 1:c0fbff97b740 | 35 | pc.printf("Connecting to AP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 36 | esp.Join("Mind", "00000000"); // Replace MyAP and MyPasswd with your SSID and password |
chanagan2540 | 1:c0fbff97b740 | 37 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 1:c0fbff97b740 | 38 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 39 | wait(8); |
chanagan2540 | 1:c0fbff97b740 | 40 | |
chanagan2540 | 1:c0fbff97b740 | 41 | pc.printf("Getting IP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 42 | esp.GetIP(rcv); |
chanagan2540 | 1:c0fbff97b740 | 43 | pc.printf("%s", rcv); |
chanagan2540 | 0:3c8c53e45689 | 44 | } |