ESP8266
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 #include <string> 00003 #include "ESP8266.h" 00004 00005 ESP8266 esp(D8, D2, 9600); 00006 Serial pc(D1, D0, 115200); 00007 00008 char snd[255], rcv[1000]; 00009 00010 int main() { 00011 pc.printf("Hello!! \n"); 00012 00013 pc.printf("Reset ESP\r\n"); 00014 esp.Reset(); 00015 esp.RcvReply(rcv, 400); 00016 pc.printf("%s", rcv); 00017 wait(2); 00018 00019 pc.printf("Sending AT\r\n"); 00020 strcpy(snd, "AT"); 00021 esp.SendCMD(snd); 00022 esp.RcvReply(rcv, 400); 00023 pc.printf("%s", rcv); 00024 wait(2); 00025 00026 pc.printf("Set mode to AP\r\n"); 00027 esp.SetMode(1); 00028 esp.RcvReply(rcv, 1000); 00029 pc.printf("%s", rcv); 00030 00031 pc.printf("Receiving Wifi List\r\n"); 00032 esp.GetList(rcv); 00033 pc.printf("%s", rcv); 00034 00035 pc.printf("Connecting to AP\r\n"); 00036 esp.Join("Mind", "00000000"); // Replace MyAP and MyPasswd with your SSID and password 00037 esp.RcvReply(rcv, 1000); 00038 pc.printf("%s", rcv); 00039 wait(8); 00040 00041 pc.printf("Check Connected\r\n"); 00042 esp.look(); 00043 esp.RcvReply(rcv, 400); 00044 pc.printf("%s", rcv); 00045 wait(2); 00046 00047 pc.printf("Getting IP\r\n"); 00048 esp.GetIP(rcv); 00049 pc.printf("%s", rcv); 00050 00051 pc.printf("Setting single connections\r\n"); 00052 esp.SetSingle(); 00053 esp.RcvReply(rcv, 1000); 00054 pc.printf("%s", rcv); 00055 wait(4); 00056 00057 pc.printf("Connect to Server\r\n"); 00058 esp.SetPath("TCP", "172.20.10.3", "9999"); 00059 esp.RcvReply(rcv, 1000); 00060 pc.printf("%s", rcv); 00061 wait(4); 00062 00063 pc.printf("Check Connected To Server\r\n"); 00064 esp.check(); 00065 esp.RcvReply(rcv, 400); 00066 pc.printf("%s", rcv); 00067 }
Generated on Fri Jul 22 2022 10:47:38 by
1.7.2