|
|
@ -21,8 +21,11 @@ Cgi/template routines for the /wifi url. |
|
|
|
#include "config.h" |
|
|
|
#include "config.h" |
|
|
|
#include "log.h" |
|
|
|
#include "log.h" |
|
|
|
|
|
|
|
|
|
|
|
//#define SLEEP_MODE LIGHT_SLEEP_T
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
#define SLEEP_MODE MODEM_SLEEP_T |
|
|
|
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__) |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#define DBG(format, ...) do { } while(0) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// ===== wifi status change callbacks
|
|
|
|
// ===== wifi status change callbacks
|
|
|
|
static WifiStateChangeCb wifi_state_change_cb[4]; |
|
|
|
static WifiStateChangeCb wifi_state_change_cb[4]; |
|
|
@ -55,48 +58,36 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) { |
|
|
|
case EVENT_STAMODE_CONNECTED: |
|
|
|
case EVENT_STAMODE_CONNECTED: |
|
|
|
wifiState = wifiIsConnected; |
|
|
|
wifiState = wifiIsConnected; |
|
|
|
wifiReason = 0; |
|
|
|
wifiReason = 0; |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi connected to ssid %s, ch %d\n", evt->event_info.connected.ssid, |
|
|
|
os_printf("Wifi connected to ssid %s, ch %d\n", evt->event_info.connected.ssid, |
|
|
|
|
|
|
|
evt->event_info.connected.channel); |
|
|
|
evt->event_info.connected.channel); |
|
|
|
#endif |
|
|
|
|
|
|
|
statusWifiUpdate(wifiState); |
|
|
|
statusWifiUpdate(wifiState); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case EVENT_STAMODE_DISCONNECTED: |
|
|
|
case EVENT_STAMODE_DISCONNECTED: |
|
|
|
wifiState = wifiIsDisconnected; |
|
|
|
wifiState = wifiIsDisconnected; |
|
|
|
wifiReason = evt->event_info.disconnected.reason; |
|
|
|
wifiReason = evt->event_info.disconnected.reason; |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi disconnected from ssid %s, reason %s (%d)\n", |
|
|
|
os_printf("Wifi disconnected from ssid %s, reason %s (%d)\n", |
|
|
|
|
|
|
|
evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason); |
|
|
|
evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason); |
|
|
|
#endif |
|
|
|
|
|
|
|
statusWifiUpdate(wifiState); |
|
|
|
statusWifiUpdate(wifiState); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case EVENT_STAMODE_AUTHMODE_CHANGE: |
|
|
|
case EVENT_STAMODE_AUTHMODE_CHANGE: |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi auth mode: %d -> %d\n", |
|
|
|
os_printf("Wifi auth mode: %d -> %d\n", |
|
|
|
|
|
|
|
evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode); |
|
|
|
evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode); |
|
|
|
#endif |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case EVENT_STAMODE_GOT_IP: |
|
|
|
case EVENT_STAMODE_GOT_IP: |
|
|
|
wifiState = wifiGotIP; |
|
|
|
wifiState = wifiGotIP; |
|
|
|
wifiReason = 0; |
|
|
|
wifiReason = 0; |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi got ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n", |
|
|
|
os_printf("Wifi got ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n", |
|
|
|
|
|
|
|
IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask), |
|
|
|
IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask), |
|
|
|
IP2STR(&evt->event_info.got_ip.gw)); |
|
|
|
IP2STR(&evt->event_info.got_ip.gw)); |
|
|
|
#endif |
|
|
|
|
|
|
|
statusWifiUpdate(wifiState); |
|
|
|
statusWifiUpdate(wifiState); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case EVENT_SOFTAPMODE_STACONNECTED: |
|
|
|
case EVENT_SOFTAPMODE_STACONNECTED: |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi AP: station " MACSTR " joined, AID = %d\n", |
|
|
|
os_printf("Wifi AP: station " MACSTR " joined, AID = %d\n", |
|
|
|
|
|
|
|
MAC2STR(evt->event_info.sta_connected.mac), evt->event_info.sta_connected.aid); |
|
|
|
MAC2STR(evt->event_info.sta_connected.mac), evt->event_info.sta_connected.aid); |
|
|
|
#endif |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case EVENT_SOFTAPMODE_STADISCONNECTED: |
|
|
|
case EVENT_SOFTAPMODE_STADISCONNECTED: |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi AP: station " MACSTR " left, AID = %d\n", |
|
|
|
os_printf("Wifi AP: station " MACSTR " left, AID = %d\n", |
|
|
|
|
|
|
|
MAC2STR(evt->event_info.sta_disconnected.mac), evt->event_info.sta_disconnected.aid); |
|
|
|
MAC2STR(evt->event_info.sta_disconnected.mac), evt->event_info.sta_disconnected.aid); |
|
|
|
#endif |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -116,9 +107,7 @@ wifiAddStateChangeCb(WifiStateChangeCb cb) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("WIFI: max state change cb count exceeded\n"); |
|
|
|
os_printf("WIFI: max state change cb count exceeded\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ===== wifi scanning
|
|
|
|
// ===== wifi scanning
|
|
|
@ -147,9 +136,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { |
|
|
|
struct bss_info *bss_link = (struct bss_info *)arg; |
|
|
|
struct bss_info *bss_link = (struct bss_info *)arg; |
|
|
|
|
|
|
|
|
|
|
|
if (status!=OK) { |
|
|
|
if (status!=OK) { |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("wifiScanDoneCb status=%d\n", status); |
|
|
|
os_printf("wifiScanDoneCb status=%d\n", status); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
cgiWifiAps.scanInProgress=0; |
|
|
|
cgiWifiAps.scanInProgress=0; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -169,9 +156,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { |
|
|
|
//Allocate memory for access point data
|
|
|
|
//Allocate memory for access point data
|
|
|
|
cgiWifiAps.apData=(ApData **)os_malloc(sizeof(ApData *)*n); |
|
|
|
cgiWifiAps.apData=(ApData **)os_malloc(sizeof(ApData *)*n); |
|
|
|
cgiWifiAps.noAps=n; |
|
|
|
cgiWifiAps.noAps=n; |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Scan done: found %d APs\n", n); |
|
|
|
os_printf("Scan done: found %d APs\n", n); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Copy access point data to the static struct
|
|
|
|
//Copy access point data to the static struct
|
|
|
|
n=0; |
|
|
|
n=0; |
|
|
@ -180,9 +165,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { |
|
|
|
if (n>=cgiWifiAps.noAps) { |
|
|
|
if (n>=cgiWifiAps.noAps) { |
|
|
|
//This means the bss_link changed under our nose. Shouldn't happen!
|
|
|
|
//This means the bss_link changed under our nose. Shouldn't happen!
|
|
|
|
//Break because otherwise we will write in unallocated memory.
|
|
|
|
//Break because otherwise we will write in unallocated memory.
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Huh? I have more than the allocated %d aps!\n", cgiWifiAps.noAps); |
|
|
|
os_printf("Huh? I have more than the allocated %d aps!\n", cgiWifiAps.noAps); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
//Save the ap data.
|
|
|
|
//Save the ap data.
|
|
|
@ -190,9 +173,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { |
|
|
|
cgiWifiAps.apData[n]->rssi=bss_link->rssi; |
|
|
|
cgiWifiAps.apData[n]->rssi=bss_link->rssi; |
|
|
|
cgiWifiAps.apData[n]->enc=bss_link->authmode; |
|
|
|
cgiWifiAps.apData[n]->enc=bss_link->authmode; |
|
|
|
strncpy(cgiWifiAps.apData[n]->ssid, (char*)bss_link->ssid, 32); |
|
|
|
strncpy(cgiWifiAps.apData[n]->ssid, (char*)bss_link->ssid, 32); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("bss%d: %s (%d)\n", n+1, (char*)bss_link->ssid, bss_link->rssi); |
|
|
|
os_printf("bss%d: %s (%d)\n", n+1, (char*)bss_link->ssid, bss_link->rssi); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bss_link = bss_link->next.stqe_next; |
|
|
|
bss_link = bss_link->next.stqe_next; |
|
|
|
n++; |
|
|
|
n++; |
|
|
@ -203,9 +184,7 @@ void ICACHE_FLASH_ATTR wifiScanDoneCb(void *arg, STATUS status) { |
|
|
|
|
|
|
|
|
|
|
|
static ETSTimer scanTimer; |
|
|
|
static ETSTimer scanTimer; |
|
|
|
static void ICACHE_FLASH_ATTR scanStartCb(void *arg) { |
|
|
|
static void ICACHE_FLASH_ATTR scanStartCb(void *arg) { |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Starting a scan\n"); |
|
|
|
os_printf("Starting a scan\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
wifi_station_scan(NULL, wifiScanDoneCb); |
|
|
|
wifi_station_scan(NULL, wifiScanDoneCb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -216,7 +195,7 @@ static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) { |
|
|
|
cgiWifiAps.scanInProgress = 1; |
|
|
|
cgiWifiAps.scanInProgress = 1; |
|
|
|
os_timer_disarm(&scanTimer); |
|
|
|
os_timer_disarm(&scanTimer); |
|
|
|
os_timer_setfn(&scanTimer, scanStartCb, NULL); |
|
|
|
os_timer_setfn(&scanTimer, scanStartCb, NULL); |
|
|
|
os_timer_arm(&scanTimer, 1000, 0); |
|
|
|
os_timer_arm(&scanTimer, 200, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
} |
|
|
@ -290,35 +269,26 @@ static ETSTimer resetTimer; |
|
|
|
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { |
|
|
|
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { |
|
|
|
int x = wifi_station_get_connect_status(); |
|
|
|
int x = wifi_station_get_connect_status(); |
|
|
|
int m = wifi_get_opmode() & 0x3; |
|
|
|
int m = wifi_get_opmode() & 0x3; |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x); |
|
|
|
os_printf("Wifi check: mode=%s status=%d\n", wifiMode[m], x); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (x == STATION_GOT_IP) { |
|
|
|
if (x == STATION_GOT_IP) { |
|
|
|
if (m != 1) { |
|
|
|
if (m != 1) { |
|
|
|
#ifdef CHANGE_TO_STA |
|
|
|
#ifdef CHANGE_TO_STA |
|
|
|
// We're happily connected, go to STA mode
|
|
|
|
// We're happily connected, go to STA mode
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi got IP. Going into STA mode..\n"); |
|
|
|
os_printf("Wifi got IP. Going into STA mode..\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
wifi_set_opmode(1); |
|
|
|
wifi_set_opmode(1); |
|
|
|
wifi_set_sleep_type(SLEEP_MODE); |
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
|
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
log_uart(false); |
|
|
|
log_uart(false); |
|
|
|
// no more resetTimer at this point, gotta use physical reset to recover if in trouble
|
|
|
|
// no more resetTimer at this point, gotta use physical reset to recover if in trouble
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (m != 3) { |
|
|
|
if (m != 3) { |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi connect failed. Going into STA+AP mode..\n"); |
|
|
|
os_printf("Wifi connect failed. Going into STA+AP mode..\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
wifi_set_opmode(3); |
|
|
|
wifi_set_opmode(3); |
|
|
|
} |
|
|
|
} |
|
|
|
log_uart(true); |
|
|
|
log_uart(true); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Enabling/continuing uart log\n"); |
|
|
|
os_printf("Enabling/continuing uart log\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); |
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -330,17 +300,17 @@ static ETSTimer reassTimer; |
|
|
|
|
|
|
|
|
|
|
|
// Callback actually doing reassociation
|
|
|
|
// Callback actually doing reassociation
|
|
|
|
static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) { |
|
|
|
static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) { |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi changing association\n"); |
|
|
|
os_printf("Wifi changing association\n"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
wifi_station_disconnect(); |
|
|
|
wifi_station_disconnect(); |
|
|
|
stconf.bssid_set = 0; |
|
|
|
stconf.bssid_set = 0; |
|
|
|
wifi_station_set_config(&stconf); |
|
|
|
wifi_station_set_config(&stconf); |
|
|
|
wifi_station_connect(); |
|
|
|
wifi_station_connect(); |
|
|
|
// Schedule check
|
|
|
|
// Schedule check, we give some extra time (4x) 'cause the reassociation can cause the AP
|
|
|
|
|
|
|
|
// to have to change channel, and then the client needs to follow before it can see the
|
|
|
|
|
|
|
|
// IP address
|
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|
os_timer_setfn(&resetTimer, resetTimerCb, NULL); |
|
|
|
os_timer_setfn(&resetTimer, resetTimerCb, NULL); |
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); |
|
|
|
os_timer_arm(&resetTimer, 4*RESET_TIMEOUT, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This cgi uses the routines above to connect to a specific access point with the
|
|
|
|
// This cgi uses the routines above to connect to a specific access point with the
|
|
|
@ -358,14 +328,12 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { |
|
|
|
//Set to 0 if you want to disable the actual reconnecting bit
|
|
|
|
//Set to 0 if you want to disable the actual reconnecting bit
|
|
|
|
os_strncpy((char*)stconf.ssid, essid, 32); |
|
|
|
os_strncpy((char*)stconf.ssid, essid, 32); |
|
|
|
os_strncpy((char*)stconf.password, passwd, 64); |
|
|
|
os_strncpy((char*)stconf.password, passwd, 64); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi try to connect to AP %s pw %s\n", essid, passwd); |
|
|
|
os_printf("Wifi try to connect to AP %s pw %s\n", essid, passwd); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Schedule disconnect/connect
|
|
|
|
//Schedule disconnect/connect
|
|
|
|
os_timer_disarm(&reassTimer); |
|
|
|
os_timer_disarm(&reassTimer); |
|
|
|
os_timer_setfn(&reassTimer, reassTimerCb, NULL); |
|
|
|
os_timer_setfn(&reassTimer, reassTimerCb, NULL); |
|
|
|
os_timer_arm(&reassTimer, 1000, 0); |
|
|
|
os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it
|
|
|
|
jsonHeader(connData, 200); |
|
|
|
jsonHeader(connData, 200); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
jsonHeader(connData, 400); |
|
|
|
jsonHeader(connData, 400); |
|
|
@ -421,9 +389,7 @@ static void ICACHE_FLASH_ATTR configWifiIP() { |
|
|
|
if (wifi_station_dhcpc_status() == DHCP_STARTED) |
|
|
|
if (wifi_station_dhcpc_status() == DHCP_STARTED) |
|
|
|
wifi_station_dhcpc_stop(); |
|
|
|
wifi_station_dhcpc_stop(); |
|
|
|
wifi_station_dhcpc_start(); |
|
|
|
wifi_station_dhcpc_start(); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi uses DHCP, hostname=%s\n", flashConfig.hostname); |
|
|
|
os_printf("Wifi uses DHCP, hostname=%s\n", flashConfig.hostname); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// no DHCP, we got static network config!
|
|
|
|
// no DHCP, we got static network config!
|
|
|
|
wifi_station_dhcpc_stop(); |
|
|
|
wifi_station_dhcpc_stop(); |
|
|
@ -432,9 +398,7 @@ static void ICACHE_FLASH_ATTR configWifiIP() { |
|
|
|
ipi.netmask.addr = flashConfig.netmask; |
|
|
|
ipi.netmask.addr = flashConfig.netmask; |
|
|
|
ipi.gw.addr = flashConfig.gateway; |
|
|
|
ipi.gw.addr = flashConfig.gateway; |
|
|
|
wifi_set_ip_info(0, &ipi); |
|
|
|
wifi_set_ip_info(0, &ipi); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi uses static IP %d.%d.%d.%d\n", IP2STR(&ipi.ip.addr)); |
|
|
|
os_printf("Wifi uses static IP %d.%d.%d.%d\n", IP2STR(&ipi.ip.addr)); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef DEBUGIP |
|
|
|
#ifdef DEBUGIP |
|
|
|
debugIP(); |
|
|
|
debugIP(); |
|
|
@ -497,7 +461,7 @@ int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) { |
|
|
|
// schedule change-over
|
|
|
|
// schedule change-over
|
|
|
|
os_timer_disarm(&reassTimer); |
|
|
|
os_timer_disarm(&reassTimer); |
|
|
|
os_timer_setfn(&reassTimer, configWifiIP, NULL); |
|
|
|
os_timer_setfn(&reassTimer, configWifiIP, NULL); |
|
|
|
os_timer_arm(&reassTimer, 1000, 0); |
|
|
|
os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it
|
|
|
|
// return redirect info
|
|
|
|
// return redirect info
|
|
|
|
jsonHeader(connData, 200); |
|
|
|
jsonHeader(connData, 200); |
|
|
|
httpdSend(connData, url, -1); |
|
|
|
httpdSend(connData, url, -1); |
|
|
@ -514,13 +478,10 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { |
|
|
|
len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); |
|
|
|
len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); |
|
|
|
if (len!=0) { |
|
|
|
if (len!=0) { |
|
|
|
int m = atoi(buff); |
|
|
|
int m = atoi(buff); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
DBG("Wifi switching to mode %d\n", m); |
|
|
|
os_printf("Wifi switching to mode %d\n", m); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
wifi_set_opmode(m&3); |
|
|
|
wifi_set_opmode(m&3); |
|
|
|
if (m == 1) { |
|
|
|
if (m == 1) { |
|
|
|
wifi_set_sleep_type(SLEEP_MODE); |
|
|
|
// STA-only mode, reset into STA+AP after a timeout if we don't get an IP address
|
|
|
|
// STA-only mode, reset into STA+AP after a timeout
|
|
|
|
|
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|
os_timer_setfn(&resetTimer, resetTimerCb, NULL); |
|
|
|
os_timer_setfn(&resetTimer, resetTimerCb, NULL); |
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); |
|
|
|
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); |
|
|
@ -619,9 +580,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
len += os_sprintf(buff+len, "\"x\":0}\n"); |
|
|
|
len += os_sprintf(buff+len, "\"x\":0}\n"); |
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
//DBG(" -> %s\n", buff);
|
|
|
|
//os_printf(" -> %s\n", buff);
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
httpdSend(connData, buff, len); |
|
|
|
httpdSend(connData, buff, len); |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
} |
|
|
|
} |
|
|
@ -644,13 +603,16 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) { |
|
|
|
// Init the wireless, which consists of setting a timer if we expect to connect to an AP
|
|
|
|
// Init the wireless, which consists of setting a timer if we expect to connect to an AP
|
|
|
|
// so we can revert to STA+AP mode if we can't connect.
|
|
|
|
// so we can revert to STA+AP mode if we can't connect.
|
|
|
|
void ICACHE_FLASH_ATTR wifiInit() { |
|
|
|
void ICACHE_FLASH_ATTR wifiInit() { |
|
|
|
wifi_set_phy_mode(2); |
|
|
|
// wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
|
|
|
|
int x = wifi_get_opmode() & 0x3; |
|
|
|
int x = wifi_get_opmode() & 0x3; |
|
|
|
os_printf("Wifi init, mode=%s\n", wifiMode[x]); |
|
|
|
DBG("Wifi init, mode=%s\n", wifiMode[x]); |
|
|
|
#endif |
|
|
|
|
|
|
|
configWifiIP(); |
|
|
|
configWifiIP(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The default sleep mode should be modem_sleep, but we set it here explicitly for good
|
|
|
|
|
|
|
|
// measure. We can't use light_sleep because that powers off everthing and we would loose
|
|
|
|
|
|
|
|
// all connections.
|
|
|
|
|
|
|
|
wifi_set_sleep_type(MODEM_SLEEP_T); |
|
|
|
|
|
|
|
|
|
|
|
wifi_set_event_handler_cb(wifiHandleEventCb); |
|
|
|
wifi_set_event_handler_cb(wifiHandleEventCb); |
|
|
|
// check on the wifi in a few seconds to see whether we need to switch mode
|
|
|
|
// check on the wifi in a few seconds to see whether we need to switch mode
|
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|