Skip to content

WiFi.status() wrongly reports WL_CONNECTED even when WiFi is lost and RSSI is always 0 dBm #762

Closed
@khoih-prog

Description

@khoih-prog

Bug Description

  1. The Terminal output shows that even after WiFi was powered down, WiFi.status() still reports WL_CONNECTED

uint8_t WiFiClass::status() {
if (_apMode && _wifiHWInitted) {
return WL_CONNECTED;
}
switch (cyw43_wifi_link_status(&cyw43_state, _apMode ? 1 : 0)) {
case CYW43_LINK_DOWN: return WL_IDLE_STATUS;
case CYW43_LINK_JOIN: return localIP().isSet() ? WL_CONNECTED : WL_DISCONNECTED;
case CYW43_LINK_FAIL: return WL_CONNECT_FAILED;
case CYW43_LINK_NONET: return WL_CONNECT_FAILED;
case CYW43_LINK_BADAUTH: return WL_CONNECT_FAILED;
}
return WL_NO_MODULE;
}

  1. The RSSI is always shows 0 dBm, even WiFi is connected

int32_t WiFiClass::RSSI() {
// TODO - driver does not return this?!
return 0;
}

This bug is very similar to [Portenta_H7] WiFi.status() wrongly reports WL_CONNECTED even when WiFi is lost #381


MRE

Using the following sketch

Arduino IDE v1.8.19,
arduino-pico core v2.4.0
RASPBERRY_PI_PICO_W using CYW43439 WiFi


#include <WiFi.h>

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = "YOUR_SSID";            // your network SSID (name)
char pass[] = "YOUR_PASSWORD";        // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

void printWifiStatus() 
{
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void setup()
{
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  while (!Serial && millis() < 5000);
  
  Serial.print(F("\nStarting RP2040W_WiFi_Bug on ")); Serial.println(BOARD_NAME);

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_SHIELD)
  {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED)
  {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 3 seconds for connection:
    delay(3000);
  }
}

void loop()
{
  if (WiFi.status() == WL_CONNECTED)
  {
    Serial.println("Connected to wifi");
    printWifiStatus();
  }
  else
  {
    Serial.println("Not connected to wifi");
  }
  
  delay(5000);
}

Terminal output


Starting RP2040W_WiFi_Bug on RASPBERRY_PI_PICO_W
Attempting to connect to SSID: HueNet1
Attempting to connect to SSID: HueNet1
Connected to wifi
SSID: HueNet1
IP Address: 192.168.2.180
signal strength (RSSI):0 dBm    <========  RSSI = 0 dBm when connected
Connected to wifi
SSID: HueNet1
IP Address: 192.168.2.180
signal strength (RSSI):0 dBm
...                         <============  Power down WiFi, WiFi.status() is still WL_CONNECTED
Connected to wifi
SSID: HueNet1
IP Address: 192.168.2.180
signal strength (RSSI):0 dBm
Connected to wifi
SSID: HueNet1
IP Address: 192.168.2.180
signal strength (RSSI):0 dBm
Connected to wifi
SSID: HueNet1
IP Address: 192.168.2.180
signal strength (RSSI):0 dBm
Connected to wifi
SSID: HueNet1
IP Address: 192.168.2.180
signal strength (RSSI):0 dBm

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions