working WPS and cmd to set AP

Former-commit-id: a2a02ab2dfb61e6f3552ccae7b7831b6647ead56
master
Ondřej Hruška 9 years ago
parent 78e0569f87
commit 485a383e6d
  1. 4
      libesphttpd/util/cgiwifi.c
  2. 2
      user/datalink.h
  3. 2
      user/utils.c
  4. 2
      user/utils.h
  5. 27
      user/wificontrol.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, "<b>Can't scan in this mode.</b> Click <a href=\"/wifi/setmode?mode=3\">here</a> to go to STA+AP mode.");
} else {
strcpy(buff, "Click <a href=\"/wifi/setmode?mode=2\">here</a> to go to stand-alone AP mode.");

@ -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

@ -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";

@ -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

@ -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;
}

Loading…
Cancel
Save