|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
/*
|
|
|
|
|
Cgi/template routines for the /wifi url. |
|
|
|
|
*/ |
|
|
|
|
Cgi/template routines for the /wifi url. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ---------------------------------------------------------------------------- |
|
|
|
@ -26,11 +26,20 @@ Cgi/template routines for the /wifi url. |
|
|
|
|
#define DBG(format, ...) do { } while(0) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
# define VERS_STR_STR(V) #V |
|
|
|
|
# define VERS_STR(V) VERS_STR_STR(V) |
|
|
|
|
|
|
|
|
|
bool mdns_started = false; |
|
|
|
|
|
|
|
|
|
// ===== wifi status change callbacks
|
|
|
|
|
static WifiStateChangeCb wifi_state_change_cb[4]; |
|
|
|
|
|
|
|
|
|
// Temp store for new ap info.
|
|
|
|
|
static struct station_config stconf; |
|
|
|
|
|
|
|
|
|
// Temp store for new ap config
|
|
|
|
|
static struct softap_config apconf; |
|
|
|
|
|
|
|
|
|
uint8_t wifiState = wifiIsDisconnected; |
|
|
|
|
// reasons for which a connection failed
|
|
|
|
|
uint8_t wifiReason = 0; |
|
|
|
@ -301,9 +310,15 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { |
|
|
|
|
log_uart(false); |
|
|
|
|
// no more resetTimer at this point, gotta use physical reset to recover if in trouble
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
if (m != 3) { |
|
|
|
|
DBG("Wifi connect failed. Going into STA+AP mode..\n"); |
|
|
|
|
// Set STA+AP mode
|
|
|
|
|
wifi_set_opmode(3); |
|
|
|
|
#ifdef AP_SSID |
|
|
|
|
// Call ap set after mode change to AP or STA+AP
|
|
|
|
|
wifi_softap_set_config(&apconf); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
log_uart(true); |
|
|
|
|
DBG("Enabling/continuing uart log\n"); |
|
|
|
@ -311,8 +326,6 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Temp store for new ap info.
|
|
|
|
|
static struct station_config stconf; |
|
|
|
|
// Reassociate timer to delay change of association so the original request can finish
|
|
|
|
|
static ETSTimer reassTimer; |
|
|
|
|
|
|
|
|
@ -494,6 +507,9 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { |
|
|
|
|
int m = atoi(buff); |
|
|
|
|
DBG("Wifi switching to mode %d\n", m); |
|
|
|
|
wifi_set_opmode(m&3); |
|
|
|
|
// Call softap set after changing to AP or STA+AP
|
|
|
|
|
wifi_softap_set_config(&apconf); |
|
|
|
|
|
|
|
|
|
if (m == 1) { |
|
|
|
|
// STA-only mode, reset into STA+AP after a timeout if we don't get an IP address
|
|
|
|
|
os_timer_disarm(&resetTimer); |
|
|
|
@ -617,10 +633,76 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) { |
|
|
|
|
// 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.
|
|
|
|
|
void ICACHE_FLASH_ATTR wifiInit() { |
|
|
|
|
// wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
|
|
|
|
|
|
|
|
|
|
// Check te wifi opmode
|
|
|
|
|
int x = wifi_get_opmode() & 0x3; |
|
|
|
|
x = x; |
|
|
|
|
DBG("Wifi init, mode=%s\n", wifiMode[x]); |
|
|
|
|
|
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
|
os_printf("Wifi init, mode=%s\n",wifiMode[x]); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// STATION parameters only on a full flash
|
|
|
|
|
#if defined(STA_SSID) && defined(STA_PASS) |
|
|
|
|
if( x == 2 ){ |
|
|
|
|
// Create struct for station config
|
|
|
|
|
struct station_config stconf; |
|
|
|
|
// Call it
|
|
|
|
|
wifi_station_get_config(&stconf); |
|
|
|
|
// Set parameters
|
|
|
|
|
if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) { |
|
|
|
|
os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32); |
|
|
|
|
os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64); |
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
|
os_printf("Wifi pre-config trying to connect to AP %s pw %s\n",(char*)stconf.ssid, (char*)stconf.password); |
|
|
|
|
#endif |
|
|
|
|
// wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
|
|
|
|
|
// Set wifi mode
|
|
|
|
|
wifi_set_opmode(3); // sta+ap, will switch to sta-only 15 secs after connecting
|
|
|
|
|
stconf.bssid_set = 0; |
|
|
|
|
wifi_station_set_config(&stconf); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// SOFT_AP parameters
|
|
|
|
|
#if defined(AP_SSID) && defined(AP_PASS) |
|
|
|
|
// Call it
|
|
|
|
|
wifi_softap_get_config(&apconf); |
|
|
|
|
// Clean memory and set the value of SSID
|
|
|
|
|
memset(apconf.ssid, 0, sizeof(apconf.ssid)); |
|
|
|
|
os_memcpy(apconf.ssid, VERS_STR(AP_SSID), strlen(VERS_STR(AP_SSID))); |
|
|
|
|
// Clean memory and set the value of PASS
|
|
|
|
|
memset(apconf.password, 0, sizeof(apconf.password)); |
|
|
|
|
os_memcpy(apconf.password, VERS_STR(AP_PASS), strlen(VERS_STR(AP_PASS))); |
|
|
|
|
// Specify the length of pass
|
|
|
|
|
apconf.ssid_len= os_strlen((char*)VERS_STR(AP_PASS)); |
|
|
|
|
#ifdef AP_AUTH_MODE |
|
|
|
|
// If set, use specified auth mode
|
|
|
|
|
apconf.authmode = AP_AUTH_MODE; |
|
|
|
|
#else |
|
|
|
|
// If not, use wpa wpa2 psk
|
|
|
|
|
apconf.authmode = AUTH_WPA_WPA2_PSK; |
|
|
|
|
#endif |
|
|
|
|
#ifdef AP_SSID_HIDDEN |
|
|
|
|
// If set, use specified ssid hidden parameter
|
|
|
|
|
apconf.ssid_hidden = AP_SSID_HIDDEN; |
|
|
|
|
#endif |
|
|
|
|
#ifdef AP_MAX_CONN |
|
|
|
|
// If set, use specified max conn number
|
|
|
|
|
apconf.max_connection = AP_MAX_CONN; |
|
|
|
|
#endif |
|
|
|
|
#ifdef AP_BEACON_INTERVAL |
|
|
|
|
// If set use specified beacon interval
|
|
|
|
|
apconf.beacon_interval = AP_BEACON_INTERVAL; |
|
|
|
|
#endif |
|
|
|
|
// Set to use the new conf
|
|
|
|
|
#ifdef CGIWIFI_DBG |
|
|
|
|
os_printf("Wifi AP parameters: %s pw %s\n",(char*)apconf.ssid, (char*)apconf.password); |
|
|
|
|
#endif |
|
|
|
|
// MUST BE called after enabling AP or STA+AP mode
|
|
|
|
|
wifi_softap_set_config(&apconf); |
|
|
|
|
#endif // AP_SSID && AP_PASS
|
|
|
|
|
|
|
|
|
|
configWifiIP(); |
|
|
|
|
|
|
|
|
|
// The default sleep mode should be modem_sleep, but we set it here explicitly for good
|
|
|
|
|