-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WiFi auto reconnect should occur for all disconnect reasons #7210
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
@RefactorFactory - thanks for reporting such detailed and well explained issue! Let's check it out and find a good fix. |
I have noticed this on 2.0.3 (platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.3/platform-espressif32-2.0.3.zip).
This event happens half the time after programming. Must reboot to get the device to connect. |
The WiFi failure on "ASSOC_EXPIRE" is a serious bug for us, so I plan to submit a PR to fix this issue. Extensive analysis follows. Feedback wanted!When ARDUINO_EVENT_WIFI_STA_DISCONNECTED occurs,
These are the current disconnect reasons from esp_wifi_types.h, wifi_err_reason_t:
Based on my understanding of scan-when-wi-fi-is-connecting , I would break down the disconnect reasons as:
Since the initial retry fires on AUTH_FAIL, I would argue it should retry for ALL disconnect reasons except WIFI_REASON_ASSOC_LEAVE. I believe the auto-reconnect should trigger for all Timeout and Transient errors. I don't know what to do with the Unknown reasons. Note to self: will be submitting PR against WiFiGeneric.cpp |
See also issue espressif#7210
See also issue espressif#7210
See also issue espressif#7210
While #7344 is an great improvement over the existing code and it handles all the WiFi disconnect reasons that I've personally seen, why not just do as the official ESP-IDF samples? Consider if there is a problem with #7344 in the future. At that time, if we ask Espressif, they might say "hmm, we never encountered such a problem because we never do that in our ESP-IDF samples (and perhaps other tests)." This hypothetical problem could have been avoided by matching what Espressif does in their code. Another way to look at this: is it a "bug" in the ESP-IDF samples that they don't do something as complicated as we're suggesting for Arduino-esp32? Perhaps the ESP-IDF samples are "simple" because they're just samples, so it's ok for them, but not real projects? BTW, I think esphome retries on all disconnect reasons, but I'm not 100% sure because their code is more complicated. |
I think a permanent reconnect regardless of the error would be a bad thing. e.g. The WiFi would keep retrying on bad credentials or incorrect configuration. In my app I need the permanent failure before I can rollback to SoftAP for recovery. Looking at this IDF sample: https://github.com/espressif/esp-idf/blob/v4.4.2/examples/wifi/getting_started/station/main/station_example_main.c#L68 |
Ok, how permanent reconnect unless the disconnect reason is one of a small list (for bad credentials or incorrect configuration)? Then again, are you sure that a WiFi router will not momentarily return "bad credentials"?
That sample uses a default of 5 retries (unless one runs Imagine putting together a project, setting it up, taking a trip, and then the retries fail while you're many hours or days away. This can cause real headaches and annoyances because you're not onsite to deal with the issue. I'm hoping that we can have a more reasonable default behavior to help scenarios like this. Thanks. |
I have that same issue ASSOC_LEAVE. I am wondering...
Because this is what I am thinking it could be the cause of the ASSOC_LEAVE. I am building a music player and reconnecting is not intresting. Could you give only that imput? Many thanks dave. |
Board
n/a
Device Description
n/a
Hardware Configuration
n/a
Version
v2.0.4
IDE Name
n/a
Operating System
n/a
Flash frequency
n/a
PSRAM enabled
yes
Upload speed
n/a
Description
WiFiSTAClass
has an _autoReconnect member, which defaults totrue
. WhenWiFiGeneric::_eventCallback()
handles aARDUINO_EVENT_WIFI_STA_DISCONNECTED
event, it checksWiFiSTAClass::getAutoReconnect()
and only reconnects if the following criteria is true:https://github.com/espressif/arduino-esp32/blob/2.0.4/libraries/WiFi/src/WiFiGeneric.cpp#L971
The code above excludes reasons such as
WIFI_REASON_ASSOC_EXPIRE
,WIFI_REASON_NOT_ASSOCED
,WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT
,WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT
and perhaps other reasons that may randomly occur.I propose that reconnection should occur for more than the reasons currently in the code above because of the following:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wifi-event-sta-disconnected
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-disconnect-phase
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-reconnect
https://github.com/espressif/esp-idf/blob/v4.4.2/examples/wifi/getting_started/station/main/station_example_main.c#L68
https://github.com/espressif/esp-idf/blob/v4.4.2/examples/provisioning/wifi_prov_mgr/main/app_main.c#L100
https://github.com/espressif/esp-jumpstart/blob/bf3e26f2295730c8f6e9e7c08c897d2155064c5c/7_mfg/main/app_wifi.c#L112
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: