Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.4.0 will not automatically reconnect #4161

Closed
ghost opened this issue Jan 13, 2018 · 6 comments
Closed

2.4.0 will not automatically reconnect #4161

ghost opened this issue Jan 13, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented Jan 13, 2018

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 after the AP restart pinging the ESP IP does succeed, so it seems the ESP really does automatically reconnect but does not report this as status.

Thank you.

`
#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;
}

}
`

@tonton81
Copy link

i noticed it doesnt reconnect as well, have to call wifi begin again or reboot ESP.. didnt have this issue before 2.4

@d-a-v
Copy link
Collaborator

d-a-v commented Jan 14, 2018

Would you agree this is duplicate of #4101 ?
If so, try latest git master version of core.

@ghost
Copy link
Author

ghost commented Jan 15, 2018 via email

@d-a-v
Copy link
Collaborator

d-a-v commented Jan 15, 2018

You can also try and use lwip v1.4 in Tools>Menu instead. Sorry I forgot to mention that as in #4166.
This will be fixed in the next release.

@ghost
Copy link
Author

ghost commented Jan 15, 2018

Solved. See 4166.

Many thanks.

@ghost
Copy link

ghost commented Apr 3, 2018

boolean WiFiReturns() {
if (WiFi.localIP() == IPAddress(0, 0, 0, 0)) return 0;
  switch (WiFi.status()) {
    case WL_NO_SHIELD: return 0;
    case WL_IDLE_STATUS: return 0;
    case WL_NO_SSID_AVAIL: return 0;
    case WL_SCAN_COMPLETED: return 1;
    case WL_CONNECTED: return 1;
    case WL_CONNECT_FAILED: return 0;
    case WL_CONNECTION_LOST: return 0;
    case WL_DISCONNECTED: return 0;
    default: return 0;
  }
}

https://www.arduino.cc/en/Reference/WiFiStatus
WL_CONNECTED: assigned when connected to a WiFi network;
WL_NO_SHIELD: assigned when no WiFi shield is present;
WL_IDLE_STATUS: it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED);
WL_NO_SSID_AVAIL: assigned when no SSID are available;
WL_SCAN_COMPLETED: assigned when the scan networks is completed;
WL_CONNECT_FAILED: assigned when the connection fails for all the attempts;
WL_CONNECTION_LOST: assigned when the connection is lost;
WL_DISCONNECTED: assigned when disconnected from a network;

void loop() {
  if (!WiFiReturns()) { 
    WiFi.reconnect(); //Connection OFF - conexión OFF
  } else { 
    //conexión ON - Connection ON
  }
}

Saludos

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants