ferreira-igor / micropython-wifi_manager

WiFi Manager for ESP8266 and ESP32 using MicroPython.
MIT License
56 stars 26 forks source link

why the automatic disconnect #1

Closed CharlieAt closed 3 years ago

CharlieAt commented 3 years ago

the disconnect during init https://github.com/h1pn0z/micropython-wifi_manager/blob/f66fa39516499e6af9140a96ed9a33aa8282574a/wifi_manager.py#L30 It causes the isconnected() shortcut in check_connection() to fail each time, so that the wifi_scan is executed on each boot slowing things down. I have removed the disconnect and found it to work properly when moving between networks.

ferreira-igor commented 3 years ago

Hi @CharlieAt!

This is intentional. Both ESP8266 and ESP32 can automatically reconnect to the last WiFi network they were when the device is reseted, but it takes some time. In Tayfunulu library he solves this by adding a delay between the checks, but as I was testing my code, I notice that the connection time is not consistent. That caused the checks to sometimes fail and the web server to be initialized. By passing this command it slows down the connection at the beginning, but I would have to use a delay to wait for the ESP to reconnect, so I don't see a big diference, and by stopping the default behavior I have more control over the way my code works. And this is in the init because it's meant to be used only when the library object is created. After that, in case of a lost connection while the main program is running, the ESP will try to reconnect normally. Also, I want that the check_connection() could be used to test the connection in the main code, something like this:

while True: if check_connection():

main code here...

Hope to made myself clear, english is not my primary language.

CharlieAt commented 3 years ago

Hi @h1pn0z

I was currently testing on the ESP8266 and had not (yet) run into the delayed reconnect.

thanks for the explanation!