Connect Wi-Fi
Dependencies: mbed
main.cpp@3:e1042768703b, 2017-12-10 (annotated)
- Committer:
- chanagan2540
- Date:
- Sun Dec 10 08:08:41 2017 +0000
- Revision:
- 3:e1042768703b
- Parent:
- 2:6738db3eb2ed
????;
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 | 3:e1042768703b | 27 | esp.SetMode(1); |
chanagan2540 | 1:c0fbff97b740 | 28 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 1:c0fbff97b740 | 29 | pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 30 | wait(2); |
chanagan2540 | 0:3c8c53e45689 | 31 | |
chanagan2540 | 1:c0fbff97b740 | 32 | pc.printf("Receiving Wifi List\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 33 | esp.GetList(rcv); |
chanagan2540 | 1:c0fbff97b740 | 34 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 35 | |
chanagan2540 | 3:e1042768703b | 36 | // pc.printf("Setting Wifi\r\n"); |
chanagan2540 | 3:e1042768703b | 37 | // esp.SetWiFi("ESP8266-MIND", "mindkafuu"); |
chanagan2540 | 3:e1042768703b | 38 | // esp.RcvReply(rcv, 1000); |
chanagan2540 | 3:e1042768703b | 39 | // pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 40 | // wait(4); |
chanagan2540 | 3:e1042768703b | 41 | |
chanagan2540 | 1:c0fbff97b740 | 42 | pc.printf("Connecting to AP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 43 | esp.Join("Mind", "00000000"); // Replace MyAP and MyPasswd with your SSID and password |
chanagan2540 | 1:c0fbff97b740 | 44 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 1:c0fbff97b740 | 45 | pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 46 | wait(8); |
chanagan2540 | 3:e1042768703b | 47 | |
chanagan2540 | 3:e1042768703b | 48 | pc.printf("Check Connected\r\n"); |
chanagan2540 | 3:e1042768703b | 49 | esp.check(); |
chanagan2540 | 3:e1042768703b | 50 | esp.RcvReply(rcv, 400); |
chanagan2540 | 3:e1042768703b | 51 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 52 | wait(2); |
chanagan2540 | 2:6738db3eb2ed | 53 | |
chanagan2540 | 3:e1042768703b | 54 | pc.printf("Check Wifi\r\n"); |
chanagan2540 | 3:e1042768703b | 55 | esp.look(); |
chanagan2540 | 3:e1042768703b | 56 | esp.RcvReply(rcv, 400); |
chanagan2540 | 2:6738db3eb2ed | 57 | pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 58 | wait(2); |
chanagan2540 | 1:c0fbff97b740 | 59 | |
chanagan2540 | 1:c0fbff97b740 | 60 | pc.printf("Getting IP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 61 | esp.GetIP(rcv); |
chanagan2540 | 1:c0fbff97b740 | 62 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 63 | |
chanagan2540 | 3:e1042768703b | 64 | pc.printf("Setting single connections\r\n"); |
chanagan2540 | 2:6738db3eb2ed | 65 | esp.SetMultiple(); |
chanagan2540 | 2:6738db3eb2ed | 66 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 2:6738db3eb2ed | 67 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 68 | wait(4); |
chanagan2540 | 2:6738db3eb2ed | 69 | |
chanagan2540 | 3:e1042768703b | 70 | pc.printf("Start server mode on port 9999\r\n"); |
chanagan2540 | 2:6738db3eb2ed | 71 | esp.StartServerMode(9999); |
chanagan2540 | 2:6738db3eb2ed | 72 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 2:6738db3eb2ed | 73 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 74 | wait(4); |
chanagan2540 | 0:3c8c53e45689 | 75 | } |