Moderator: Sprite_tm
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
int x = wifi_station_get_connect_status();
int m = wifi_get_opmode() & 0x3;
os_printf("Wifi check: mode=%s status=%d\n", wifiMode[m], x);
if (x == STATION_GOT_IP) { //connected successfully and got ip
if (m != 1) { //not already in sta mode
#ifdef CHANGE_TO_STA
// We're happily connected, go to STA mode
os_printf("Wifi got IP. Going into STA mode..\n");
wifi_set_opmode(1); //stay in the mode we are in!
wifi_set_sleep_type(SLEEP_MODE);
#endif
}
//continue to check on the wifi state
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); //check again in RESET_TIMEOUT seconds
} else {
if (m == 3) { //if we are in AP+STA Mode
if (retry) {
os_printf("WiFI: no ip, retry...\n");
wifi_station_connect(); //attemp to reconnect
retry = false; //unset the retry flag
os_timer_arm(&resetTimer, 10000, 0); //check again in 10s
}
else {
os_printf("WiFI: no ip, wait...\n");
wifi_station_disconnect(); //disable auto-reconnect
retry = true; // set retry flag
os_timer_arm(&resetTimer, 120000, 0); //check again in 120s
}
}
if (m == 1) { //in STA mode and no ip
os_printf("STA->AP+STA\n");
wifi_set_opmode(3); //change to AP+STA mode so the user can correct the wifi settings
wifi_station_disconnect(); //disable auto-reconnect //disable auto-reconnect
retry = true; // set retry flag
os_timer_arm(&resetTimer, 120000, 0); //check again in 120s
}
//if in AP mode (default after flash) do nothing
}
}
Update: I thought that wifi_station_set_reconnect_policy(false); would work instead of wifi_station_disconnect(); - but it does not.
I noticed something very odd: on one of my four esp-01 modules this workaround has no effect - I flashed all of them via uart "make flash" - so the flash content should be identical, right? Is there a way to hard reset the module's flash even further? I have another module that flashes ok but then it's not possible to connect to it's (esp8266) AP - bricked bootloader?!
Flashing a bin file which is smaller than the flash chip will leave some areas untouched, of course.