ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By tve
#22218 I've also seen it get into weird states when it can't connect. One of my APs is borderline because it's too close, I believe, and it sometimes gets a bit wedged. I don't know whether it's good to try and work around it by adding more code or whether it's more a matter of waiting for the next SDK update... Espressif seems to have rejiggled Wifi stuff when going from 1.0 to 1.1 (probbaly to make the mesh SDK work) and it looks to me like things are not yet fully stabilized.
User avatar
By iothing
#22358 Here the complete workaround:

Code: Select allstatic 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?!
Last edited by iothing on Sun Jul 05, 2015 6:14 pm, edited 2 times in total.
User avatar
By kriegste
#22360 To my knowledge the actual bootloader is in the µC itself and it is read-only. So you can totally overwrite the complete flash chip with whatever you want without bricking it. You can flash blank512k.bin (only 0xFFs) to delete all settings, for example.

Flashing a bin file which is smaller than the flash chip will leave some areas untouched, of course.