-->
Page 1 of 1

2.4.0 will not automatically reconnect

PostPosted: Sat Jan 13, 2018 1:45 pm
by pidloop
The following sketch would automatically reconnect using 2.3.0 but in 2.4.0 it never does. To test:

1. edit ssid and pw to your AP creds
2. turn on your Access Point radio, start sketch, it will soon report WL_CONNECTED
3. turn off the AP radio and it will soon report WL_DISCONNECTED
4. turn on AP radio. Version 2.3.0 will soon report WL_CONNECTED but 2.4.0 stays WL_DISCONNECTED forever
5. Note that in 2.4.0 even though the status stays WL_DISCONNECTED pinging the ESP IP does succeed, so it seems the ESP really does automatically reconnect but does not report this as status.

Thank you.


Code: Select all#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>

char ssid[] = "xxx";
char pw[] = "yyy";

void setup()
{
    Serial.begin(115200);

    WiFi.enableSTA(true);

    WiFi.setAutoConnect (true);
    WiFi.setAutoReconnect (true);

    WiFi.begin (ssid, pw);

    Serial.println("start");
}

void loop()
{
    prWiFiStatus(WiFi.status());

    if (WiFi.isConnected())
        Serial.println (WiFi.localIP());

    delay(2000);
}

void prWiFiStatus (int s)
{
    #define     VALCASE(x)      case x: Serial.println(#x); break;

    switch (s) {
    VALCASE(WL_NO_SHIELD);
    VALCASE(WL_IDLE_STATUS);
    VALCASE(WL_NO_SSID_AVAIL);
    VALCASE(WL_SCAN_COMPLETED);
    VALCASE(WL_CONNECTED);
    VALCASE(WL_CONNECT_FAILED);
    VALCASE(WL_CONNECTION_LOST);
    VALCASE(WL_DISCONNECTED);
    default: Serial.println(s); break;
    }
}

Re: 2.4.0 will not automatically reconnect

PostPosted: Sun Jan 14, 2018 6:23 am
by jankop
I've come across something like this before, and I'm resolving it with reset modul after loss of WiFi. Your information and test are useful. Thank you

Re: 2.4.0 will not automatically reconnect

PostPosted: Mon Jan 15, 2018 12:59 pm
by pidloop
Seems to be a problem with lwip. In the Arduino IDE look under Tools and you will find a new menu item, try choosing "v1.4 Prebuilt" and rebuild your sketch. This solved it for me. See more info at this thread https://github.com/esp8266/Arduino/issues/4166

Re: 2.4.0 will not automatically reconnect

PostPosted: Mon Jan 15, 2018 1:13 pm
by dragondaud
using 1.4 will leave you vulnerable to various WiFi bugs that were fixed in the newer version (like KRACK). Instead of going backwards, I use this workaround which has worked for me:

Code: Select allvoid loop() {
  while (WiFi.status() != WL_CONNECTED || WiFi.localIP() == IPAddress(0,0,0,0)) {
    WiFi.reconnect();
    delay(1000);
  }
  [...]
}