Connect Wi-Fi
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 wait(2); 00031 00032 pc.printf("Receiving Wifi List\r\n"); 00033 esp.GetList(rcv); 00034 pc.printf("%s", rcv); 00035 00036 // pc.printf("Setting Wifi\r\n"); 00037 // esp.SetWiFi("ESP8266-MIND", "mindkafuu"); 00038 // esp.RcvReply(rcv, 1000); 00039 // pc.printf("%s", rcv); 00040 // wait(4); 00041 00042 pc.printf("Connecting to AP\r\n"); 00043 esp.Join("Mind", "00000000"); // Replace MyAP and MyPasswd with your SSID and password 00044 esp.RcvReply(rcv, 1000); 00045 pc.printf("%s", rcv); 00046 wait(8); 00047 00048 pc.printf("Check Connected\r\n"); 00049 esp.check(); 00050 esp.RcvReply(rcv, 400); 00051 pc.printf("%s", rcv); 00052 wait(2); 00053 00054 pc.printf("Check Wifi\r\n"); 00055 esp.look(); 00056 esp.RcvReply(rcv, 400); 00057 pc.printf("%s", rcv); 00058 wait(2); 00059 00060 pc.printf("Getting IP\r\n"); 00061 esp.GetIP(rcv); 00062 pc.printf("%s", rcv); 00063 00064 pc.printf("Setting single connections\r\n"); 00065 esp.SetMultiple(); 00066 esp.RcvReply(rcv, 1000); 00067 pc.printf("%s", rcv); 00068 wait(4); 00069 00070 pc.printf("Start server mode on port 9999\r\n"); 00071 esp.StartServerMode(9999); 00072 esp.RcvReply(rcv, 1000); 00073 pc.printf("%s", rcv); 00074 wait(4); 00075 }
Generated on Fri Jul 15 2022 01:56:21 by
1.7.2