Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

retries block the main loop #18

Closed
tomtobback opened this issue Jan 5, 2022 · 5 comments
Closed

retries block the main loop #18

tomtobback opened this issue Jan 5, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@tomtobback
Copy link

tomtobback commented Jan 5, 2022

Thanks for the great work on this library. I have an issue that might not be a bug; in that case it would be a useful feature i think.

When the configured WiFi network becomes unavailable, retries are blocking the loop.

Steps to Reproduce

I'm using REQUIRE_ONE_SET_SSID_PW true, and i can configure a single SSID/PWD via the portal and it connects successfully. When i switch off my home AP, the wifimanager keeps trying to reconnect for about 25 seconds, then goes back to the loop but immediately tries again to reconnect, producing and endless loop of:

[WN] r:WLost.ReconW
[WN] Ignore invalid WiFi PW : index=1, PW=
[WN] con2WF:SSID=Cassiopeia,PW=***
[WN] Failed using index=0, retry_time=0
[WN] Failed using index=0, retry_time=0
[WN] con2WF:failed
[WN] r:Check&WLost

Expected behavior

My application requires the retries to occur only at a certain interval, to allow the main functions of the loop to continue to work even when the wifi connection is down (e.g. polling sensors and saving the data to SD to upload later). I have tried changing RETRY_TIMES_RECONNECT_WIFI but that does not accept lower than 2. Would it be possible to define an interval between retries, e.g. RETRY_RECONNECT_WIFI_INTERVAL in order to allow the application to run in between retries? Or can you suggest a workaround?

Also, i'm not seeing the behaviour described in the readme, where the Config Portal is reopened when both SSIDs fail. I set REQUIRE_ONE_SET_SSID_PW false and configure 2 SSIDs, and when they both become unavailable, the retries alternate but there is no countdown to the Config Portal.

Information

  • Arduino IDE 1.8.13
  • SAMD21G Industruino board
  • library version 1.4.1
@khoih-prog
Copy link
Owner

Hi @tomtobback

Thanks for using the library as well as your nice words.

This is definitely a necessary enhancement and I've already added / tested this new feature and will publish a new release soon. Any other enhancement you'd like to propose?

The library will be certainly better and better thanks to users like you.

Best Regards,

@khoih-prog khoih-prog added the enhancement New feature or request label Jan 5, 2022
khoih-prog added a commit that referenced this issue Jan 5, 2022
### Release v1.5.0

