Skip to content
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

ESP32 WiFi.begin works only every second time - workaround #2501

Closed
DIRR70 opened this issue Feb 24, 2019 · 400 comments · Fixed by #6359
Closed

ESP32 WiFi.begin works only every second time - workaround #2501

DIRR70 opened this issue Feb 24, 2019 · 400 comments · Fixed by #6359
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: Awaiting triage Issue is waiting for triage

Comments

@DIRR70
Copy link

DIRR70 commented Feb 24, 2019

Hardware:

Board: ESP32-WROOM-32 Dev Module
Core Installation version: 1.0.1 (installed using board manager feb/23)
IDE name: Arduino IDE 1.88
CPU Frequency: 80MHz
Flash Frequency: 40Mhz
Flash Mode: QIO
Flash Size: 2MB (16MB)
Partition Scheme: Standard
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10

Description:

With a portable device I need to ensure that WiFi connection is beeing established as soon as the router is in range. Also I need to do some stuff as soon the connection is established or lost (in my sketch below just a serial output).

I have the problem that "WiFi.begin(ssid, pass)" works only every second time. If it doesn't work, I have to press the reset button and then it works. If I press reset again it won't work. Pressing reset again and it works, and so on.

If it doesn't work I get the following output with Debug Level set to verbose:
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 202 - AUTH_FAIL

My router is a Fritz! Box 6490 cable and even though I've checked the router's options I can't find anything wrong. Regarding to familiar posts I even have tried with a regulated power supply at 5V (current limit 2.5A) - but no change.

I came up with a workaround with a task checking the connection and that works pretty well. In case of "WiFi.status" turns to "WL_CONNECT_FAILED" I need to call "WiFi.disconnect(true)" and a bit later "WiFi.begin" again.

About the whole working sketch below I have several questions:

  1. Is that "works/doesn't work" behaviour a firmware bug, a bug in arduino or this SDK or a router problem?
  2. In my sketch I'm using "xTaskCreatePinnedToCore" for the connection watching task. How large does the stack for that task need to be (seems to work with 8kB) and what priority does such a task need to have (I just took 3 to be higher than IDLE)?
  3. I never got "WL_CONNECTION_LOST" as Wifi status. Do I need to consider that? And if so, how?

Please advise! Thank's!

Sketch:

#include <WiFi.h>

const char* ssid = "...";
const char* password = "...";

bool myWiFiFirstConnect = true;

void myWiFiTask(void *pvParameters) {
  wl_status_t state;

  while (true) {
    state = WiFi.status();
    if (state != WL_CONNECTED) {  // We have no connection
      if (state == WL_NO_SHIELD) {  // WiFi.begin wasn't called yet
        Serial.println("Connecting WiFi");

        WiFi.mode(WIFI_STA);
        WiFi.begin(ssid, password);

      } else if (state == WL_CONNECT_FAILED) {  // WiFi.begin has failed (AUTH_FAIL)
        Serial.println("Disconnecting WiFi");

        WiFi.disconnect(true);

      } else if (state == WL_DISCONNECTED) {  // WiFi.disconnect was done or Router.WiFi got out of range
        if (!myWiFiFirstConnect) {  // Report only once
          myWiFiFirstConnect = true;

          Serial.println("WiFi disconnected");
        }
      }

      vTaskDelay (250); // Check again in about 250ms

    } else { // We have connection
      if (myWiFiFirstConnect) {  // Report only once
        myWiFiFirstConnect = false;

        Serial.print("Connected to ");
        Serial.println(ssid);
        Serial.print("IP address: ");
        Serial.println(WiFi.localIP());
        Serial.println("");
      }

      vTaskDelay (5000); // Check again in about 5s
    }
  }
}

void setup() {
  delay(1000); // Power up

  Serial.begin(115200);

  // Create a connection task with 8kB stack on core 0
  xTaskCreatePinnedToCore(myWiFiTask, "myWiFiTask", 8192, NULL, 3, NULL, 0);
}

void loop() {
}

Debug Messages:

