Skip to content

[Portenta_H7] WiFi.status() wrongly reports WL_CONNECTED even when WiFi is lost #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
khoih-prog opened this issue Jan 8, 2022 · 1 comment · Fixed by #538
Closed

Comments

@khoih-prog
Copy link

MRE

Using the following sketch

  • Arduino IDE v1.8.19,
  • mbed_portenta core v2.6.1
  • Portenta_H7_M7 with Murata WiFi
#ifdef CORE_CM7    // Start M7 Core programming  

#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);

  delay(500);

  // 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)
  //if ( (WiFi.status() == WL_CONNECTED) && (WiFi.RSSI() != 0) )      // temporary workaround
  {
    Serial.println("Connected to wifi");
    printWifiStatus();
  }
  else
  {
    Serial.println("Not connected to wifi");
  }
  
  delay(5000);
}

#endif

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

Attempting to connect to SSID: YOUR_SSID
Connected to wifi
SSID: YOUR_SSID
IP Address: 192.168.2.104
signal strength (RSSI):-26 dBm
Connected to wifi
SSID: YOUR_SSID
IP Address: 192.168.2.104
signal strength (RSSI):-38 dBm
Connected to wifi
SSID: YOUR_SSID
...
Connected to wifi
SSID: YOUR_SSID
IP Address: 192.168.2.104
signal strength (RSSI):0 dBm  <======= WiFi Powered down, RSSI = 0, but still reporting WL_CONNECTED
Connected to wifi
SSID: YOUR_SSID
IP Address: 192.168.2.104
signal strength (RSSI):0 dBm
Connected to wifi
SSID: YOUR_SSID
IP Address: 192.168.2.104
signal strength (RSSI):0 dBm

Discussion

WiFi.status() returns _currentNetworkStatus, which is updated only in begin() or beginAP(), but there is no function to update _currentNetworkStatus if the connected WiFi is lost.

uint8_t arduino::WiFiClass::status() {
  return _currentNetworkStatus;
}

Temporary Workaround (not 100% working now)

Using with WiFi.RSSI() to detect if WiFi is powered down or signal lost

if ( (WiFi.status() == WL_CONNECTED) && (WiFi.RSSI() != 0) )
@khoih-prog
Copy link
Author

Tested OK with new core v3.3.0.

Thanks and Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant