Why? What's wrong?
Here is my Code:
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
WiFiManager wm;
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("");
WiFi.mode(WIFI_STA); // Station Mode
Serial.print("try to connect to wifi ");
Serial.println("SSID: " + WiFi.SSID());
startWiFi(); // Connect
delay(2000);
wm.disconnect();
Serial.println("Wifi Disconnected");
Serial.println("");
delay(2000);
Serial.print("Try to RECONNECT to wifi ");
Serial.println("SSID: " + WiFi.SSID());
startWiFi(); // Connect
}
void loop() {
//
}
// -------------------------------------------------------------------------
// startWiFi
// -------------------------------------------------------------------------
//for reference:
//typedef enum {
// WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
// WL_IDLE_STATUS = 0,
// WL_NO_SSID_AVAIL = 1,
// WL_SCAN_COMPLETED = 2,
// WL_CONNECTED = 3,
// WL_CONNECT_FAILED = 4,
// WL_CONNECTION_LOST = 5,
// WL_DISCONNECTED = 6
//} wl_status_t;
void startWiFi() {
Serial.print("Is WiFi Configured and saved: ");
Serial.println((String)wm.getWiFiIsSaved() ? "YES" : "NO");
if (!WiFi.isConnected()) {
Serial.println("SSID: " + WiFi.SSID());
int conn_result = WiFi.waitForConnectResult(10000); // connect try it for 10 seconds
Serial.print("conn_result: ");
Serial.println(conn_result, DEC);
}
if (WiFi.isConnected()) {
Serial.println("Wifi is connected!");
}
else {
Serial.println("Wifi is NOT connected!");
}
Serial.println("");
}
And here the results:
try to connect to wifi SSID: InProg1
Is WiFi Configured and saved: YES
SSID: InProg1
conn_result: 3
Wifi is connected!
Wifi Disconnected
Try to RECONNECT to wifi SSID: InProg1
Is WiFi Configured and saved: YES
SSID: InProg1
conn_result: 0
Wifi is not connected!
The conn_result 0 comes promptly not after 10 seconds.