Skip to content

ESP: WiFi: Fix (re)connection #89

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

Merged
merged 7 commits into from
Dec 1, 2022

Conversation

pennam
Copy link
Contributor

@pennam pennam commented Nov 24, 2022

Issue 1: i've got 2 ESP8266 boards and they are not able to connect to my WiFi with the current implementation: it looks like this delay is not enough to get the board connected.

WiFi.begin(_ssid, _pass);
delay(1000);

Solution: delay until the board is connected with a maximum timeout of 3s

#if defined(ARDUINO_ARCH_ESP8266)
    /* Wait connection otherwise board won't connect */
    unsigned long start = millis();
    while((WiFi.status() != WL_CONNECTED) && (millis() - start) < ESP_WIFI_CONNECTION_TIMEOUT) {
      delay(100);
    }
#endif

Issue 2: both my ESP8266 and ESP32 board are not alway reconneting to WiFi if connection drops (power off WiFi from the router)

Solution: moving WiFi.begin(_ssid, _pass); in CONNECTING status with a proper retry delay solves the issue for both boards

@pennam pennam requested review from aentinger and facchinm November 24, 2022 08:44
@pennam pennam changed the title Esp reconnect 2 ESP: WiFi: Fix (re)connection Nov 24, 2022
@github-actions
Copy link

Memory usage change @ 91f7345

Board flash % RAM for global variables %
arduino:mbed:envie_m7 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nicla:nicla_vision 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
esp32:esp32:esp32 💚 -32 - -32 -0.0 - -0.0 0 - 0 0.0 - 0.0
esp8266:esp8266:huzzah 🔺 +32 - +32 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/ConnectionHandlerDemo
flash
% examples/ConnectionHandlerDemo
RAM for global variables
%
arduino:mbed:envie_m7 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0
arduino:mbed_nicla:nicla_vision 0 0.0 0 0.0
arduino:samd:mkr1000 0 0.0 0 0.0
arduino:samd:mkrgsm1400 0 0.0 0 0.0
arduino:samd:mkrnb1500 0 0.0 0 0.0
arduino:samd:mkrwan1300 0 0.0 0 0.0
arduino:samd:mkrwan1310 0 0.0 0 0.0
arduino:samd:mkrwifi1010 0 0.0 0 0.0
arduino:samd:nano_33_iot 0 0.0 0 0.0
esp32:esp32:esp32 -32 -0.0 0 0.0
esp8266:esp8266:huzzah 32 0.0 0 0.0
Click for full report CSV
Board,examples/ConnectionHandlerDemo<br>flash,%,examples/ConnectionHandlerDemo<br>RAM for global variables,%
arduino:mbed:envie_m7,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0
arduino:mbed_nicla:nicla_vision,0,0.0,0,0.0
arduino:samd:mkr1000,0,0.0,0,0.0
arduino:samd:mkrgsm1400,0,0.0,0,0.0
arduino:samd:mkrnb1500,0,0.0,0,0.0
arduino:samd:mkrwan1300,0,0.0,0,0.0
arduino:samd:mkrwan1310,0,0.0,0,0.0
arduino:samd:mkrwifi1010,0,0.0,0,0.0
arduino:samd:nano_33_iot,0,0.0,0,0.0
esp32:esp32:esp32,-32,-0.0,0,0.0
esp8266:esp8266:huzzah,32,0.0,0,0.0

Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 ESP8266 was running some internal state machine too afaik. That's one of those problems of highly abstracted APIs like WiFi.begin() - you really don't know what's happening under the hood and how long it might take.

@pennam pennam merged commit 80f543c into arduino-libraries:master Dec 1, 2022
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants