Skip to content

2.4.0 incorrectly reports WL_CONNECTED immediately after WiFi.mode(WIFI_STA), without waiting for WiFi.begin() or a successful connection. #4166

@Rob58329

Description

@Rob58329

Hardware: D1-mini
Core Version: Arduino-IDE(v1.8.5) with ESP8266-board-software-version 2.4.0
[IwIP Variant: v2 Prebuilt (both MSS=536 and MSS=1460)]

Problem description

After successfully connecting using "WiFi.mode(WIFI_STA)". If you then disconnect using "WiFi.disconnect()" & "WiFi.mode(WIFI_OFF)", and finally try to reconnect again starting with "WiFi.mode(WIFI_STA)", then "WiFi.status()" reports "WL_CONNECTED" immediately after the "WiFi.mode(WIFI_STA)" (ie. long before it has connected). It then continues to say "WL_CONNECTED" up until you issue the "WiFi.begin(ssid, password)" command (at which point it starts to correctly say "WL_DISCONNECTED" again).

This means it is not possible to reliably use "while (WiFi.status()!=WL_CONNECTED)" to check for or initiate a "WiFi.begin" command or similar.

(Note that v2.3.0 and v2.4.0-rc2 seemed to correctly report "WL_DISCONNECTED" or "WL_IDLE_STATUS" right up until the connection was successfully re-established.)

(This seems to be different to the issue reported in #4161.)

Example Sketch

#include <ESP8266WiFi.h>
const char* ssid = "your_ssid";
const char* password = "your_password";

void setup() {
Serial.begin(74880); delay(3000);
Serial.print("About to start:"); display_status();

WiFi.mode(WIFI_STA);
Serial.print("WiFi.mode(WIFI_STA):"); display_status(); // correct here gives: "WiFi.status()=WL_DISCONNECTED"
WiFi.begin(ssid, password);
Serial.print("WiFi.begin:"); display_status();
wait_connection();
Serial.print("WiFi connected: "); display_status();
Serial.println("--------------------");delay(5000);

WiFi.disconnect(); delay(5);
Serial.print("WiFi.disconnect: "); display_status();
WiFi.mode(WIFI_OFF); delay(5);
Serial.print("WiFi.mode(WIFI_OFF): "); display_status();
WiFi.forceSleepBegin(); delay(1);
Serial.print("WiFi.forceSleepBegin: "); display_status();
Serial.println("--------------------");delay(5000);

WiFi.forceSleepWake(); delay(1);
Serial.print("WiFi.forceSleepWake: "); display_status();
WiFi.mode(WIFI_STA); delay(5);
Serial.print("WiFi.mode(WIFI_STA):"); display_status(); // error here gives: "WiFi.status()=WL_CONNECTED"
Serial.println("NB. I beleive the above should NOT return 'WL_CONNECTED'");
Serial.println("(when used with D1-Mini and Arduino-IDE-with-ESP8266-board-sw-v2.4.0)");
Serial.println("--------------------");delay(5000);

Serial.print("After Delay:"); display_status();
WiFi.begin(ssid, password);
Serial.print("WiFi.begin:"); display_status();
wait_connection();
Serial.print("WiFi connected: "); display_status();
Serial.println("--------END---------");
}

void loop() {}

void wait_connection() {while (WiFi.status()!=WL_CONNECTED) {Serial.print(".");delay(500);}}

void display_status() {
byte x=WiFi.status(); Serial.print(" WiFi.status()=");
if (x==WL_CONNECTED) Serial.println("WL_CONNECTED");
else if (x==WL_DISCONNECTED) Serial.println("WL_DISCONNECTED");
else if (x==WL_CONNECT_FAILED) Serial.println("WL_CONNECT_FAILED");
else if (x==WL_NO_SSID_AVAIL) Serial.println("WL_NO_SSID_AVAIL");
else if (x==WL_IDLE_STATUS) Serial.println("WL_IDLE_STATUS");
else Serial.println(x);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions