You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering an issue with the following minimal reproduction code. After disconnecting from WiFi, setting WiFi.mode(WIFI_OFF), and using digitalWrite(23, LOW) (GP23: Wi-Fi module power) to turn off the WiFi chip power, the subsequent reconnect attempt fails. The issue specifically arises when trying to reinitialize the WiFiClient and reconnect to the WiFi network.
Steps to Reproduce
Connect to WiFi successfully.
Disconnect WiFi using WiFi.disconnect() and turn off the WiFi chip power using digitalWrite(23, LOW).
Attempt to reconnect by re-enabling power with digitalWrite(23, HIGH) and calling WiFi.begin(ssid, password) again.
Try to reinitialize and use a WiFiClient to connect to a server.
Expected Behavior
The WiFi chip should reconnect to the network, and WiFiClient should be able to establish a connection to the server.
Actual Behavior
The reconnection process fails, and WiFiClient cannot establish a new connection.
Reproduction Code
#include<Arduino.h>
#include<WiFi.h>// WiFi Settingsconstchar* ssid = "SSID";
constchar* password = "PASSWORD";
WiFiClient client;
voidconnectToWiFi();
voidreconnectWiFiAndClient();
voiddisconnectWiFi();
voidsetup() {
Serial.begin(115200);
// Initial WiFi connectionconnectToWiFi();
// Test communication with WiFiClientif (client.connect("example.com", 80)) {
Serial.println("Connected to server!");
client.println("GET / HTTP/1.1");
client.println("Host: example.com");
client.println("Connection: close");
client.println();
delay(1000);
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println(line);
}
client.stop();
} else {
Serial.println("Connection to server failed.");
}
// WiFi disconnection processdisconnectWiFi();
// Reconnection processreconnectWiFiAndClient();
}
voidloop() {
// No specific tasks in the main loop
}
// Function to connect to WiFivoidconnectToWiFi() {
Serial.print("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
// Function to disconnect WiFi and turn off WiFi chip powervoiddisconnectWiFi() {
Serial.println("Disconnecting WiFi...");
client.stop(); // Stop WiFiClient connection
WiFi.disconnect(); // Disconnect WiFidelay(100); // Wait a bit
WiFi.mode(WIFI_OFF); // Turn off WiFi modedelay(100); // Wait a bitdigitalWrite(23, LOW); // Turn off WiFi chip power
Serial.println("WiFi disconnected and power to WiFi chip is off.");
}
// Function to reconnect WiFi and WiFiClientvoidreconnectWiFiAndClient() {
digitalWrite(23, HIGH); // Turn on WiFi chip powerdelay(100); // Wait for stabilization
Serial.println("Reconnecting WiFi...");
WiFi.mode(WIFI_STA); // Set WiFi mode to STAconnectToWiFi(); // Reconnect to WiFi// Reuse WiFiClient after reconnectionif (client.connect("example.com", 80)) {
Serial.println("Reconnected to server!");
client.println("GET / HTTP/1.1");
client.println("Host: example.com");
client.println("Connection: close");
client.println();
delay(1000);
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println(line);
}
client.stop();
} else {
Serial.println("Reconnection to server failed.");
}
}
Additional Information
Board: Raspberry Pi Pico W
PlatformIO Framework: Arduino
Library: None
When the code related to WiFiClient is removed, the reconnection process works as expected.
It would be great to know if this is a bug or if there is a missing step in the process for properly reinitializing the WiFi chip and WiFiClient.
Thank you!
The text was updated successfully, but these errors were encountered:
Description
I'm encountering an issue with the following minimal reproduction code. After disconnecting from WiFi, setting
WiFi.mode(WIFI_OFF)
, and usingdigitalWrite(23, LOW)
(GP23: Wi-Fi module power) to turn off the WiFi chip power, the subsequent reconnect attempt fails. The issue specifically arises when trying to reinitialize the WiFiClient and reconnect to the WiFi network.Steps to Reproduce
WiFi.disconnect()
and turn off the WiFi chip power usingdigitalWrite(23, LOW)
.digitalWrite(23, HIGH)
and calling WiFi.begin(ssid, password) again.Expected Behavior
The WiFi chip should reconnect to the network, and WiFiClient should be able to establish a connection to the server.
Actual Behavior
The reconnection process fails, and WiFiClient cannot establish a new connection.
Reproduction Code
Additional Information
Board: Raspberry Pi Pico W
PlatformIO Framework: Arduino
Library: None
When the code related to WiFiClient is removed, the reconnection process works as expected.
It would be great to know if this is a bug or if there is a missing step in the process for properly reinitializing the WiFi chip and WiFiClient.
Thank you!
The text was updated successfully, but these errors were encountered: