Connect Wi-Fi

Dependencies:   mbed

Committer:
chanagan2540
Date:
Sat Dec 09 22:20:18 2017 +0000
Revision:
2:6738db3eb2ed
Parent:
1:c0fbff97b740
Child:
3:e1042768703b
esp8266

Who changed what in which revision?

UserRevisionLine numberNew 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 2:6738db3eb2ed 39 wait(2);
chanagan2540 2:6738db3eb2ed 40
chanagan2540 2:6738db3eb2ed 41 pc.printf("Check Connect\r\n");
chanagan2540 2:6738db3eb2ed 42 esp.Check(rcv);
chanagan2540 2:6738db3eb2ed 43 esp.RcvReply(rcv, 200);
chanagan2540 2:6738db3eb2ed 44 pc.printf("%s", rcv);
chanagan2540 1:c0fbff97b740 45
chanagan2540 1:c0fbff97b740 46 pc.printf("Getting IP\r\n");
chanagan2540 1:c0fbff97b740 47 esp.GetIP(rcv);
chanagan2540 1:c0fbff97b740 48 pc.printf("%s", rcv);
chanagan2540 2:6738db3eb2ed 49
chanagan2540 2:6738db3eb2ed 50 pc.printf("Setting multiple connections\r\n");
chanagan2540 2:6738db3eb2ed 51 esp.SetMultiple();
chanagan2540 2:6738db3eb2ed 52 esp.RcvReply(rcv, 1000);
chanagan2540 2:6738db3eb2ed 53 pc.printf("%s", rcv);
chanagan2540 2:6738db3eb2ed 54 wait(4);
chanagan2540 2:6738db3eb2ed 55
chanagan2540 2:6738db3eb2ed 56 pc.printf("Start server mode on port 81\r\n");
chanagan2540 2:6738db3eb2ed 57 esp.StartServerMode(9999);
chanagan2540 2:6738db3eb2ed 58 esp.RcvReply(rcv, 1000);
chanagan2540 2:6738db3eb2ed 59 pc.printf("%s", rcv);
chanagan2540 2:6738db3eb2ed 60 wait(4);
chanagan2540 0:3c8c53e45689 61 }