fix #101: doesn't stay in AP-only after reset

pull/140/merge
Thorsten von Eicken 9 years ago
parent bd40769138
commit 8b4749fb90
  1. 19
      esp-link/cgiwifi.c

@ -305,9 +305,11 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
int m = wifi_get_opmode() & 0x3; int m = wifi_get_opmode() & 0x3;
DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x); DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);
if(m!=2){ if (m == 2) return; // 2=AP, in AP-only mode we don't do any auto-switching
if ( x == STATION_GOT_IP ) { if ( x == STATION_GOT_IP ) {
if (m != 1) { // if we got an IP we could switch to STA-only...
if (m != 1) { // 1=STA
#ifdef CHANGE_TO_STA #ifdef CHANGE_TO_STA
// We're happily connected, go to STA mode // We're happily connected, go to STA mode
DBG("Wifi got IP. Going into STA mode..\n"); DBG("Wifi got IP. Going into STA mode..\n");
@ -318,6 +320,7 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
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 {
// we don't have an IP address
if (m != 3) { if (m != 3) {
DBG("Wifi connect failed. Going into STA+AP mode..\n"); DBG("Wifi connect failed. Going into STA+AP mode..\n");
wifi_set_opmode(3); wifi_set_opmode(3);
@ -327,7 +330,6 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
DBG("Enabling/continuing uart log\n"); DBG("Enabling/continuing uart log\n");
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
} }
}
} }
// Reassociate timer to delay change of association so the original request can finish // Reassociate timer to delay change of association so the original request can finish
@ -829,11 +831,12 @@ int ICACHE_FLASH_ATTR checkString(char *str){
*/ */
void ICACHE_FLASH_ATTR wifiInit() { void ICACHE_FLASH_ATTR wifiInit() {
// Check te wifi opmode // Check the wifi opmode
int x = wifi_get_opmode() & 0x3; int x = wifi_get_opmode() & 0x3;
// Set opmode to 3 to let system scan aps, otherwise it won't scan // If STA is enabled switch to STA+AP to allow for recovery, it will then switch to STA-only
wifi_set_opmode(3); // once it gets an IP address
if (x == 1) wifi_set_opmode(3);
// Call both STATION and SOFTAP default config // Call both STATION and SOFTAP default config
wifi_station_get_config_default(&stconf); wifi_station_get_config_default(&stconf);
@ -841,7 +844,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
DBG("Wifi init, mode=%s\n",wifiMode[x]); DBG("Wifi init, mode=%s\n",wifiMode[x]);
// STATION parameters // Change STATION parameters, if defined in the Makefile
#if defined(STA_SSID) && defined(STA_PASS) #if defined(STA_SSID) && defined(STA_PASS)
// Set parameters // Set parameters
if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) { if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) {
@ -856,7 +859,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
} }
#endif #endif
// Change SOFT_AP settings if defined in Makefile // Change SOFT_AP settings, if defined in Makefile
#if defined(AP_SSID) #if defined(AP_SSID)
// Check if ssid and pass are alphanumeric values // Check if ssid and pass are alphanumeric values
int ssidlen = os_strlen(VERS_STR(AP_SSID)); int ssidlen = os_strlen(VERS_STR(AP_SSID));

Loading…
Cancel
Save