ESP8266

Dependencies:   mbed

Committer:
chanagan2540
Date:
Sun Dec 10 08:08:29 2017 +0000
Revision:
1:edcfe804de99
Parent:
0:3222c85ebd43
???;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chanagan2540 0:3222c85ebd43 1 #include "mbed.h"
chanagan2540 0:3222c85ebd43 2 #include <string>
chanagan2540 0:3222c85ebd43 3 #include "ESP8266.h"
chanagan2540 0:3222c85ebd43 4
chanagan2540 0:3222c85ebd43 5 ESP8266 esp(D8, D2, 9600);
chanagan2540 0:3222c85ebd43 6 Serial pc(D1, D0, 115200);
chanagan2540 0:3222c85ebd43 7
chanagan2540 0:3222c85ebd43 8 char snd[255], rcv[1000];
chanagan2540 0:3222c85ebd43 9
chanagan2540 0:3222c85ebd43 10 int main() {
chanagan2540 0:3222c85ebd43 11 pc.printf("Hello!! \n");
chanagan2540 0:3222c85ebd43 12
chanagan2540 0:3222c85ebd43 13 pc.printf("Reset ESP\r\n");
chanagan2540 0:3222c85ebd43 14 esp.Reset();
chanagan2540 0:3222c85ebd43 15 esp.RcvReply(rcv, 400);
chanagan2540 0:3222c85ebd43 16 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 17 wait(2);
chanagan2540 0:3222c85ebd43 18
chanagan2540 0:3222c85ebd43 19 pc.printf("Sending AT\r\n");
chanagan2540 0:3222c85ebd43 20 strcpy(snd, "AT");
chanagan2540 0:3222c85ebd43 21 esp.SendCMD(snd);
chanagan2540 0:3222c85ebd43 22 esp.RcvReply(rcv, 400);
chanagan2540 0:3222c85ebd43 23 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 24 wait(2);
chanagan2540 0:3222c85ebd43 25
chanagan2540 0:3222c85ebd43 26 pc.printf("Set mode to AP\r\n");
chanagan2540 0:3222c85ebd43 27 esp.SetMode(1);
chanagan2540 0:3222c85ebd43 28 esp.RcvReply(rcv, 1000);
chanagan2540 0:3222c85ebd43 29 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 30
chanagan2540 0:3222c85ebd43 31 pc.printf("Receiving Wifi List\r\n");
chanagan2540 0:3222c85ebd43 32 esp.GetList(rcv);
chanagan2540 0:3222c85ebd43 33 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 34
chanagan2540 0:3222c85ebd43 35 pc.printf("Connecting to AP\r\n");
chanagan2540 1:edcfe804de99 36 esp.Join("Mind", "00000000"); // Replace MyAP and MyPasswd with your SSID and password
chanagan2540 0:3222c85ebd43 37 esp.RcvReply(rcv, 1000);
chanagan2540 0:3222c85ebd43 38 pc.printf("%s", rcv);
chanagan2540 1:edcfe804de99 39 wait(8);
chanagan2540 1:edcfe804de99 40
chanagan2540 1:edcfe804de99 41 pc.printf("Check Connected\r\n");
chanagan2540 1:edcfe804de99 42 esp.look();
chanagan2540 1:edcfe804de99 43 esp.RcvReply(rcv, 400);
chanagan2540 1:edcfe804de99 44 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 45 wait(2);
chanagan2540 0:3222c85ebd43 46
chanagan2540 0:3222c85ebd43 47 pc.printf("Getting IP\r\n");
chanagan2540 0:3222c85ebd43 48 esp.GetIP(rcv);
chanagan2540 0:3222c85ebd43 49 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 50
chanagan2540 0:3222c85ebd43 51 pc.printf("Setting single connections\r\n");
chanagan2540 0:3222c85ebd43 52 esp.SetSingle();
chanagan2540 0:3222c85ebd43 53 esp.RcvReply(rcv, 1000);
chanagan2540 0:3222c85ebd43 54 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 55 wait(4);
chanagan2540 0:3222c85ebd43 56
chanagan2540 0:3222c85ebd43 57 pc.printf("Connect to Server\r\n");
chanagan2540 1:edcfe804de99 58 esp.SetPath("TCP", "172.20.10.3", "9999");
chanagan2540 0:3222c85ebd43 59 esp.RcvReply(rcv, 1000);
chanagan2540 0:3222c85ebd43 60 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 61 wait(4);
chanagan2540 1:edcfe804de99 62
chanagan2540 1:edcfe804de99 63 pc.printf("Check Connected To Server\r\n");
chanagan2540 1:edcfe804de99 64 esp.check();
chanagan2540 1:edcfe804de99 65 esp.RcvReply(rcv, 400);
chanagan2540 1:edcfe804de99 66 pc.printf("%s", rcv);
chanagan2540 0:3222c85ebd43 67 }