-
Notifications
You must be signed in to change notification settings - Fork 7.6k
The WiFi disconnects as soon as the CPU frequency is modified with setCpuFrequencyMhz() #7240
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
Comments
@cicciocb - I can't reproduce this issue using Arduino Core 2.0.4. |
Very strange, I tried to download again the core 2.0.4 and I still have the same problem. |
I have used this sketch (similar to the one posted here + WiFiClient test): #include <WiFi.h>
void onGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
Serial.print(F("\nConnected to "));
Serial.println(WiFi.SSID());
Serial.print(F("IP address: "));
Serial.println(WiFi.localIP());
WiFi.setAutoReconnect(true);
}
void onConnected(WiFiEvent_t event, WiFiEventInfo_t info) {
Serial.println("CONNECTED");
}
void onDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
Serial.println("DISCONNECTED");
}
void readRemoteSite() {
const char* host = "espressif.com";
const char* url = "/index.html";
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
WiFi.mode(WIFI_AP_STA);
WiFi.enableSTA(true);
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.printf("\nRunning at %d MHz\n", getCpuFrequencyMhz());
Serial.println("closing connection");
}
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.onEvent(onGotIP, ARDUINO_EVENT_WIFI_STA_GOT_IP);
WiFi.onEvent(onConnected, ARDUINO_EVENT_WIFI_STA_CONNECTED);
WiFi.onEvent(onDisconnected, ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
WiFi.setSleep(false); // enable the wifi all the time
WiFi.begin("SSID", "wifi_Password");
for (int i = 0; i < 50; i++)
{
if (WiFi.status() == WL_CONNECTED) {
Serial.printf("Connected\n");
break;
}
Serial.print(".");
delay(500);
}
readRemoteSite();
delay(10000);
Serial.print("Freq 160");
setCpuFrequencyMhz(160);
readRemoteSite();
delay(10000);
Serial.print("Freq 80");
setCpuFrequencyMhz(80);
readRemoteSite();
delay(10000);
readRemoteSite();
Serial.print("Freq 240");
setCpuFrequencyMhz(240);
readRemoteSite();
}
// Add the main program code into the continuous loop() function
void loop()
{
Serial.println("End of Testing....");
delay(10000);
} |
@SuGlider Thanks for your time. This is the log
|
Hi @cicciocb just a thought - have you tried a different AP? Thanks |
@felmue As you can see in the latest log, I'm using another AP (MYSPOT) as I'm actually in another site. |
Hi @cicciocb ok, sorry, I missed that. Thanks |
@felmue You are welcome. |
Just to conclude this post, I found a workaround, maybe can be useful for others.
instead of the simple
enables to change the CPU frequency without WiFi disconnections |
It may be related to IDF version as well... WiFi is based on IDF llibraries. |
Thanks for your answer, in fact I found a workaround so it is not really an issue for me anymore. |
Same problem here, the workaround from @cicciocb works but if you often play with the values ends up disconnecting, as example going back from 160Mhz modem sleep true to 240Mhz no modem sleep will force a disconnection, then reconnect and it is stable (until you change the frequency again). |
I'm working on a debugging library and one of the features I'd like to implement is CPU Speed switching on the fly. Whenever I use Is CPU speed switching not supported while using WiFi? |
Switching CPU speed works for me generally also with WIFI whether using the workaround above or not, but what I experience here is that my sketch runs most of the time with 80 MHz and only for the purpose of outputting a data log, I increase the speed to 240 MHz. With LAN, this brings an output improvement of around 20%, but with WIFI it's actually getting worse! Instead of around 300 kB/s with 80 MHz, I get less than 100 kB/s, sometimes even much less or even a stalled connection. This is not the case when setting the CPU speed once and for all at the beginning of the script, both with 80 or with 240 MHz. |
This is still an issue and should be reopened. The workaround that @cicciocb posted does not work for me. I still lose connectivity about 5 seconds after lowering the CPU speed and it does not reconnect until I bump the speed back up to 240. This happens every single time. Can we reopen this so the actual source of the problem is identified? Here's what I see in my logs:
The gibberish is due to the CPU frequency change where I have to reinitialize the Serial output every time it changes (another bug that was never fully fixed). Also, you will notice that it sees it is disconnected and tries to reconnect, but it simply REFUSES. It's not until I "wake" it (the Screen ON and OFF is where the CPU changes occur in code), where the CPU speed is set back to 240Mhz that the WiFi reconnects:
The only difference during the reconnect is the CPU speed. This should not be. I would really like to get this working as I need the WiFi to stay up and running even in low power mode as I am trying to use these for some IoT devices I am creating that can run on battery if need be. |
Should I just open a new issue? |
Any news on this? |
Board
ESP32 Dev Module
Device Description
A bare ESP32 Dev Module
Hardware Configuration
N/A
Version
v2.0.4
IDE Name
Arduino IDE
Operating System
Windows 10
Flash frequency
80 Mhz
PSRAM enabled
no
Upload speed
115200
Description
The WiFi connection is lost as soon as the setCpuFrequencyMhz() is used with a value or 80 or 160.
The connection comes back when the frequency is set back to 240MHz.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: