diff --git a/libesphttpd/util/cgiwifi.c b/libesphttpd/util/cgiwifi.c index 0cde23a..f948a6c 100644 --- a/libesphttpd/util/cgiwifi.c +++ b/libesphttpd/util/cgiwifi.c @@ -316,7 +316,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { //Template code for the WLAN page. httpd_cgi_state ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) { char buff[256]; - int x; + WIFI_MODE x; static struct station_config stconf; if (token==NULL) return HTTPD_CGI_DONE; wifi_station_get_config(&stconf); @@ -331,7 +331,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, // strcpy(buff, (char*)stconf.password); } else if (strcmp(token, "WiFiapwarn")==0) { x=wifi_get_opmode(); - if (x==2) { + if (x==SOFTAP_MODE) { strcpy(buff, "Can't scan in this mode. Click here to go to STA+AP mode."); } else { strcpy(buff, "Click here to go to stand-alone AP mode."); diff --git a/user/datalink.h b/user/datalink.h index fd34834..392a692 100644 --- a/user/datalink.h +++ b/user/datalink.h @@ -7,9 +7,11 @@ // request to capture data... #define DG_REQUEST_RAW 40 #define DG_REQUEST_FFT 41 + // reporting #define DG_REQUEST_STORE_REF 42 // request to capture & store reference FFT #define DG_REQUEST_COMPARE_REF 43 // request to capture FFT & compare with reference + // wifi status & control #define DG_SETMODE_AP 44 // request AP mode (AP button pressed) #define DG_WPS_START 45 // start WPS diff --git a/user/utils.c b/user/utils.c index 30f8472..8514179 100644 --- a/user/utils.c +++ b/user/utils.c @@ -29,7 +29,7 @@ const FLASH_FN char *auth2str(AUTH_MODE auth) } } -const FLASH_FN char *opmode2str(int opmode) +const FLASH_FN char *opmode2str(WIFI_MODE opmode) { switch (opmode) { case NULL_MODE: return "Disabled"; diff --git a/user/utils.h b/user/utils.h index 3ab70cd..5efc93e 100644 --- a/user/utils.h +++ b/user/utils.h @@ -5,6 +5,6 @@ int rssi2perc(int rssi); const char *auth2str(AUTH_MODE auth); -const char *opmode2str(int opmode); +const char *opmode2str(WIFI_MODE opmode); #endif // UTILS_H diff --git a/user/wificontrol.c b/user/wificontrol.c index 7eeb993..f0f80de 100644 --- a/user/wificontrol.c +++ b/user/wificontrol.c @@ -10,9 +10,9 @@ void FLASH_FN wificontrol_setmode_ap(void) { wifi_station_disconnect(); // disconnect - wifi_set_opmode(SOFTAP_MODE); // enter AP mode + wifi_set_opmode(STATIONAP_MODE); // enter AP mode - warn("SBMP request to switch to SoftAP mode. Restarting...\n"); + warn("Received Rq to enable AP.\n");// Restarting... system_restart(); // TODO check if restart is needed } @@ -42,10 +42,13 @@ static void FLASH_FN my_wps_cb(int status) info("WPS success!"); wifi_wps_disable(); wifi_station_connect(); + os_timer_disarm(&wps_abort_timer); break; default: error("WPS failed."); + wifi_wps_disable(); + os_timer_disarm(&wps_abort_timer); break; } @@ -54,23 +57,31 @@ static void FLASH_FN my_wps_cb(int status) void FLASH_FN wificontrol_start_wps(void) { + if (wps_in_progress) { + warn("Request to abort WPS."); + wifi_wps_disable(); + wps_in_progress = false; + return; + } + info("Starting WPS..."); // Make sure station is enabled - if (wifi_get_opmode() == SOFTAP_MODE) { - wifi_set_opmode(STATIONAP_MODE); - } - + wifi_set_opmode(STATION_MODE); // Disconnect if connected to any station wifi_station_disconnect(); + os_delay_us(1000000); + // enable WPS - wifi_set_wps_cb(my_wps_cb); + wifi_wps_disable(); wifi_wps_enable(WPS_TYPE_PBC); + wifi_set_wps_cb(my_wps_cb); + wifi_wps_start(); os_timer_disarm(&wps_abort_timer); os_timer_setfn(&wps_abort_timer, abort_wps_cb, NULL); - os_timer_arm(&wps_abort_timer, 15000, false); // 15 seconds + os_timer_arm(&wps_abort_timer, 60000, false); // 15 seconds wps_in_progress = true; }