Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit d64ce2d

Browse files
authored
v1.7.0 to fix the blocking issue in loop()
### 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
1 parent 0a4c722 commit d64ce2d

File tree

9 files changed

+279
-61
lines changed

9 files changed

+279
-61
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1414

1515
Please ensure to specify the following:
1616

17-
* Arduino IDE version (e.g. 1.8.16) or Platform.io version
18-
* `ESP8266` or `ESP32` Core Version (e.g. ESP8266 core v3.0.2 or ESP32 v2.0.1)
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18+
* `ESP8266` or `ESP32` Core Version (e.g. ESP8266 core v3.0.2 or ESP32 v2.0.2)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -26,10 +26,10 @@ Please ensure to specify the following:
2626
### Example
2727

2828
```
29-
Arduino IDE version: 1.8.16
29+
Arduino IDE version: 1.8.19
3030
ESP8266 Core Version 3.0.2
3131
OS: Ubuntu 20.04 LTS
32-
Linux Inspiron 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
32+
Linux Inspiron 5.4.0-92-generic #103-Ubuntu SMP Fri Nov 26 16:13:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
3333
3434
Context:
3535
The board couldn't autoreconnect to Local Blynk Server after router power recycling.

README.md

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
* [12.1 Enable auto-scan of WiFi networks for selection in Configuration Portal](#121-enable-auto-scan-of-wifi-networks-for-selection-in-configuration-portal)
4545
* [12.2 Disable manually input SSIDs](#122-disable-manually-input-ssids)
4646
* [12.3 Select maximum number of SSIDs in the list](#123-select-maximum-number-of-ssids-in-the-list)
47+
* [13. To avoid blocking in loop when WiFi is lost](#13-To-avoid-blocking-in-loop-when-wifi-is-lost)
48+
* [13.1 Max times to try WiFi per loop](#131-max-times-to-try-wifi-per-loop)
49+
* [13.2 Interval between reconnection WiFi if lost](#132-interval-between-reconnection-wifi-if-lost)
4750
* [Examples](#examples)
4851
* [ 1. ESP_WiFi](examples/ESP_WiFi)
4952
* [ 2. ESP_WiFi_MQTT](examples/ESP_WiFi_MQTT)
@@ -138,8 +141,8 @@ This [**ESP_WiFiManager_Lite** library](https://github.com/khoih-prog/ESP_WiFiMa
138141

139142
## Prerequisites
140143

141-
1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software)
142-
2. [`ESP32 Core 2.0.1+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
144+
1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software)
145+
2. [`ESP32 Core 2.0.2+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
143146
3. [`ESP8266 Core 3.0.2+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/). SPIFFS is deprecated from ESP8266 core 2.7.1+, to use LittleFS.
144147
4. [`ESP_DoubleResetDetector v1.2.1+`](https://github.com/khoih-prog/ESP_DoubleResetDetector) if using DRD feature. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector).
145148
5. [`ESP_MultiResetDetector v1.2.1+`](https://github.com/khoih-prog/ESP_MultiResetDetector) if using MRD feature. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_MultiResetDetector.svg?)](https://www.ardu-badge.com/ESP_MultiResetDetector).
@@ -470,6 +473,35 @@ The maximum number of SSIDs in the list is seletable from 2 to 15. If invalid nu
470473
#define MAX_SSID_IN_LIST 8
471474
```
472475
476+
#### 13. To avoid blocking in loop when WiFi is lost
477+
478+
#### 13.1 Max times to try WiFi per loop
479+
480+
To define max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
481+
482+
Default is 1 if not defined, and minimum is forced to be 1.
483+
484+
To use, uncomment in `defines.h`.
485+
486+
Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18#issue-1094004380)
487+
488+
```
489+
#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 2
490+
```
491+
492+
#### 13.2 Interval between reconnection WiFi if lost
493+
494+
Default is no interval between reconnection WiFi times if lost WiFi. Max permitted interval will be 10mins.
495+
496+
Uncomment to use. Be careful, WiFi reconnection will be delayed if using this method.
497+
498+
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.
499+
500+
Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18#issuecomment-1006197561)
501+
502+
```
503+
#define WIFI_RECON_INTERVAL 30000 // 30s
504+
```
473505
474506
---
475507
---
@@ -913,7 +945,10 @@ void loop()
913945

914946
// RTC Memory Address for the DoubleResetDetector to use
915947
#define MRD_ADDRESS 0
916-
#warning Using MULTI_RESETDETECTOR
948+
949+
#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
950+
#warning Using MULTI_RESETDETECTOR
951+
#endif
917952
#else
918953
#define DOUBLERESETDETECTOR_DEBUG true
919954

@@ -923,7 +958,10 @@ void loop()
923958

924959
// RTC Memory Address for the DoubleResetDetector to use
925960
#define DRD_ADDRESS 0
926-
#warning Using DOUBLE_RESETDETECTOR
961+
962+
#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
963+
#warning Using DOUBLE_RESETDETECTOR
964+
#endif
927965
#endif
928966

929967
/////////////////////////////////////////////
@@ -947,10 +985,6 @@ void loop()
947985

948986
/////////////////////////////////////////////
949987

950-
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
951-
// Default is false (if not defined) => must input 2 sets of SSID/PWD
952-
#define REQUIRE_ONE_SET_SSID_PW false
953-
954988
// Force some params
955989
#define TIMEOUT_RECONNECT_WIFI 10000L
956990

@@ -963,9 +997,32 @@ void loop()
963997
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
964998

965999
// Config Timeout 120s (default 60s). Applicable only if Config Data is Valid
966-
#define CONFIG_TIMEOUT 120000L
1000+
#define CONFIG_TIMEOUT 120000L
1001+
1002+
/////////////////////////////////////////////
1003+
1004+
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
1005+
// Default is false (if not defined) => must input 2 sets of SSID/PWD
1006+
#define REQUIRE_ONE_SET_SSID_PW true //false
1007+
1008+
// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
1009+
// Default 1 if not defined, and minimum 1.
1010+
#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 2
1011+
1012+
// Default no interval between recon WiFi if lost
1013+
// Max permitted interval will be 10mins
1014+
// Uncomment to use. Be careful, WiFi reconnect will be delayed if using this method
1015+
// 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.
1016+
//#define WIFI_RECON_INTERVAL 30000
1017+
1018+
/////////////////////////////////////////////
1019+
1020+
// Permit reset hardware if no WiFi to permit user another chance to access Config Portal.
1021+
#define RESET_IF_NO_WIFI false
1022+
1023+
/////////////////////////////////////////////
9671024

968-
#define USE_DYNAMIC_PARAMETERS true
1025+
#define USE_DYNAMIC_PARAMETERS true
9691026

9701027
/////////////////////////////////////////////
9711028

@@ -975,7 +1032,7 @@ void loop()
9751032
#define MANUAL_SSID_INPUT_ALLOWED true
9761033

9771034
// From 2-15
978-
#define MAX_SSID_IN_LIST 8
1035+
#define MAX_SSID_IN_LIST 8
9791036

9801037
/////////////////////////////////////////////
9811038

@@ -1171,7 +1228,7 @@ This is the terminal output when running [**ESP_WiFi**](examples/ESP_WiFi) examp
11711228

11721229
```
11731230
Starting ESP_WiFi using LittleFS on ESP32_DEV
1174-
ESP_WiFiManager_Lite v1.6.0
1231+
ESP_WiFiManager_Lite v1.7.0
11751232
ESP_MultiResetDetector v1.2.1
11761233
LittleFS Flag read = 0xFFFC0003
11771234
multiResetDetectorFlag = 0xFFFC0003
@@ -1242,7 +1299,7 @@ FFFFFFFFF
12421299

12431300
```
12441301
Starting ESP_WiFi using LittleFS on ESP32_DEV
1245-
ESP_WiFiManager_Lite v1.6.0
1302+
ESP_WiFiManager_Lite v1.7.0
12461303
ESP_MultiResetDetector v1.2.1
12471304
LittleFS Flag read = 0xFFFE0001
12481305
multiResetDetectorFlag = 0xFFFE0001
@@ -1314,7 +1371,7 @@ This is the terminal output when running [**ESP_WiFi_MQTT**](examples/ESP_WiFi_M
13141371

13151372
```
13161373
Starting ESP_WiFi_MQTT using LittleFS on ESP8266_NODEMCU
1317-
ESP_WiFiManager_Lite v1.6.0
1374+
ESP_WiFiManager_Lite v1.7.0
13181375
ESP_MultiResetDetector v1.2.1
13191376
LittleFS Flag read = 0xFFFE0001
13201377
multiResetDetectorFlag = 0xFFFE0001
@@ -1389,7 +1446,7 @@ NNN
13891446
13901447
13911448
Starting ESP_WiFi_MQTT using LittleFS on ESP8266_NODEMCU
1392-
ESP_WiFiManager_Lite v1.6.0
1449+
ESP_WiFiManager_Lite v1.7.0
13931450
ESP_MultiResetDetector v1.2.1
13941451
LittleFS Flag read = 0xFFFE0001
13951452
multiResetDetectorFlag = 0xFFFE0001
@@ -1481,7 +1538,7 @@ This is the terminal output when running [**ESP_WiFi_MQTT**](examples/ESP_WiFi_M
14811538

14821539
```
14831540
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV
1484-
ESP_WiFiManager_Lite v1.6.0
1541+
ESP_WiFiManager_Lite v1.7.0
14851542
ESP_MultiResetDetector v1.2.1
14861543
LittleFS Flag read = 0xFFFE0001
14871544
multiResetDetectorFlag = 0xFFFE0001
@@ -1594,7 +1651,7 @@ entry 0x4004c190
15941651
15951652
15961653
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV
1597-
ESP_WiFiManager_Lite v1.6.0
1654+
ESP_WiFiManager_Lite v1.7.0
15981655
ESP_MultiResetDetector v1.2.1
15991656
LittleFS Flag read = 0xFFFE0001
16001657
multiResetDetectorFlag = 0xFFFE0001
@@ -1696,7 +1753,7 @@ This is the terminal output when running [**ESP_WiFi_MQTT**](examples/ESP_WiFi_M
16961753

16971754
```
16981755
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV
1699-
ESP_WiFiManager_Lite v1.6.0
1756+
ESP_WiFiManager_Lite v1.7.0
17001757
ESP_MultiResetDetector v1.2.1
17011758
LittleFS Flag read = 0xFFFC0003
17021759
multiResetDetectorFlag = 0xFFFC0003
@@ -1724,7 +1781,7 @@ NNNN NNNNN NNNNN NNNNN NN[WML] h:UpdLittleFS
17241781

17251782
```
17261783
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV
1727-
ESP_WiFiManager_Lite v1.6.0
1784+
ESP_WiFiManager_Lite v1.7.0
17281785
ESP_MultiResetDetector v1.2.1
17291786
LittleFS Flag read = 0xFFFE0001
17301787
multiResetDetectorFlag = 0xFFFE0001
@@ -1780,7 +1837,7 @@ This is the terminal output when running [**ESP_WiFi**](examples/ESP_WiFi) examp
17801837

17811838
```
17821839
Starting ESP_WiFi_MQTT using LittleFS on ESP32_DEV
1783-
ESP_WiFiManager_Lite v1.6.0
1840+
ESP_WiFiManager_Lite v1.7.0
17841841
ESP_MultiResetDetector v1.2.1
17851842
LittleFS Flag read = 0xFFFC0003
17861843
multiResetDetectorFlag = 0xFFFC0003
@@ -1824,7 +1881,7 @@ N
18241881

18251882
```
18261883
Starting ESP_WiFi_MQTT using LittleFS on ESP32_DEV
1827-
ESP_WiFiManager_Lite v1.6.0
1884+
ESP_WiFiManager_Lite v1.7.0
18281885
ESP_MultiResetDetector v1.2.1
18291886
LittleFS Flag read = 0xFFFE0001
18301887
multiResetDetectorFlag = 0xFFFE0001
@@ -1935,6 +1992,8 @@ Submit issues to: [ESP_WiFiManager_Lite issues](https://github.com/khoih-prog/ES
19351992
23. Add support to **ESP32-C3 using EEPROM and SPIFFS**
19361993
24. Enable **scan of WiFi networks** for selection in Configuration Portal
19371994
25. Ready for ESP32 core v2.0.0+
1995+
26. Fix ESP8266 bug not easy to connect to Config Portal for ESP8266 core v3.0.0+
1996+
27. Fix the blocking issue in loop() with configurable `WIFI_RECON_INTERVAL`
19381997

19391998
---
19401999
---

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Release v1.7.0](#release-v170)
1516
* [Release v1.6.0](#release-v160)
1617
* [Release v1.5.1](#release-v151)
1718
* [Major Release v1.5.0](#major-release-v150)
@@ -26,6 +27,13 @@
2627

2728
## Changelog
2829

30+
### Release v1.7.0
31+
32+
1. Fix ESP8266 bug not easy to connect to Config Portal for ESP8266 core v3.0.0+
33+
2. Fix the blocking issue in loop(). Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18)
34+
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18#issuecomment-1006197561)
35+
4. Clean up
36+
2937
### Release v1.6.0
3038

3139
1. Auto detect ESP32 core and use either built-in LittleFS or [LITTLEFS](https://github.com/lorol/LITTLEFS) library.

examples/ESP_WiFi/defines.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333

3434
// RTC Memory Address for the DoubleResetDetector to use
3535
#define MRD_ADDRESS 0
36-
#warning Using MULTI_RESETDETECTOR
36+
37+
#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
38+
#warning Using MULTI_RESETDETECTOR
39+
#endif
3740
#else
3841
#define DOUBLERESETDETECTOR_DEBUG true
3942

@@ -43,7 +46,10 @@
4346

4447
// RTC Memory Address for the DoubleResetDetector to use
4548
#define DRD_ADDRESS 0
46-
#warning Using DOUBLE_RESETDETECTOR
49+
50+
#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
51+
#warning Using DOUBLE_RESETDETECTOR
52+
#endif
4753
#endif
4854

4955
/////////////////////////////////////////////
@@ -67,10 +73,6 @@
6773

6874
/////////////////////////////////////////////
6975

70-
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
71-
// Default is false (if not defined) => must input 2 sets of SSID/PWD
72-
#define REQUIRE_ONE_SET_SSID_PW false
73-
7476
// Force some params
7577
#define TIMEOUT_RECONNECT_WIFI 10000L
7678

@@ -83,9 +85,32 @@
8385
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
8486

8587
// Config Timeout 120s (default 60s). Applicable only if Config Data is Valid
86-
#define CONFIG_TIMEOUT 120000L
88+
#define CONFIG_TIMEOUT 120000L
89+
90+
/////////////////////////////////////////////
91+
92+
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
93+
// Default is false (if not defined) => must input 2 sets of SSID/PWD
94+
#define REQUIRE_ONE_SET_SSID_PW true //false
95+
96+
// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
97+
// Default 1 if not defined, and minimum 1.
98+
#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 2
99+
100+
// Default no interval between recon WiFi if lost
101+
// Max permitted interval will be 10mins
102+
// Uncomment to use. Be careful, WiFi reconnect will be delayed if using this method
103+
// 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.
104+
//#define WIFI_RECON_INTERVAL 30000
105+
106+
/////////////////////////////////////////////
107+
108+
// Permit reset hardware if no WiFi to permit user another chance to access Config Portal.
109+
#define RESET_IF_NO_WIFI false
110+
111+
/////////////////////////////////////////////
87112

88-
#define USE_DYNAMIC_PARAMETERS true
113+
#define USE_DYNAMIC_PARAMETERS true
89114

90115
/////////////////////////////////////////////
91116

examples/ESP_WiFi_MQTT/defines.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@
6767

6868
/////////////////////////////////////////////
6969

70-
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
71-
// Default is false (if not defined) => must input 2 sets of SSID/PWD
72-
#define REQUIRE_ONE_SET_SSID_PW false
73-
7470
// Force some params
7571
#define TIMEOUT_RECONNECT_WIFI 10000L
7672

@@ -83,9 +79,32 @@
8379
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
8480

8581
// Config Timeout 120s (default 60s). Applicable only if Config Data is Valid
86-
#define CONFIG_TIMEOUT 120000L
82+
#define CONFIG_TIMEOUT 120000L
83+
84+
/////////////////////////////////////////////
85+
86+
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
87+
// Default is false (if not defined) => must input 2 sets of SSID/PWD
88+
#define REQUIRE_ONE_SET_SSID_PW true //false
89+
90+
// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
91+
// Default 1 if not defined, and minimum 1.
92+
#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 2
93+
94+
// Default no interval between recon WiFi if lost
95+
// Max permitted interval will be 10mins
96+
// Uncomment to use. Be careful, WiFi reconnect will be delayed if using this method
97+
// 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.
98+
//#define WIFI_RECON_INTERVAL 30000
99+
100+
/////////////////////////////////////////////
101+
102+
// Permit reset hardware if no WiFi to permit user another chance to access Config Portal.
103+
#define RESET_IF_NO_WIFI false
104+
105+
/////////////////////////////////////////////
87106

88-
#define USE_DYNAMIC_PARAMETERS true
107+
#define USE_DYNAMIC_PARAMETERS true
89108

90109
/////////////////////////////////////////////
91110

0 commit comments

Comments
 (0)