Skip to content

WiFi.status() incorrect after reconnection #4792

Closed
@d-a-v

Description

@d-a-v

from @Rob58329 (link),

This commit "lwip2: fix static address management (#4677)" breaks the WiFi.status() command after a WiFi.disconnect() and WiFi.begin(ssid,pw).
(Specifically, the WiFi.status()==WL_CONNECTED never returns true after the 1st successful connection & disconnection.)
ie. git checkout 758b0bd WORKS
but git checkout 76a14b1 FAILS

My setup is Arduino-IDE using Github-ESP8266 code, with a D1-Mini-ESP8266
Test code is show below:

const char* ssid = "your_ssid";
const char* pw = "your_password"; // details for your router

#include <ESP8266WiFi.h>

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  delay(5);
  WiFi.disconnect();
  delay(5); // disconnect any existing [WIFI_STA] connection

  delay(3000);
  Serial.println();
  Serial.println("TEST SKETCH");
  if (Connect_wifi())
    Disconnect_wifi(); // this works fine

  Serial.println("Please wait until 2nd try...");
  delay(5000);
  if (Connect_wifi())
    Disconnect_wifi(); // this fails to report "connected"

  WiFi.disconnect();
  delay(5); // disconnect any still existing [WIFI_STA] connection
  Serial.println("Test END");
}

void Disconnect_wifi() {
  delay(2000);
  Serial.print("Disconnecting from router=");
  Serial.println(WiFi.disconnect());
}

boolean Connect_wifi() {
  Serial.print("Connecting to router ");
  WiFi.begin(ssid, pw);
  byte x = 0, y = 0, Wstatus_old = 99;
  boolean success;
  do {
    byte Wstatus = WiFi.status();
    if (Wstatus_old != Wstatus) {
      Wstatus_old = Wstatus;
      Serial.print(Wstatus);
    }
    y++;
    if (y == 250) {
      y = 0;
      x++;
      Serial.print(".");
    }
    success = (Wstatus == WL_CONNECTED);
    delay(4);
  } while ((x < 20) and !success ); // try for 20seconds
  if (success)
    Serial.println(" connected OK");
  else
    Serial.println(" FAILED (but the router actually says apparently connected OK!)");
  return success;
}

void loop() {}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions