From f1d80059d605c2d285a05a852261b104644675b5 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Thu, 4 Dec 2014 21:11:16 +0100 Subject: [PATCH] Added warning about scanning not working in AP mode, possibility to switch modes. --- Makefile | 2 +- html/wifi/wifi.tpl | 3 +++ user/cgiwifi.c | 31 ++++++++++++++++++++++++++++++- user/cgiwifi.h | 1 + user/user_main.c | 4 +++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 003f6c6..05e5b7d 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,7 @@ flash: $(FW_FILE_1) $(FW_FILE_2) $(Q) sleep $(ESPDELAY) $(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x40000 -cf firmware/0x40000.bin -v -webpages.espfs: html/ mkespfsimage/mkespfsimage +webpages.espfs: html/ html/wifi/ mkespfsimage/mkespfsimage cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. mkespfsimage/mkespfsimage: mkespfsimage/ diff --git a/html/wifi/wifi.tpl b/html/wifi/wifi.tpl index 631b7bc..cd43566 100644 --- a/html/wifi/wifi.tpl +++ b/html/wifi/wifi.tpl @@ -65,6 +65,9 @@ window.onload=function(e) {

Current WiFi mode: %WiFiMode%

+

+Note: %WiFiapwarn% +

To connect to a WiFi network, please select one of the detected networks...
diff --git a/user/cgiwifi.c b/user/cgiwifi.c index a74156d..91e5270 100644 --- a/user/cgiwifi.c +++ b/user/cgiwifi.c @@ -210,7 +210,8 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { //Schedule disconnect/connect os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, reassTimerCb, NULL); -#if 1 //Set to 0 if you want to disable the actual reconnecting bit +//Set to 0 if you want to disable the actual reconnecting bit +#if 1 os_timer_arm(&reassTimer, 1000, 0); httpdRedirect(connData, "connecting.html"); @@ -220,6 +221,27 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { return HTTPD_CGI_DONE; } +//This cgi uses the routines above to connect to a specific access point with the +//given ESSID using the given password. +int ICACHE_FLASH_ATTR cgiWifiSetMode(HttpdConnData *connData) { + int len; + char buff[1024]; + + if (connData->conn==NULL) { + //Connection aborted. Clean up. + return HTTPD_CGI_DONE; + } + + len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); + if (len!=0) { + os_printf("cgiWifiSetMode: %s\n", buff); + wifi_set_opmode(atoi(buff)); + system_restart(); + } + httpdRedirect(connData, "/wifi"); + return HTTPD_CGI_DONE; +} + //Template code for the WLAN page. void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) { char buff[1024]; @@ -238,6 +260,13 @@ void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) os_strcpy(buff, (char*)stconf.ssid); } else if (os_strcmp(token, "WiFiPasswd")==0) { os_strcpy(buff, (char*)stconf.password); + } else if (os_strcmp(token, "WiFiapwarn")==0) { + x=wifi_get_opmode(); + if (x==2) { + os_strcpy(buff, "Can't scan in this mode. Click here to go to STA+AP mode."); + } else { + os_strcpy(buff, "Click here to go to standalone AP mode."); + } } espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff)); } diff --git a/user/cgiwifi.h b/user/cgiwifi.h index 91c1992..18f4816 100644 --- a/user/cgiwifi.h +++ b/user/cgiwifi.h @@ -7,5 +7,6 @@ int cgiWiFiScan(HttpdConnData *connData); void tplWlan(HttpdConnData *connData, char *token, void **arg); int cgiWiFi(HttpdConnData *connData); int cgiWiFiConnect(HttpdConnData *connData); +int cgiWifiSetMode(HttpdConnData *connData); #endif \ No newline at end of file diff --git a/user/user_main.c b/user/user_main.c index b5b414b..95fd68e 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -32,7 +32,9 @@ HttpdBuiltInUrl builtInUrls[]={ {"/wifi/", cgiRedirect, "/wifi/wifi.tpl"}, {"/wifi/wifiscan.cgi", cgiWiFiScan, NULL}, {"/wifi/wifi.tpl", cgiEspFsTemplate, tplWlan}, - {"/wifi/connect.cgi", cgiWiFiConnect}, + {"/wifi/connect.cgi", cgiWiFiConnect, NULL}, + {"/wifi/setmode.cgi", cgiWifiSetMode, NULL}, + {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem {NULL, NULL, NULL}