Skip to content

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

Closed
1 task done
cicciocb opened this issue Sep 11, 2022 · 17 comments
Closed
1 task done
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: Awaiting triage Issue is waiting for triage Status: Community help needed Issue need help from any member from the Community.

Comments

@cicciocb
Copy link

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

#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 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("Bbox-AED5AE73", "mypass");
    for (int i = 0; i < 50; i++)
    {
        if (WiFi.status() == WL_CONNECTED) {
            Serial.printf("Connected\n");
            break;
        }
        Serial.print(".");
        delay(500);
    }
    delay(10000);
    Serial.print("Freq 160");
    setCpuFrequencyMhz(160);
    delay(10000);
    Serial.print("Freq 80");
    setCpuFrequencyMhz(80);
    delay(10000);
    Serial.print("Freq 240");
    setCpuFrequencyMhz(240);

}

// Add the main program code into the continuous loop() function
void loop()
{


}

Debug Message

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
[    57][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[   141][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[   143][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[   143][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
.[   212][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: Bbox-AED5AE73, BSSID: d8:d7:75:d6:44:80, Channel: 1, Auth: WPA_WPA2_PSK
[   214][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
CONNECTED
[   558][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:192.168.1.85
[   558][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[   561][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.1.85, MASK: 255.255.255.0, GW: 192.168.1.254

Connected to Bbox-AED5AE73
IP address: 192.168.1.85
Connected
���00662][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 320 / 2 = 160 Mhz, APB: 80000000 Hz
Freq 160
[ 19143][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: Bbox-AED5AE73, BSSID: d8:d7:75:d6:44:80, Reason: 200
[ 19144][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 19152][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 200 - BEACON_TIMEOUT
[ 19159][D][WiFiGeneric.cpp:966] _eventCallback(): WiFi Reconnect Running
[ 19167][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 20663][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz
Freq 80
[ 21241][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: Bbox-AED5AE73, BSSID: 00:00:00:00:00:00, Reason: 201
[ 21242][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 21249][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 21256][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 21266][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 23349][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: Bbox-AED5AE73, BSSID: 00:00:00:00:00:00, Reason: 201
[ 23350][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 23357][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 23364][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 23374][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 25456][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: Bbox-AED5AE73, BSSID: 00:00:00:00:00:00, Reason: 201
[ 25457][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 25464][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 25471][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 25481][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 27563][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: Bbox-AED5AE73, BSSID: 00:00:00:00:00:00, Reason: 201
[ 27564][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 27571][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 27578][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 27588][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 29669][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: Bbox-AED5AE73, BSSID: 00:00:00:00:00:00, Reason: 201
[ 29670][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 29678][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 29684][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 29695][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[�������m�um����2-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
Freq 240
[ 30853][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: Bbox-AED5AE73, BSSID: d8:d7:75:d6:44:80, Channel: 1, Auth: WPA_WPA2_PSK
[ 30856][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
CONNECTED
[ 30879][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got Same IP:192.168.1.85
[ 30879][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[ 30882][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.1.85, MASK: 255.255.255.0, GW: 192.168.1.254

Connected to Bbox-AED5AE73
IP address: 192.168.1.85

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@cicciocb cicciocb added the Status: Awaiting triage Issue is waiting for triage label Sep 11, 2022
@SuGlider
Copy link
Collaborator

@cicciocb - I can't reproduce this issue using Arduino Core 2.0.4.
It works fine here. I can also access any WebSite using WiFiClient at any CPU Frequency.

@cicciocb
Copy link
Author

cicciocb commented Sep 12, 2022

Very strange, I tried to download again the core 2.0.4 and I still have the same problem.
I tried also with Wemos D1 mini and I confirm the same problem.
The same code on an ESP32-S2 works well.
Maybe someone else could confirm ...

@SuGlider
Copy link
Collaborator

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 SuGlider added the Status: Community help needed Issue need help from any member from the Community. label Sep 12, 2022
@cicciocb
Copy link
Author

cicciocb commented Sep 12, 2022

@SuGlider Thanks for your time.
Just tested your code and I confirm the issue

This is the log


rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
[������m�um����2-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[    67][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[   158][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[   159][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[   160][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
.[   211][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: MYSPOT, BSSID: 1c:bf:ce:6a:63:aa, Channel: 11, Auth: WPA2_PSK
[   212][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
CONNECTED
[   262][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:192.168.137.143
[   262][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[   265][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.137.143, MASK: 255.255.255.0, GW: 192.168.137.1

Connected to MYSPOT
IP address: 192.168.137.143
Connected
connecting to espressif.com
[   686][V][WiFiGeneric.cpp:390] _arduino_event_cb(): AP Started
[   686][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 10 - AP_START
Requesting URL: /index.html
HTTP/1.1 301 Moved Permanently
Server: CloudFront
Date: Mon, 12 Sep 2022 11:19:30 GMT
Content-Type: text/html
Content-Length: 183
Connection: close
Location: https://espressif.com/index.html
X-Cache: Redirect from cloudfront
Via: 1.1 6c980dcb60a714b7de2e5b65761a4940.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: CDG53-C1
X-Amz-Cf-Id: OVIoTGz-1Ezik-8d5z_3KxWLiNGtx2SxlJh8AcB_56dj--V6LwKbcQ==
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
Vary: Origin

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>CloudFront</center>
</body>
</html>


Running at 240 MHz
closing connection
Fre�����ځ11822][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 320 / 2 = 160 Mhz, APB: 80000000 Hz
connecting to espressif.com
[ 14825][I][WiFiClient.cpp:253] connect(): select returned due to timeout 3000 ms for fd 48
connection failed
[ 20240][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 1c:bf:ce:6a:63:aa, Reason: 200
[ 20240][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 20247][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 200 - BEACON_TIMEOUT
[ 20254][D][WiFiGeneric.cpp:966] _eventCallback(): WiFi Reconnect Running
[ 20263][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 22731][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 22731][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 22738][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 22745][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 22754][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
Freq 80[ 24826][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz
connecting to espressif.com
[ 25219][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 25220][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 25227][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 25233][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 25244][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 27727][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 27728][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 27735][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 27742][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 27752][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 27831][I][WiFiClient.cpp:253] connect(): select returned due to timeout 3000 ms for fd 48
connection failed
[ 30234][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 30235][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 30242][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 30248][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 30259][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 32741][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 32741][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 32748][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 32755][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 32766][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 35247][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 35248][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 35255][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 35262][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 35273][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 37754][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 37755][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 37762][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 37768][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 37779][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
connecting to espressif.com
[ 40261][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: MYSPOT, BSSID: 00:00:00:00:00:00, Reason: 201
[ 40262][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 40269][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 40276][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi AutoReconnect Running
[ 40287][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
DISCONNECTED
[ 40836][I][WiFiClient.cpp:253] connect(): select returned due to timeout 3000 ms for fd��8
connection failed
Freq 240[ 40837][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
connecting to espressif.com
[ 40907][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: MYSPOT, BSSID: 1c:bf:ce:6a:63:aa, Channel: 11, Auth: WPA2_PSK
[ 40908][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
CONNECTED
[ 40954][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got Same IP:192.168.137.143
[ 40954][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[ 40958][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 192.168.137.143, MASK: 255.255.255.0, GW: 192.168.137.1

Connected to MYSPOT
IP address: 192.168.137.143
[ 43855][I][WiFiClient.cpp:253] connect(): select returned due to timeout 3000 ms for fd 48
connection failed
End of Testing....
End of Testing....````

@felmue
Copy link

felmue commented Sep 12, 2022

Hi @cicciocb

just a thought - have you tried a different AP?

Thanks
Felix

@cicciocb
Copy link
Author

cicciocb commented Sep 12, 2022

@felmue As you can see in the latest log, I'm using another AP (MYSPOT) as I'm actually in another site.

@felmue
Copy link

felmue commented Sep 12, 2022

Hi @cicciocb

ok, sorry, I missed that.

Thanks
Felix

@VojtechBartoska VojtechBartoska added the Area: BT&Wifi BT & Wifi related issues label Sep 13, 2022
@cicciocb
Copy link
Author

cicciocb commented Sep 14, 2022

@felmue You are welcome.
In the while I tested with another kind of module, an ESP32-CAM and I confirm this issue.
The same problem exists also with the SDK 1.0.6
Rolling back the SDK to the version 1.0.4 the problem disappears, so it looks that something happened from the 1.0.4 to the 1.0.6

@cicciocb
Copy link
Author

Just to conclude this post, I found a workaround, maybe can be useful for others.
In fact using the following sequence

    WiFi.setSleep(true); delay(100);
    setCpuFrequencyMhz(160);
    WiFi.setSleep(false);

instead of the simple

setCpuFrequencyMhz(160);

enables to change the CPU frequency without WiFi disconnections

@SuGlider
Copy link
Collaborator

Rolling back the SDK to the version 1.0.4 the problem disappears, so it looks that something happened from the 1.0.4 to the 1.0.6

It may be related to IDF version as well... WiFi is based on IDF llibraries.
I think it may have relationship with Authentication and WiFi.
Do you know what is the Authentication method used in the AP (MYSPOT)?
Is it WPA, WAP2, WAP_WAP2, WAP3, None...
Is TKIP enabled?

@cicciocb
Copy link
Author

Rolling back the SDK to the version 1.0.4 the problem disappears, so it looks that something happened from the 1.0.4 to the 1.0.6

It may be related to IDF version as well... WiFi is based on IDF llibraries. I think it may have relationship with Authentication and WiFi. Do you know what is the Authentication method used in the AP (MYSPOT)? Is it WPA, WAP2, WAP_WAP2, WAP3, None... Is TKIP enabled?

Thanks for your answer, in fact I found a workaround so it is not really an issue for me anymore.
I have the same problem with several hotspots, including the WINDOWS10 hotspot that is in WPA2-PSK AES

@SuGlider SuGlider self-assigned this Sep 19, 2022
@srcastor
Copy link

srcastor commented Jan 9, 2023

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).

@scottchiefbaker
Copy link

scottchiefbaker commented Mar 13, 2023

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 setCpuFrequencyMhx() after WiFi is initialized I lose connection. I'm using ESP 2.0.7 if it matters.

Is CPU speed switching not supported while using WiFi?

@fredlcore
Copy link

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.

@JooJooBee666
Copy link

JooJooBee666 commented Aug 9, 2023

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:

Screen off for timer!
�␀�␞f␘xx�x�f�␆`�f�fx␞␀�x␘��␘�␆␆��␞␀f~��␞�~␘␘␞`�~␀��fx`�␀f~x��fx␆f~f��␞ff����␆����␀␘ff␀␆��␀␘␞␀␀��␀��␀��␀␘␞␀␀�␞␆��␆�␀�␀␀f��~␀␘␞␀␀␀␀␀␀␀␀␘��f�X 5:12 PM
 5 12 PM
 5:12 PM
 5 12 PM
 5:12 PM
 5 12 PM
 5:12 PM
[ 83733][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: WiFiSSID, BSSID: fc:34:97:03:38:d8, Reason: 200
[ 83736][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 83742][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 200 - BEACON_TIMEOUT
[ 83750][D][WiFiGeneric.cpp:1077] _eventCallback(): WiFi Reconnect Running
83771Reconnecting to WiFi...
 5 12 PM
 5:12 PM
 5 12 PM
[ 86201][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: WiFiSSID, BSSID: 00:00:00:00:00:00, Reason: 201
[ 86203][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 86210][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND
[ 86217][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running

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:

[373577][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: WiFiSSID, BSSID: 00:00:00:00:00:00, Reason: 201
[373580][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[373586][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND
[373593][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running
)J��␗)<=��Jk���Q���␎��M␖
�K�␐��JJ
��Screen ON!
 5 17 PM
updateWiFiStatus: Checking WiFi signal...
drawActionBMPdata: Opening file /wifi-disconnected.bin
15
drawActionBMPdata: Drawing of /wifi-disconnected.bin completed.
[374459][V][WiFiGeneric.cpp:355] _arduino_event_cb(): STA Connected: SSID: WiFiSSID, BSSID: fc:34:97:03:38:d8, Channel: 6, Auth: WPA_WPA2_PSK
[374461][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
[374464][V][WiFiGeneric.cpp:369] _arduino_event_cb(): STA Got New IP:192.168.1.30
[374475][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[374483][D][WiFiGeneric.cpp:1098] _eventCallback(): STA IP: 192.168.1.30, MASK: 255.255.255.0, GW: 192.168.1.1

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.

@JooJooBee666
Copy link

Should I just open a new issue?

@srcastor
Copy link

srcastor commented Nov 9, 2023

Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Awaiting triage Issue is waiting for triage Status: Community help needed Issue need help from any member from the Community.
Projects
None yet
Development

No branches or pull requests

8 participants