wifi setup APmode

Dependencies:   mbed

Revision:
6:c3c9277c64ba
Parent:
5:9f46b8cdd469
Child:
7:8055eb42a0f0
--- a/main.cpp	Fri Aug 28 01:21:15 2015 +0000
+++ b/main.cpp	Mon Aug 24 02:36:06 2020 +0000
@@ -1,7 +1,9 @@
+//https://translate.googleusercontent.com/translate_c?anno=2&depth=1&hl=ja&prev=search&rurl=translate.google.co.jp&sl=en&sp=nmt4&tl=ja&u=https://os.mbed.com/users/4180_1/code/ESP8266-configuration-mbed-LPC1768/&usg=ALkJrhgXBJ5ngwZUdq75QAiih4mRDcyBfg
+//wifi接続確認
 #include "mbed.h"
 
 Serial pc(USBTX, USBRX);
-Serial esp(p28, p27); // tx, rx
+Serial esp(p13, p14); // tx, rx
 DigitalOut reset(p26);
 Timer t;
 
@@ -9,8 +11,18 @@
 char buf[1024];
 char snd[255];
 
-char ssid[32] = "mySSID";     // enter WiFi router ssid inside the quotes
-char pwd [32] = "myPASSWORD"; // enter WiFi router password inside the quotes
+//char ssid[32] = "iP-202004T0898";
+//char pwd [32] = "ew3a9baz9o2vk";
+//char ssid[32] = "802ZTa-00311F";     // enter WiFi router ssid inside the quotes
+//char pwd [32] = "0126954a"; // enter WiFi router password inside the quotes
+//char ssid[32] = "802ZTa-008AD0";
+//char pwd [32] = "0355967a";
+
+//char ssid[32] = "802ZTa-003243";
+//char pwd [32] = "0129875a";
+
+char ssid[32] = "mbed01";
+char pwd [32] = "0123456789a";
 
 void SendCMD(),getreply(),ESPconfig(),ESPsetbaudrate();
 
@@ -35,13 +47,13 @@
 
     // continuosly get AP list and IP
     while(1) {
-        pc.printf("\n---------- Listing Acces Points ----------\r\n");
-        strcpy(snd, "AT+CWLAP\r\n");
-        SendCMD();
-        timeout=15;
-        getreply();
-        pc.printf(buf);
-        wait(2);
+//        pc.printf("\n---------- Listing Acces Points ----------\r\n");
+//        strcpy(snd, "AT+CWLAP\r\n");
+//        SendCMD();
+//        timeout=15;
+//        getreply();
+//        pc.printf(buf);
+//        wait(2);
         pc.printf("\n---------- Get IP and MAC ----------\r\n");
         strcpy(snd, "AT+CIFSR\r\n");
         SendCMD();
@@ -97,7 +109,7 @@
 
     // set CWMODE to 1=Station,2=AP,3=BOTH, default mode 1 (Station)
     pc.printf("\n---------- Setting Mode ----------\r\n");
-    strcpy(snd, "AT+CWMODE=1\r\n");
+    strcpy(snd, "AT+CWMODE=2\r\n");
     SendCMD();
     timeout=4;
     getreply();
@@ -107,7 +119,7 @@
 
     // set CIPMUX to 0=Single,1=Multi
     pc.printf("\n---------- Setting Connection Mode ----------\r\n");
-    strcpy(snd, "AT+CIPMUX=1\r\n");
+    strcpy(snd, "AT+CIPMUX=0\r\n");
     SendCMD();
     timeout=4;
     getreply();
@@ -115,22 +127,44 @@
 
     wait(2);
 
-    pc.printf("\n---------- Listing Access Points ----------\r\n");
-    strcpy(snd, "AT+CWLAP\r\n");
-    SendCMD();
-    timeout=15;
-    getreply();
-    pc.printf(buf);
+//    pc.printf("\n---------- Listing Access Points ----------\r\n");
+//    strcpy(snd, "AT+CWLAP\r\n");
+//    SendCMD();
+//    timeout=15;
+//    getreply();
+//    pc.printf(buf);
+//
+//    wait(2);
+//---------------------------------------------------------------------------------------------------------------------------------------------
+//    pc.printf("\n---------- Connecting to AP ----------\r\n");
+//    pc.printf("ssid = %s   pwd = %s\r\n",ssid,pwd);
+//    strcpy(snd, "AT+CWJAP=\"");
+//    strcat(snd, ssid);
+//    strcat(snd, "\",\""); //  "," を入力
+//    strcat(snd, pwd);
+//    strcat(snd, "\"\r\n"); // "を入力し改行             //「AT+CWJAP="ssid","pwd"」
+//    SendCMD();
+//    timeout=10;
+//    getreply();
+//    pc.printf(buf);
+//
+//    wait(5);
 
-    wait(2);
+
+    pc.printf("\n---------- APmode set ----------\r\n");
 
-    pc.printf("\n---------- Connecting to AP ----------\r\n");
+
+    
     pc.printf("ssid = %s   pwd = %s\r\n",ssid,pwd);
-    strcpy(snd, "AT+CWJAP=\"");
+    strcpy(snd, "AT+CWSAP_DEF=\"");
     strcat(snd, ssid);
-    strcat(snd, "\",\"");
+    strcat(snd, "\",\""); //  "," を入力
     strcat(snd, pwd);
-    strcat(snd, "\"\r\n");
+    strcat(snd, "\",");
+    strcat(snd, "5");   //<chl>: channel ID. 
+    strcat(snd, ",");
+    strcat(snd, "4");   //<ecn>: encryption method; WEP is notsupported.(0:OPEN, 2:WPA_PSK, 3:WPA2_PSK, 4:WPA_WPA2_PSK)
+    strcat(snd, "\r\n"); // "を入力し改行             //「AT+CWJAP="ssid","pwd",5,3」
     SendCMD();
     timeout=10;
     getreply();
@@ -138,6 +172,7 @@
 
     wait(5);
 
+//--------------------------------------------------------------------------------------------------------------------------------------
     pc.printf("\n---------- Get IP's ----------\r\n");
     strcpy(snd, "AT+CIFSR\r\n");
     SendCMD();