arduino-libraries / Arduino_ConnectionHandler

GNU General Public License v3.0
97 stars 36 forks source link

ESP: WiFi: Fix (re)connection #89

Closed pennam closed 1 year ago

pennam commented 1 year ago

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

github-actions[bot] commented 1 year ago

Memory usage change @ 91f734574689818ad7653bcbcd26c4dfaae8509e

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 :green_heart: -32 - -32 -0.0 - -0.0 0 - 0 0.0 - 0.0
esp8266:esp8266:huzzah :small_red_triangle: +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
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 ```