1. Fix the blocking issue in loop(). Check [retries block the main loop #18](#18)
2. Drop support to `AVR Mega`
3. Update `Packages' Patches`
@khoih-prog
Copy link
Owner

Hi @tomtobback

The new WiFiManager_NINA_Lite releases v1.5.0 has just been published.

Your contribution has been noted in Contributions and Thanks

Please test and see if there is any new issue. You can modify MAX_NUM_WIFI_RECON_TRIES_PER_LOOP in defined.h as necessary

// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
// Default 1 if not defined, and minimum 1.
//#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP     2

Release v1.5.0

  1. Fix the blocking issue in loop(). Check retries block the main loop #18
  2. Drop support to AVR Mega
  3. Update Packages' Patches

@tomtobback
Copy link
Author

Hi @khoih-prog many thanks for your prompt follow-up. Unfortunately it does not seem to fix my issue, sorry for the misunderstanding. My goal is to keep the main loop() going without any blocking in between reconnect retries. In my sensor application, i want to catch events (and save to SD), also when wifi is temporarily unavailable. So i would need to have the retries occur only at e.g. 10min intervals, with the loop() running normally (i.e. fast) during that interval. This already works when the Config Portal is active; that does not block the loop().
With the latest release i see this when my one configured SSID becomes unavailable (with Serial Monitor timestamps), and with a print("loop"); in the loop:

08:29:39.586 -> loop
08:29:39.620 -> loop
08:29:39.620 -> loop
08:29:39.653 -> loop
08:29:39.653 -> loop
08:29:39.653 -> loop
08:29:39.686 -> loop
08:29:39.686 -> loop
08:29:39.686 -> loop
08:29:39.719 -> loop
08:29:39.719 -> loop
08:29:39.719 -> loop
08:29:39.719 -> [WN] r:Check&WLost
08:29:39.719 -> [WN] r:WLost.ReconW
08:29:39.719 -> [WN] Ignore invalid WiFi PW : index=1, PW=
08:29:39.719 -> [WN] con2WF:SSID=Cassiopeia,PW=***
08:29:50.285 -> [WN] Failed using index=0, retry_time=0
08:29:50.285 -> [WN] con2WF:failed
08:29:50.319 -> loop
08:29:50.319 -> [WN] r:WLost.ReconW
08:29:50.319 -> [WN] Ignore invalid WiFi PW : index=1, PW=
08:29:50.319 -> [WN] con2WF:SSID=Cassiopeia,PW=***
08:30:00.875 -> [WN] Failed using index=0, retry_time=0
08:30:00.875 -> [WN] con2WF:failed
08:30:00.908 -> loop
08:30:00.908 -> [WN] r:Check&WLost
08:30:00.908 -> [WN] r:WLost.ReconW
08:30:00.908 -> [WN] Ignore invalid WiFi PW : index=1, PW=
08:30:00.908 -> [WN] con2WF:SSID=Cassiopeia,PW=***
08:30:11.454 -> [WN] Failed using index=0, retry_time=0
08:30:11.454 -> [WN] con2WF:failed
08:30:11.487 -> loop

In between the retries, the loop() only runs once, while my aim is to have it run at the usual high speed for a certain interval (e.g. 10min). My sensor application does not work when the loop runs only once per 10 seconds.

khoih-prog added a commit that referenced this issue Jan 6, 2022
### Major Release v1.6.0

1. Add support to RP2040-based boards, such as **NANO_RP2040_CONNECT**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
2. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](#18 (comment))
@khoih-prog
Copy link
Owner

Hi @tomtobback

Try the WiFiManager_NINA_Lite releases v1.6.0 and post the results here, OK or not.

You have to modify in defines.h as follows to have 10mins WIFI_RECON_INTERVAL

// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
// Default 1 if not defined, and minimum 1.
#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP     2

// Default no interval between recon WiFi if lost
// Max permitted interval will be 10mins
// Uncomment to use. Be careful, WiFi reconnect will be delayed if using this method
// Only use whenever urgent tasks in loop() can't be delayed. But if so, it's better you have to rewrite your code, e.g. using higher priority tasks.
#define WIFI_RECON_INTERVAL                   600000

New instructions are at 13. To avoid blocking in loop when WiFi is lost

Best Regards,


Major Release v1.6.0

  1. Add support to RP2040-based boards, such as NANO_RP2040_CONNECT, using Earle Philhower's arduino-pico core
  2. Configurable WIFI_RECON_INTERVAL. Check retries block the main loop #18

@tomtobback
Copy link
Author

Hi @khoih-prog - great, that works for me and hopefully others will also find it useful in similar cases. Many thanks.

khoih-prog added a commit to khoih-prog/WiFiManager_Generic_Lite that referenced this issue Jan 7, 2022
### Major Release v1.5.0

1. Add support to RP2040-based boards, such as **NANO_RP2040_CONNECT**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
4. Update `Packages' Patches`
khoih-prog added a commit to khoih-prog/WiFiManager_Portenta_H7_Lite that referenced this issue Jan 8, 2022
### Release v1.5.0

1. Workaround for core WiFi.status() bug, which does not detect WiFi lost.
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
4. Update `Packages' Patches`
khoih-prog added a commit to khoih-prog/WiFiManager_Portenta_H7_Lite that referenced this issue Jan 8, 2022
### Release v1.5.0

1. Workaround for core WiFi.status() bug, which does not detect WiFi lost.
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
4. Update `Packages' Patches`
khoih-prog added a commit to khoih-prog/ESP_WiFiManager_Lite that referenced this issue Jan 8, 2022
### Release v1.7.0

1. Fix ESP8266 bug not easy to connect to Config Portal for ESP8266 core v3.0.0+ 
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
4. Clean up
khoih-prog added a commit to khoih-prog/ESP_AT_WM_Lite that referenced this issue Jan 9, 2022
### Release v1.5.0

1. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
2. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
3. Update `Packages' Patches`
khoih-prog added a commit to khoih-prog/ESP_AT_WM_Lite that referenced this issue Jan 9, 2022
### Release v1.5.0

1. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
2. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
3. Update `Packages' Patches`
khoih-prog added a commit to khoih-prog/ESPAsync_WiFiManager_Lite that referenced this issue Jan 9, 2022
### Major Release v1.7.0

1. Fix ESP8266 bug not easy to connect to Config Portal for ESP8266 core v3.0.0+ 
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Clean up
khoih-prog added a commit to khoih-prog/ESPAsync_WiFiManager_Lite that referenced this issue Jan 9, 2022
### Major Release v1.7.0

1. Fix ESP8266 bug not easy to connect to Config Portal for ESP8266 core v3.0.0+ 
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](khoih-prog/WiFiManager_NINA_Lite#18 (comment))
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Clean up
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants