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

Commit

Permalink
v1.7.0 to fix the blocking issue in loop()
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
khoih-prog authored Jan 9, 2022
1 parent c6b49bb commit c895470
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 114 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p

Please ensure to specify the following:

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

```
Arduino IDE version: 1.8.16
Arduino IDE version: 1.8.19
ESP8266 Core Version 3.0.2
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.4.0-92-generic #103-Ubuntu SMP Fri Nov 26 16:13:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Context:
The board couldn't autoreconnect to Local Blynk Server after router power recycling.
Expand Down
100 changes: 80 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
* [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)
* [12.2 Disable manually input SSIDs](#122-disable-manually-input-ssids)
* [12.3 Select maximum number of SSIDs in the list](#123-select-maximum-number-of-ssids-in-the-list)
* [13. To avoid blocking in loop when WiFi is lost](#13-To-avoid-blocking-in-loop-when-wifi-is-lost)
* [13.1 Max times to try WiFi per loop](#131-max-times-to-try-wifi-per-loop)
* [13.2 Interval between reconnection WiFi if lost](#132-interval-between-reconnection-wifi-if-lost)
* [Examples](#examples)
* [ 1. ESPAsync_WiFi](examples/ESPAsync_WiFi)
* [ 2. ESPAsync_WiFi_MQTT](examples/ESPAsync_WiFi_MQTT)
Expand Down Expand Up @@ -161,9 +164,9 @@ This [**ESPAsync_WiFiManager_Lite** library](https://github.com/khoih-prog/ESPAs

## Prerequisites

1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software)
1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software)
2. [`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/). To use ESP8266 core 2.7.1+ for LittleFS.
3. [`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/)
3. [`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/)
4. [`ESPAsyncWebServer v1.2.3+`](https://github.com/me-no-dev/ESPAsyncWebServer) for all ESP32/ESP8266-based boards.
5. [`ESPAsyncTCP v1.2.2+`](https://github.com/me-no-dev/ESPAsyncTCP) for ESP8266-based boards.
6. [`AsyncTCP v1.1.1+`](https://github.com/me-no-dev/AsyncTCP) for ESP32-based boards
Expand Down Expand Up @@ -494,6 +497,35 @@ The maximum number of SSIDs in the list is seletable from 2 to 15. If invalid nu
#define MAX_SSID_IN_LIST 8
```
#### 13. To avoid blocking in loop when WiFi is lost
#### 13.1 Max times to try WiFi per loop
To define max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
Default is 1 if not defined, and minimum is forced to be 1.
To use, uncomment in `defines.h`.
Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18#issue-1094004380)
```
#define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 2
```
#### 13.2 Interval between reconnection WiFi if lost
Default is no interval between reconnection WiFi times if lost WiFi. Max permitted interval will be 10mins.
Uncomment to use. Be careful, WiFi reconnection 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.
Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18#issuecomment-1006197561)
```
#define WIFI_RECON_INTERVAL 30000 // 30s
```
---
---
Expand Down Expand Up @@ -938,7 +970,10 @@ void loop()

// RTC Memory Address for the DoubleResetDetector to use
#define MRD_ADDRESS 0
#warning Using MULTI_RESETDETECTOR

#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
#warning Using MULTI_RESETDETECTOR
#endif
#else
#define DOUBLERESETDETECTOR_DEBUG true

Expand All @@ -948,7 +983,10 @@ void loop()

// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
#warning Using DOUBLE_RESETDETECTOR

#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
#warning Using DOUBLE_RESETDETECTOR
#endif
#endif

/////////////////////////////////////////////
Expand All @@ -972,10 +1010,6 @@ void loop()

/////////////////////////////////////////////

// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW false

// Force some params
#define TIMEOUT_RECONNECT_WIFI 10000L

Expand All @@ -988,9 +1022,32 @@ void loop()
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5

// Config Timeout 120s (default 60s). Applicable only if Config Data is Valid
#define CONFIG_TIMEOUT 120000L
#define CONFIG_TIMEOUT 120000L

/////////////////////////////////////////////

// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW true //false

// 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 30000

/////////////////////////////////////////////

// Permit reset hardware if no WiFi to permit user another chance to access Config Portal.
#define RESET_IF_NO_WIFI false

/////////////////////////////////////////////

#define USE_DYNAMIC_PARAMETERS true
#define USE_DYNAMIC_PARAMETERS true

/////////////////////////////////////////////

Expand Down Expand Up @@ -1196,7 +1253,7 @@ This is the terminal output when running [**ESPAsync_WiFi_MQTT**](examples/ESPAs

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1271,7 +1328,7 @@ NNN
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1363,7 +1420,7 @@ This is the terminal output when running [**ESPAsync_WiFi_MQTT**](examples/ESPAs

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP8266_NODEMCU
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1438,7 +1495,7 @@ NNN
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP8266_NODEMCU
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1529,7 +1586,7 @@ This is the terminal output when running [**ESPAsync_WiFi_MQTT**](examples/ESPAs

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32S2_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1642,7 +1699,7 @@ entry 0x4004c190
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32S2_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1745,7 +1802,7 @@ This is the terminal output when running [**ESPAsync_WiFi_MQTT**](examples/ESPAs

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32S2_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFC0003
multiResetDetectorFlag = 0xFFFC0003
Expand Down Expand Up @@ -1788,7 +1845,7 @@ entry 0x4004c190

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32S2_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -1844,7 +1901,7 @@ This is the terminal output when running [**ESPAsync_WiFi_MQTT**](examples/ESPAs

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFC0003
multiResetDetectorFlag = 0xFFFC0003
Expand Down Expand Up @@ -1889,7 +1946,7 @@ NNNN NNNNN NNNNN N

```
Starting ESPAsync_WiFi_MQTT using LittleFS on ESP32_DEV
ESPAsync_WiFiManager_Lite v1.6.0
ESPAsync_WiFiManager_Lite v1.7.0
ESP_MultiResetDetector v1.2.1
LittleFS Flag read = 0xFFFE0001
multiResetDetectorFlag = 0xFFFE0001
Expand Down Expand Up @@ -2000,6 +2057,9 @@ Submit issues to: [ESPAsync_WiFiManager_Lite issues](https://github.com/khoih-pr
20. Add support to **ESP32-C3 using EEPROM and SPIFFS**
21. Enable **scan of WiFi networks** for selection in Configuration Portal
22. Ready for ESP32 core v2.0.0+
23. Fix ESP8266 bug not easy to connect to Config Portal for ESP8266 core v3.0.0+
24. Fix the blocking issue in loop() with configurable `WIFI_RECON_INTERVAL`
25. Optimize library code by using `reference-passing` instead of `value-passing`

---
---
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Major Release v1.7.0](#major-release-v170)
* [Release v1.6.0](#release-v160)
* [Release v1.5.1](#release-v151)
* [Major Release v1.5.0](#major-release-v150)
Expand All @@ -27,6 +28,14 @@

## Changelog

### 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](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18)
3. Configurable `WIFI_RECON_INTERVAL`. Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18#issuecomment-1006197561)
4. Optimize library code by using `reference-passing` instead of `value-passing`
5. Clean up

### Release v1.6.0

1. Auto detect ESP32 core and use either built-in LittleFS or [LITTLEFS](https://github.com/lorol/LITTLEFS) library.
Expand Down
41 changes: 33 additions & 8 deletions examples/ESPAsync_WiFi/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

// RTC Memory Address for the DoubleResetDetector to use
#define MRD_ADDRESS 0
#warning Using MULTI_RESETDETECTOR

#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
#warning Using MULTI_RESETDETECTOR
#endif
#else
#define DOUBLERESETDETECTOR_DEBUG true

Expand All @@ -43,7 +46,10 @@

// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
#warning Using DOUBLE_RESETDETECTOR

#if (_ESP_WM_LITE_LOGLEVEL_ > 3)
#warning Using DOUBLE_RESETDETECTOR
#endif
#endif

/////////////////////////////////////////////
Expand All @@ -67,10 +73,6 @@

/////////////////////////////////////////////

// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW false

// Force some params
#define TIMEOUT_RECONNECT_WIFI 10000L

Expand All @@ -83,9 +85,32 @@
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5

// Config Timeout 120s (default 60s). Applicable only if Config Data is Valid
#define CONFIG_TIMEOUT 120000L
#define CONFIG_TIMEOUT 120000L

/////////////////////////////////////////////

// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW true //false

// 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 30000

/////////////////////////////////////////////

// Permit reset hardware if no WiFi to permit user another chance to access Config Portal.
#define RESET_IF_NO_WIFI false

/////////////////////////////////////////////

#define USE_DYNAMIC_PARAMETERS true
#define USE_DYNAMIC_PARAMETERS true

/////////////////////////////////////////////

Expand Down
Loading

0 comments on commit c895470

Please sign in to comment.