If WiFi.begin works:
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
....[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.168.178.21, MASK: 255.255.255.0, GW: 192.168.178.1

If it doesn't work:
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 202 - AUTH_FAIL
@asetyde
Copy link

asetyde commented Feb 24, 2019

Also I confirm it , i use check every 5 seconds if is not connect, also sometimes passing char[] ssid and pass not work, i ve said many times but i never get a reply

@PhantomKunai
Copy link

From my experience, it seems that a

WiFi.disconnect();

Seems to reset the configurations. To be clear, while closing a connection/disconnecting you need to clear the configurations to enable a clean connect the second time around. I've used this to ensure solid connects and reconnects with any network. Although this seems to fail regardless of settings when connecting to a Mobile Hotspot. I feel it has something to do with the mobile hotspots, though.

@ImkereiWetzel
Copy link

I trying to solve the exact same problem here -
Test scenario: using example WifiClientEvents
If I reset the board, only every other reboot gives me a Wifi connection.

Is there something I can do to help fix this problem?

@timothy3001
Copy link

Facing the same issue here. If I capture the events via WiFi.on, i get the WiFiEvent_t number 5 which seems to be WIFI_REASON_ASSOC_TOOMANY.

When I keep resetting the board, this event is occuring every other time.

@kireol
Copy link

kireol commented May 22, 2019

Also experiencing this issue. NodeMCU board with ESP-WROOM-32. Calling WiFi.disconnect did not help.

@asetyde
Copy link

asetyde commented May 22, 2019

with library 1.0.3 rc connection 1 of 3 go , with 1.0.2 at 2 of 3 connect

@nouser2013
Copy link

nouser2013 commented May 25, 2019

I can confirm the issue with latest GIT. WiFi.disconnect() does not help, neither with true nor with false as argument.

@goldwingman
Copy link

I'm new to GitHub so please keep the flames low. I have duplicated the aforementioned "every other reset" issue on several ESP32 Wroom. I have also found a permanent solution to my problem. Not to suggest that this will address others problems but certainly worth the effort.
Arduino IDE 1.8.6
ESP32 1.0.2
I am running a fauxmoESP and Blynk app so not using WiFi.begin(). Just the same, only using WiFi.begin() without fauxmoESP and Blynk, always duplicated the "every other" reset condition.

I my case; ESP32 connected with RSSI levels of -70 or higher (even lower signal strength). After moving my project to final destination, RSSI levels of -50 or lower (higher signal strength) have been the expected normal. My ESP32 is connecting after every reset without any problem. So, signal quality appears to have EVERYTHING to do with my issue. I have not verified at what signal levels do things again become marginal.

Just to be clear:
D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 202 - AUTH_FAIL

Followed after reset by:
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
....[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.X.X.X, MASK: 255.255.255.0, GW: 192.X.X.X

Results after every reset with RSSI at -50 or lower
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
....[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.X.X.X, MASK: 255.255.255.0, GW: 192.X.X.X

Hope this helps someone.

@nouser2013
Copy link

Well, that may help pinpoint the bugs source code location. I did a different approach:

RTC_DATA_ATTR int bootCount;

void setup() {
  // ...
  // Reset Boot counter if reason was brownout or first power-on
  if (rtc_get_reset_reason(0) == 1 || rtc_get_reset_reason(0) == 15 || rtc_get_reset_reason(1) == 1 || rtc_get_reset_reason(1) == 15) { bootCount = 0; }
  bootCount++;
  // [Try to connect to WIFI here]
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("...WIFI is connected, local IP: ");
    Serial.println(WiFi.localIP());
  } else { 
    if (bootCount < 3) {
      Serial.println("...failed, REBOOT!");
      // Do not use ESP.restart! This would reset the RTC memory.
      esp_sleep_enable_timer_wakeup(10);
      esp_deep_sleep_start();
    } else {
      Serial.println("...finally failed.");
      Serial.println("Opening unprotected access point...");
      // Code to open WIFI AP
    }
  }
  // ...
}

@barneyz
Copy link

barneyz commented Jul 15, 2019

I had the same problem, the ESP.reboot() or esp_deep_sleep_start(); cannot proper reset the WiFi-Hardware, so every sencond time I got no Wifi connection.
I extended the code from DIRR70, now I get a connection every new start...

else if (wifi_state == WL_DISCONNECTED) // WiFi.disconnect was done or Router.WiFi got out of range
{
if (!myWiFiFirstConnect) // Report only once
{
myWiFiFirstConnect = true;
Serial.println("WiFi disconnected");
}
Serial.println("No Connection -> Wifi Reset");
WiFi.persistent(false);
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
// WiFi.config(ip, gateway, subnet); // Only for fix IP needed
WiFi.begin(ssid, password);
delay(3000); // Wait 3 Seconds, WL_DISCONNECTED is present until new connect!
}
vTaskDelay(250); // Check again in about 250ms

@Sandotter
Copy link

I can confirm this issue too with 2 different devices. @DIRR70 and @barneyz you made my day. The combination of your coding is a working workaround. Hopefully this issue will be solved. The above solution is not suitable for beginners.

@kugelkopf123
Copy link

Same here... Its pretty annoying...


WiFi Event ID: 3
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 2 - STA_START
[WiFi-event] event: 2
WiFi client started
[WiFi-event] event: 0
WiFi interface ready

.[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:351] _eventCallback(): Reason: 202 - AUTH_FAIL
202

@kugelkopf123
Copy link

By the way another Solution:
Based on @nouser2013 idea

  WiFiEventId_t eventID = WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
    Serial.print("WiFi lost connection. Reason: ");
    Serial.println(info.disconnected.reason);
    if (info.disconnected.reason == 202) {

      Serial.println("Connection failed, REBOOT/SLEEP!");
      esp_sleep_enable_timer_wakeup(10);
      esp_deep_sleep_start();
      delay(100);

    }
  }, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);

