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