Chanagan Kanokwattananon
/
Server
Connect Wi-Fi
Fork of Server-ESP8266 by
main.cpp@4:217a562d8950, 2017-12-10 (annotated)
- Committer:
- chanagan2540
- Date:
- Sun Dec 10 18:46:42 2017 +0000
- Revision:
- 4:217a562d8950
- Parent:
- 3:e1042768703b
- Child:
- 5:569ef8ad0b45
fuck
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 | 4:217a562d8950 | 4 | //////////////// |
chanagan2540 | 1:c0fbff97b740 | 5 | ESP8266 esp(D8, D2, 9600); |
chanagan2540 | 4:217a562d8950 | 6 | Serial pc(D1, D0); |
chanagan2540 | 1:c0fbff97b740 | 7 | |
chanagan2540 | 1:c0fbff97b740 | 8 | char snd[255], rcv[1000]; |
chanagan2540 | 0:3c8c53e45689 | 9 | |
chanagan2540 | 4:217a562d8950 | 10 | int main() |
chanagan2540 | 4:217a562d8950 | 11 | { |
chanagan2540 | 1:c0fbff97b740 | 12 | pc.printf("Hello!! \n"); |
chanagan2540 | 4:217a562d8950 | 13 | |
chanagan2540 | 1:c0fbff97b740 | 14 | pc.printf("Reset ESP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 15 | esp.Reset(); |
chanagan2540 | 1:c0fbff97b740 | 16 | esp.RcvReply(rcv, 400); |
chanagan2540 | 1:c0fbff97b740 | 17 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 18 | wait(2); |
chanagan2540 | 4:217a562d8950 | 19 | |
chanagan2540 | 1:c0fbff97b740 | 20 | pc.printf("Sending AT\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 21 | strcpy(snd, "AT"); |
chanagan2540 | 1:c0fbff97b740 | 22 | esp.SendCMD(snd); |
chanagan2540 | 1:c0fbff97b740 | 23 | esp.RcvReply(rcv, 400); |
chanagan2540 | 1:c0fbff97b740 | 24 | pc.printf("%s", rcv); |
chanagan2540 | 1:c0fbff97b740 | 25 | wait(2); |
chanagan2540 | 4:217a562d8950 | 26 | |
chanagan2540 | 1:c0fbff97b740 | 27 | pc.printf("Set mode to AP\r\n"); |
chanagan2540 | 4:217a562d8950 | 28 | esp.SetMode(3); |
chanagan2540 | 1:c0fbff97b740 | 29 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 1:c0fbff97b740 | 30 | pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 31 | wait(2); |
chanagan2540 | 4:217a562d8950 | 32 | |
chanagan2540 | 1:c0fbff97b740 | 33 | pc.printf("Receiving Wifi List\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 34 | esp.GetList(rcv); |
chanagan2540 | 1:c0fbff97b740 | 35 | pc.printf("%s", rcv); |
chanagan2540 | 4:217a562d8950 | 36 | |
chanagan2540 | 4:217a562d8950 | 37 | //pc.printf("Setting Wifi\r\n"); |
chanagan2540 | 3:e1042768703b | 38 | // esp.SetWiFi("ESP8266-MIND", "mindkafuu"); |
chanagan2540 | 3:e1042768703b | 39 | // esp.RcvReply(rcv, 1000); |
chanagan2540 | 3:e1042768703b | 40 | // pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 41 | // wait(4); |
chanagan2540 | 4:217a562d8950 | 42 | |
chanagan2540 | 1:c0fbff97b740 | 43 | pc.printf("Connecting to AP\r\n"); |
chanagan2540 | 4:217a562d8950 | 44 | esp.Join("BIN11_2G", "789789BN"); // Replace MyAP and MyPasswd with your SSID and password |
chanagan2540 | 1:c0fbff97b740 | 45 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 1:c0fbff97b740 | 46 | pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 47 | wait(8); |
chanagan2540 | 4:217a562d8950 | 48 | |
chanagan2540 | 3:e1042768703b | 49 | pc.printf("Check Connected\r\n"); |
chanagan2540 | 3:e1042768703b | 50 | esp.check(); |
chanagan2540 | 3:e1042768703b | 51 | esp.RcvReply(rcv, 400); |
chanagan2540 | 3:e1042768703b | 52 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 53 | wait(2); |
chanagan2540 | 4:217a562d8950 | 54 | |
chanagan2540 | 3:e1042768703b | 55 | pc.printf("Check Wifi\r\n"); |
chanagan2540 | 3:e1042768703b | 56 | esp.look(); |
chanagan2540 | 3:e1042768703b | 57 | esp.RcvReply(rcv, 400); |
chanagan2540 | 2:6738db3eb2ed | 58 | pc.printf("%s", rcv); |
chanagan2540 | 3:e1042768703b | 59 | wait(2); |
chanagan2540 | 4:217a562d8950 | 60 | |
chanagan2540 | 1:c0fbff97b740 | 61 | pc.printf("Getting IP\r\n"); |
chanagan2540 | 1:c0fbff97b740 | 62 | esp.GetIP(rcv); |
chanagan2540 | 1:c0fbff97b740 | 63 | pc.printf("%s", rcv); |
chanagan2540 | 4:217a562d8950 | 64 | |
chanagan2540 | 4:217a562d8950 | 65 | pc.printf("Setting multiple connections\r\n"); |
chanagan2540 | 2:6738db3eb2ed | 66 | esp.SetMultiple(); |
chanagan2540 | 2:6738db3eb2ed | 67 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 2:6738db3eb2ed | 68 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 69 | wait(4); |
chanagan2540 | 4:217a562d8950 | 70 | |
chanagan2540 | 4:217a562d8950 | 71 | pc.printf("Start server mode on port 80\r\n"); |
chanagan2540 | 4:217a562d8950 | 72 | esp.StartServerMode(80); |
chanagan2540 | 2:6738db3eb2ed | 73 | esp.RcvReply(rcv, 1000); |
chanagan2540 | 2:6738db3eb2ed | 74 | pc.printf("%s", rcv); |
chanagan2540 | 2:6738db3eb2ed | 75 | wait(4); |
chanagan2540 | 4:217a562d8950 | 76 | |
chanagan2540 | 4:217a562d8950 | 77 | while(1) { |
chanagan2540 | 4:217a562d8950 | 78 | esp.CheckIP(); |
chanagan2540 | 4:217a562d8950 | 79 | esp.RcvReply(rcv, 5000); |
chanagan2540 | 4:217a562d8950 | 80 | pc.printf("%s", rcv); |
chanagan2540 | 4:217a562d8950 | 81 | wait(2); |
chanagan2540 | 4:217a562d8950 | 82 | } |
chanagan2540 | 0:3c8c53e45689 | 83 | } |