@Informaticore
Copy link

I had the same issue and it was fixed with calling WiFi.disconnect() before going into deep sleep.

@maxdd
Copy link

maxdd commented Aug 27, 2019

How come this problem is still present?!?! EPS32 is a mess like this.
Can anyone please post a decent code? Also i can make it reboot and have it connected but why do we need to do this, how come it cannot work properly. Not to mention that i have this problem on 3 devices and they also DC during the day without reconnecting anymore!

@kugelkopf123
Copy link

Another possibility is using wifimulti. But it takes longer.


#include <WiFi.h>
#include <WiFiMulti.h>

void setup() {
wifiMulti.addAP("SSID", "PASS");
if((wifiMulti.run() == WL_CONNECTED)) { 
Serial.println("Fantastic iam connected...");

}
}

@schreibfaul1
Copy link

wifiMulti.run() works only at second time after reset

#include <WiFiMulti.h>
WiFiMulti wifiMulti;

void setup() {
	wifiMulti.addAP("Wolles-FRITZBOX", "xxxxxxxxx");
	wifiMulti.run();
	WiFi.disconnect(true);
	wifiMulti.run();
}

void loop() {
}

result:

[I][WiFiMulti.cpp:84] addAP(): [WIFI][APlistAdd] add SSID: Wolles-FRITZBOX
[I][WiFiMulti.cpp:114] run(): [WIFI] scan done
[I][WiFiMulti.cpp:119] run(): [WIFI] 7 networks found
[I][WiFiMulti.cpp:160] run(): [WIFI] Connecting BSSID: 08:96:D7:FB:72:65 SSID: Wolles-FRITZBOX Channal: 11 (-28)
[W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 202 - AUTH_FAIL
[E][WiFiMulti.cpp:184] run(): [WIFI] Connecting Failed.
[I][WiFiMulti.cpp:114] run(): [WIFI] scan done
[I][WiFiMulti.cpp:119] run(): [WIFI] 7 networks found
[I][WiFiMulti.cpp:160] run(): [WIFI] Connecting BSSID: 08:96:D7:FB:72:65 SSID: Wolles-FRITZBOX Channal: 11 (-31)
[I][WiFiMulti.cpp:174] run(): [WIFI] Connecting done.

@kugelkopf123
Copy link

wifiMulti.run() works only at second time after reset

#include <WiFiMulti.h>
WiFiMulti wifiMulti;

void setup() {
	wifiMulti.addAP("Wolles-FRITZBOX", "xxxxxxxxx");
	wifiMulti.run();
	WiFi.disconnect(true);
	wifiMulti.run();
}

void loop() {
}

result:

[I][WiFiMulti.cpp:84] addAP(): [WIFI][APlistAdd] add SSID: Wolles-FRITZBOX
[I][WiFiMulti.cpp:114] run(): [WIFI] scan done
[I][WiFiMulti.cpp:119] run(): [WIFI] 7 networks found
[I][WiFiMulti.cpp:160] run(): [WIFI] Connecting BSSID: 08:96:D7:FB:72:65 SSID: Wolles-FRITZBOX Channal: 11 (-28)
[W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 202 - AUTH_FAIL
[E][WiFiMulti.cpp:184] run(): [WIFI] Connecting Failed.
[I][WiFiMulti.cpp:114] run(): [WIFI] scan done
[I][WiFiMulti.cpp:119] run(): [WIFI] 7 networks found
[I][WiFiMulti.cpp:160] run(): [WIFI] Connecting BSSID: 08:96:D7:FB:72:65 SSID: Wolles-FRITZBOX Channal: 11 (-31)
[I][WiFiMulti.cpp:174] run(): [WIFI] Connecting done.

Yes. But it doesnt reboot the ESP ;)

schreibfaul1 added a commit to schreibfaul1/ESP32-audioI2S that referenced this issue Sep 5, 2019
Use WiFiMulti, (bug in ESP32 release 1.0.2 and 1.0.3)  Reason: 202 - AUTH_FAIL after reset, see espressif/arduino-esp32#2501
@timothy3001
Copy link

Are there any news on this?

@HendrikHo
Copy link

Not fine, but this seems to work for me:

while (WiFi.status() != WL_CONNECTED) {
    WiFi.begin(c_wifi_ssid, c_wifi_psk);
    delay(1000);
    Serial.print(".")

@ThePositronCode
Copy link

WiFi.disconnect(); worked for me! Thank you so much @baaridunnasr

@ElToberino
Copy link

I'm also facing this annoying issue.
Using the workaround with WiFi.begin() works for me, but that's not a really satisfying solution because I'd like to use the wifimanager library - that's not possible with this method.

The WiFi issue seems to depend on the router or AP the ESP32 connects to.
I tested it with a "Netgear WN2000RPTv3" - the issue occurs and a connection is only established every second time.
Connecting to an "Arcadyan ARV752DPW" shows a completely different result: the ESP32 always connects as expected and the issue doesn't occur at all.

I really hope someone will find the reason for this bug and find a solution !

1technophile added a commit to 1technophile/OpenMQTTGateway that referenced this issue Dec 7, 2019
1technophile added a commit to 1technophile/OpenMQTTGateway that referenced this issue Dec 7, 2019
* do not launch a ble scan if mqtt client is disconnected

* add wifi.begin when disconnected

espressif/arduino-esp32#2501
@bkgoodman
Copy link

I too have this issue - but I am having much more difficult luck than most. It seems as though some combination of the disconnect, and deep-sleep reboot work - but sometimes it takes several reboots for that to happen. My AP is usually -70 to -50 dB.

I can't believe that this has gone on for SO LONG with so many people having connection issues...

BTW - BLE works flawlessly.

@tablatronix
Copy link
Contributor

Not yet, its only a test patch against a specific build, it is in the SDK so its a binary patch

@SofaSurfer76
Copy link

Hi everyone, this could be a little OT, but I have a very similar problem with an ESP32 Heltec Wifi Kit 32.
My router is a Fritz Box 7530, and I have problem to connect to it ONLY with this ESP32. after a few seconds after gettin IP of the ESP, the connection drops. I have tried both with Arduino IDE (not in multi connection), forcing reconnection with no results, and I have the same issue with ESPHOME,
I thik it's a problem only with FRITZ routers. I am solving this issue by using a repeater non-Fritz, in this way it works fine and the connection is stable.
Did someone have the same or a comparable issue?

@rljonesau
Copy link

rljonesau commented Mar 7, 2022 via email

@rljonesau
Copy link

rljonesau commented Mar 7, 2022 via email

@SofaSurfer76
Copy link

Yes, I saw as well the "handshake error" with another Heltec wifi kit 32, the first I have bought. Defo it's not a matter of device.. I will check fritz setting and if I can find something I will post it, maybe I will open another thread. In my case I can avoid the problem with the extender (out of my mesh network).

@tablatronix
Copy link
Contributor

tablatronix commented Mar 7, 2022

Post esp32 debug serial output please so we can confirm its the same or similar issue, another bugfix (workarounds) was posted recently for this by p-r-o-c-h-y

@SofaSurfer76
Copy link

SofaSurfer76 commented Mar 7, 2022

Hi,
below the log from serial output, the code is from Esphome, at the end there are the "4 handshake..."

Tonight I was able to connect with Arduino ide running the Factory test, if connected directly to Fritz router the connection drops after a few minutes and never connect; if I am connected to my extender non-mesh the connection is stable and I can ping for hours.

�[0;32m[I][app:062]: setup() finished successfully!�[0m
�[0;32m[I][app:102]: ESPHome version 2022.2.1 compiled on Mar  7 2022, 21:03:38�[0m
�[0;35m[C][wifi:491]: WiFi:�[0m
�[0;35m[C][wifi:353]:   Local MAC: 24:6F:28:79:14:00�[0m
�[0;35m[C][wifi:354]:   SSID: �[5m'Livello_pozzo'�[6m�[0m
�[0;35m[C][wifi:355]:   IP Address: 20.20.1.109�[0m
�[0;35m[C][wifi:357]:   BSSID: �[5m14:59:C0:9B:2D:DB�[6m�[0m
�[0;35m[C][wifi:358]:   Hostname: 'livello-pozzo-old'�[0m
�[0;35m[C][wifi:360]:   Signal strength: -75 dB �[0;33m▂▄�[0;37m▆█�[0m�[0m
�[0;37m[V][wifi:362]:   Priority: 0.0�[0m
�[0;35m[C][wifi:364]:   Channel: 1�[0m
�[0;35m[C][wifi:365]:   Subnet: 255.255.255.0�[0m
�[0;35m[C][wifi:366]:   Gateway: 20.20.1.1�[0m
�[0;35m[C][wifi:367]:   DNS1: 0.0.0.0�[0m
�[0;35m[C][wifi:368]:   DNS2: 0.0.0.0�[0m
�[0;35m[C][logger:233]: Logger:�[0m
�[0;35m[C][logger:234]:   Level: VERBOSE�[0m
�[0;35m[C][logger:235]:   Log Baud Rate: 115200�[0m
�[0;35m[C][logger:236]:   Hardware UART: UART0�[0m
�[0;35m[C][captive_portal:144]: Captive Portal:�[0m
�[0;35m[C][web_server:179]: Web Server:�[0m
�[0;35m[C][web_server:180]:   Address: 20.20.1.109:80�[0m
�[0;35m[C][mdns:084]: mDNS:�[0m
�[0;35m[C][mdns:085]:   Hostname: livello-pozzo-old�[0m
�[0;37m[V][mdns:086]:   Services:�[0m
�[0;37m[V][mdns:088]:   - _esphomelib, _tcp, 6053�[0m
�[0;37m[V][mdns:090]:     TXT: version = 2022.2.1�[0m
�[0;37m[V][mdns:090]:     TXT: mac = 246f28791400�[0m
�[0;37m[V][mdns:090]:     TXT: platform = ESP32�[0m
�[0;37m[V][mdns:090]:     TXT: board = heltec_wifi_kit_32_v2�[0m
�[0;35m[C][ota:085]: Over-The-Air Updates:�[0m
�[0;35m[C][ota:086]:   Address: 20.20.1.109:3232�[0m
�[0;35m[C][ota:089]:   Using Password.�[0m
�[0;33m[W][ota:095]: Last Boot was an unhandled reset, will proceed to safe mode in 5 restarts�[0m
�[0;35m[C][api:138]: API Server:�[0m
�[0;35m[C][api:139]:   Address: 20.20.1.109:6053�[0m
�[0;35m[C][api:143]:   Using noise encryption: NO�[0m
�[0;37m[V][esp-idf:000]: I (7568) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: run -> init (fc0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (7570) wifi:�[0m
�[0;37m[V][esp-idf:000]: pm stop, total sleep time: 0 us / 2960062 us
�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (7583) wifi:�[0m
�[0;37m[V][esp-idf:000]: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:391] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
�[0;33m[W][wifi_esp32:495]: Event: Disconnected ssid='Livello_pozzo' bssid=�[5m14:59:C0:9B:2D:DB�[6m reason='4-Way Handshake Timeout'�[0m
�[0;33m[W][wifi:120]: WiFi Connection lost... Reconnecting...�[0m
�[0;32m[I][wifi:248]: WiFi Connecting to 'Livello_pozzo'...�[0m
�[0;37m[V][wifi:250]: Connection Params:�[0m
�[0;37m[V][wifi:251]:   SSID: 'Livello_pozzo'�[0m
�[0;37m[V][wifi:254]:   BSSID: 14:59:C0:9B:2D:DB�[0m
�[0;37m[V][wifi:274]:   Password: �[5mxxxxxxxxxxxxxxxx'�[6m�[0m
�[0;37m[V][wifi:279]:   Channel: 1�[0m
�[0;37m[V][wifi:286]:   Manual IP: Static IP=20.20.1.109 Gateway=20.20.1.1 Subnet=255.255.255.0 DNS1=0.0.0.0 DNS2=0.0.0.0�[0m
�[0;37m[V][wifi:290]:   Hidden: NO�[0m
�[0;37m[V][component:199]: Component wifi took a long time for an operation (0.05 s).�[0m
�[0;37m[V][component:200]: Components should block for at most 20-30ms.�[0m
�[0;37m[V][esp-idf:000]: I (7688) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: auth -> assoc (0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (7702) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: assoc -> run (10)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (10005) wifi:�[0m
�[0;37m[V][esp-idf:000]: connected with Livello_pozzo, aid = 1, channel 1, BW20, bssid = 14:59:c0:9b:2d:db�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (10011) wifi:�[0m
�[0;37m[V][esp-idf:000]: security type: 3, phy: bgn, rssi: -73�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (10024) wifi:�[0m
�[0;37m[V][esp-idf:000]: pm start, type: 0
�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 20.20.1.109, MASK: 255.255.255.0, GW: 20.20.1.1
�[0;37m[V][wifi_esp32:537]: Event: Got IP static_ip=20.20.1.109 gateway=20.20.1.1�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 20.20.1.109, MASK: 255.255.255.0, GW: 20.20.1.1
�[0;37m[V][esp-idf:000]: AP's beacon interval = 102400 us, DTIM period = 2�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;32m[I][wifi:505]: WiFi Connected!�[0m
�[0;35m[C][wifi:353]:   Local MAC: 24:6F:28:79:14:00�[0m
�[0;35m[C][wifi:354]:   SSID: �[5m'Livello_pozzo'�[6m�[0m
�[0;35m[C][wifi:355]:   IP Address: 20.20.1.109�[0m
�[0;35m[C][wifi:357]:   BSSID: �[5m14:59:C0:9B:2D:DB�[6m�[0m
�[0;35m[C][wifi:358]:   Hostname: 'livello-pozzo-old'�[0m
�[0;35m[C][wifi:360]:   Signal strength: -73 dB �[0;33m▂▄�[0;37m▆█�[0m�[0m
�[0;37m[V][wifi:362]:   Priority: -1.0�[0m
�[0;35m[C][wifi:364]:   Channel: 1�[0m
�[0;35m[C][wifi:365]:   Subnet: 255.255.255.0�[0m
�[0;35m[C][wifi:366]:   Gateway: 20.20.1.1�[0m
�[0;35m[C][wifi:367]:   DNS1: 0.0.0.0�[0m
�[0;35m[C][wifi:368]:   DNS2: 0.0.0.0�[0m
�[0;36m[D][wifi:514]: Disabling AP...�[0m
�[0;37m[V][component:199]: Component wifi took a long time for an operation (0.07 s).�[0m
�[0;37m[V][component:200]: Components should block for at most 20-30ms.�[0m
�[0;37m[V][esp-idf:000]: I (12992) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: run -> init (fc0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (12994) wifi:�[0m
�[0;37m[V][esp-idf:000]: pm stop, total sleep time: 0 us / 2959625 us
�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (13007) wifi:�[0m
�[0;37m[V][esp-idf:000]: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:391] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
�[0;33m[W][wifi_esp32:495]: Event: Disconnected ssid='Livello_pozzo' bssid=�[5m14:59:C0:9B:2D:DB�[6m reason='4-Way Handshake Timeout'�[0m
�[0;33m[W][wifi:120]: WiFi Connection lost... Reconnecting...�[0m
�[0;32m[I][wifi:248]: WiFi Connecting to 'Livello_pozzo'...�[0m
�[0;37m[V][wifi:250]: Connection Params:�[0m
�[0;37m[V][wifi:251]:   SSID: 'Livello_pozzo'�[0m
�[0;37m[V][wifi:254]:   BSSID: 14:59:C0:9B:2D:DB�[0m
�[0;37m[V][wifi:274]:   Password: �[5m'xxxxxxxxxxxxxxxxxx'�[6m�[0m
�[0;37m[V][wifi:279]:   Channel: 1�[0m
�[0;37m[V][wifi:286]:   Manual IP: Static IP=20.20.1.109 Gateway=20.20.1.1 Subnet=255.255.255.0 DNS1=0.0.0.0 DNS2=0.0.0.0�[0m
�[0;37m[V][wifi:290]:   Hidden: NO�[0m
�[0;37m[V][component:199]: Component wifi took a long time for an operation (0.05 s).�[0m
�[0;37m[V][component:200]: Components should block for at most 20-30ms.�[0m
�[0;37m[V][esp-idf:000]: I (13115) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: auth -> assoc (0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (13128) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: assoc -> run (10)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (13436) wifi:�[0m
�[0;37m[V][esp-idf:000]: connected with Livello_pozzo, aid = 1, channel 1, BW20, bssid = 14:59:c0:9b:2d:db�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (13442) wifi:�[0m
�[0;37m[V][esp-idf:000]: security type: 3, phy: bgn, rssi: -73�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (13455) wifi:�[0m
�[0;37m[V][esp-idf:000]: pm start, type: 0
�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (13467) wifi:�[0m
�[0;37m[V][esp-idf:000]: AP's beacon interval = 102400 us, DTIM period = 2�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 20.20.1.109, MASK: 255.255.255.0, GW: 20.20.1.1
�[0;37m[V][wifi_esp32:537]: Event: Got IP static_ip=20.20.1.109 gateway=20.20.1.1�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 20.20.1.109, MASK: 255.255.255.0, GW: 20.20.1.1
�[0;37m[V][wifi_esp32:537]: Event: Got IP static_ip=20.20.1.109 gateway=20.20.1.1�[0m
�[0;32m[I][wifi:505]: WiFi Connected!�[0m
�[0;35m[C][wifi:353]:   Local MAC: 24:6F:28:79:14:00�[0m
�[0;35m[C][wifi:354]:   SSID: �[5m'Livello_pozzo'�[6m�[0m
�[0;35m[C][wifi:355]:   IP Address: 20.20.1.109�[0m
�[0;35m[C][wifi:357]:   BSSID: �[5m14:59:C0:9B:2D:DB�[6m�[0m
�[0;35m[C][wifi:358]:   Hostname: 'livello-pozzo-old'�[0m
�[0;35m[C][wifi:360]:   Signal strength: -74 dB �[0;33m▂▄�[0;37m▆█�[0m�[0m
�[0;37m[V][wifi:362]:   Priority: -2.0�[0m
�[0;35m[C][wifi:364]:   Channel: 1�[0m
�[0;35m[C][wifi:365]:   Subnet: 255.255.255.0�[0m
�[0;35m[C][wifi:366]:   Gateway: 20.20.1.1�[0m
�[0;35m[C][wifi:367]:   DNS1: 0.0.0.0�[0m
�[0;35m[C][wifi:368]:   DNS2: 0.0.0.0�[0m
�[0;36m[D][wifi:514]: Disabling AP...�[0m
�[0;37m[V][component:199]: Component wifi took a long time for an operation (0.06 s).�[0m
�[0;37m[V][component:200]: Components should block for at most 20-30ms.�[0m
�[0;37m[V][esp-idf:000]: I (16426) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: run -> init (fc0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (16428) wifi:�[0m
�[0;37m[V][esp-idf:000]: pm stop, total sleep time: 0 us / 2961869 us
�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (16441) wifi:�[0m
�[0;37m[V][esp-idf:000]: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:391] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
�[0;33m[W][wifi_esp32:495]: Event: Disconnected ssid='Livello_pozzo' bssid=�[5m14:59:C0:9B:2D:DB�[6m reason='4-Way Handshake Timeout'�[0m
�[0;33m[W][wifi:120]: WiFi Connection lost... Reconnecting...�[0m
�[0;32m[I][wifi:248]: WiFi Connecting to 'Livello_pozzo'...�[0m
�[0;37m[V][wifi:250]: Connection Params:�[0m
�[0;37m[V][wifi:251]:   SSID: 'Livello_pozzo'�[0m
�[0;37m[V][wifi:254]:   BSSID: 14:59:C0:9B:2D:DB�[0m
�[0;37m[V][wifi:274]:   Password: �[5m'xxxxxxxxxxxxxxxxxx'�[6m�[0m
�[0;37m[V][wifi:279]:   Channel: 1�[0m
�[0;37m[V][wifi:286]:   Manual IP: Static IP=20.20.1.109 Gateway=20.20.1.1 Subnet=255.255.255.0 DNS1=0.0.0.0 DNS2=0.0.0.0�[0m
�[0;37m[V][wifi:290]:   Hidden: NO�[0m
�[0;37m[V][component:199]: Component wifi took a long time for an operation (0.05 s).�[0m
�[0;37m[V][component:200]: Components should block for at most 20-30ms.�[0m
�[0;37m[V][esp-idf:000]: I (16545) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: auth -> assoc (0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (16560) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: assoc -> run (10)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (19780) wifi:�[0m
�[0;37m[V][esp-idf:000]: state: run -> init (fc0)�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
�[0;37m[V][esp-idf:000]: I (19782) wifi:�[0m
�[0;37m[V][esp-idf:000]: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1�[0m
�[0;37m[V][esp-idf:000]: 
�[0m
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:391] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
�[0;33m[W][wifi_esp32:495]: Event: Disconnected ssid='Livello_pozzo' bssid=�[5m14:59:C0:9B:2D:DB�[6m reason='4-Way Handshake Timeout'�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
�[0;33m[W][wifi:557]: WiFi Unknown connection status 0�[0m
```



@rljonesau
Copy link

rljonesau commented Mar 7, 2022 via email

@tablatronix
Copy link
Contributor

tablatronix commented Mar 8, 2022

Thanks, yes 4WAY_HANDSHAKE_TIMEOUT seems to not be covered here, interesting that there is also an regular handshake timeout, perhaps adding this to the first_connect patch above will help..

I wonder what causes this one, probably similar cause different software handling on the ap side.

Are these both fritzboxs?

Anyone know what security type: 3, is..

Also what IDF ver if its not in your logs

@rljonesau
Copy link

rljonesau commented Mar 8, 2022 via email

@SofaSurfer76
Copy link

@tablatronix
Copy link
Contributor

tablatronix commented Mar 8, 2022

Yeah without wireshark logs, its best guess, sometimes band steering and mesh. Best workaround for now is to disconnect, delay a few seconds for the router to drop its negotiation queue and try again.. other wise you will have to turn stuff off and test, PMF off, band steering off, wpa2 not 3 etc.. could just be a bug in the router software all these linux boxes uses the same stuff

@rljonesau
Copy link

rljonesau commented Mar 9, 2022 via email

@tablatronix
Copy link
Contributor

tablatronix commented Mar 9, 2022

Yes, Wireshark can capture 802.11 frames when used with a wifi phy that lets you put it into monitor mode. Some hardware does, some doesn't and you also need the capability to lock it to a specific channel.

hmm are you sure you are disconnecting fully ?

@bhupiister
Copy link

This seems to work for me on every restart, working on mobile hotspot as well.. (Without restarting ESP)

static bool ConnectWifi(const char *_ssid, const char *wifipass)
{
  WiFi.disconnect(true, true);
  WiFi.begin(_ssid, wifipass);
  uint8_t wifiAttempts = 0;
  while (WiFi.status() != WL_CONNECTED && wifiAttempts < 20)
  {
    Serial.print(".");
    delay(1000);
    if(wifiAttempts == 10)
    {
      WiFi.disconnect(true, true);//Switch off the wifi on making 10 attempts and start again.
      WiFi.begin(_ssid, wifipass);
    }
    wifiAttempts++;
  }
  if (WiFi.status() == WL_CONNECTED)
  {
    WiFi.setAutoReconnect(true);//Not necessary
    Serial.println();//Not necessary
    Serial.print("Connected with IP: ");//Not necessary
    Serial.println(WiFi.localIP());//Not necessary
    return true;
  }
  else
  {
    WiFi.disconnect(true, true);
    return false;
  }
  delay(100);
}

@FlyingRossolini
Copy link

I realize this issue is closed, but I felt I had to document my $0.02 somewhere and this seemed as an appropriate place as any.

My current project requires 4 separate ESP32 in close proximity to each other. I didn't start having issues with wifi until I started dealing with 2 or more going online at the same time. My r&d with a single ESP32 would connect to my router without any issue and work fine. As soon as I attempted to power up additional microcontrollers, the exact issues described here started making a grand entrance - issues connecting galore, but once it did connect (i.e. a second press of the reset button, but not the first) it was rock solid stable.

This leads me to believe the onboard pcb antenna is noisy, especially with the initial connect sequence. However, without being armed with any SnR meters or equipment to prove or disprove this, I may as well be shaking my fist at the clouds. My google-fu eventually lead me here.

I did want to create an account after finding this thread and trying the code from bhupiister. This the only code that would work for me and connect all 4 ESP32s to my wifi. It's actually quite interesting to watch them connect up on power up - It will take 10 seconds for ONE esp32 to connect, and then another 10 seconds for only ONE more to connect. Another 10 seconds, ... well, you get the idea.

Eventually all 4 ESPs will connect.... I just find it strange that they would exhibit this kind of behavior. Hopefully this info helps some wayward intrepid future troubleshooter. (Huge thank you to bhupiister - if no one has told you this yet today, allow me to be the first - you are awesome!)

@tablatronix
Copy link
Contributor

Sounds unrelated, try making sure you have WiFi.mode(STA) in your setup if using arduino, aka make sure you are not starting up softaps, as they will certainly cause issues if they are in range of each other. This issue is very specific to access points sending/responding to deauths

@miky-boy
Copy link

Hi,
I started this days testing my ESP32 for the first time and i realized this same issue. Sometime can't connect at first time and others do without any specific reason. I use this same code on my all couple of ESP8266 and never experiencid this anoying issue.
I'm side by sude with the ONT and is not a matter of signal...something is wrong somewhere. I activated the debug and realized this error when it occurs: 4WAY_HANDSHAKE_TIMEOUT
I saw a lot of people with the same issue, so why it can be definitively solved to avoid some strange workarouds?
I saw people saying about the version 1.0.2 or 1.0.0 where this issue doesn't acour.
Exists any ESP32 stable version to develop our projects?
Thanks and Regards

@tablatronix
Copy link
Contributor

I am getting 4 way handshake timeouts also now.

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
Projects
Development

Successfully merging a pull request may close this issue.