diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5147cc22..1b41c67b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -15,7 +15,7 @@ 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
-* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.5.2, etc.)
+* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.6.1, etc.)
* 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:
@@ -26,11 +26,11 @@ Please ensure to specify the following:
### Example
```
-Arduino IDE version: 1.8.16
-RASPBERRY_PI_PICO board
-ArduinoCore-mbed v2.5.2
+Arduino IDE version: 1.8.19
+Nano_RP2040_Connect board
+ArduinoCore-mbed v2.6.1
OS: Ubuntu 20.04 LTS
-Linux xy-Inspiron-3593 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 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.
diff --git a/README.md b/README.md
index 4a5c5ab5..677ca224 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@
* [8. For RP2040-based boards using Earle Philhower arduino-pico core](#8-for-rp2040-based-boards-using-earle-philhower-arduino-pico-core)
* [8.1. To use BOARD_NAME](#81-to-use-board_name)
* [8.2. To avoid compile error relating to microsecondsToClockCycles](#82-to-avoid-compile-error-relating-to-microsecondstoclockcycles)
- * [9. For Portenta_H7 boards using Arduino IDE in Linux](#9-for-portenta_h7-boards-using-arduino-ide-in-linux)
+ * [9. For Portenta_H7 boards using Arduino IDE in Linux](#9-for-portenta_h7-boards-using-arduino-ide-in-linux)
* [How It Works](#how-it-works)
* [How to use](#how-to-use)
* [ 1. Basic usage](#1-basic-usage)
@@ -57,6 +57,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. MKR1000_WiFi101](examples/MKR1000_WiFi101)
* [ 2. MKR1000_WiFi101_MQTT](examples/MKR1000_WiFi101_MQTT)
@@ -119,7 +122,7 @@ The LittleFS of the new **Nano_RP2040_Connect** board ( see [New board](pics/New
Check [**RP2040 Connect board has faulty components in newest purchase** #318](https://github.com/arduino/ArduinoCore-mbed/issues/318#) for more information of when and how the issue will be fixed.
-The old board ( see [Old board](pics/Old_Board.png) ), using Adesto Flash chip, is currently working with [`Arduino mbed_rp2040 core 2.4.1`](https://github.com/arduino/ArduinoCore-mbed/releases/tag/2.4.1).
+The old board ( see [Old board](pics/Old_Board.png) ), using Adesto Flash chip, is currently working with [`Arduino mbed_rp2040 core 2.4.1+`](https://github.com/arduino/ArduinoCore-mbed/releases/tag/2.4.1).
---
---
@@ -194,7 +197,7 @@ This [**WiFiManager_Generic_Lite** library](https://github.com/khoih-prog/WiFiMa
- Generic Flight Controllers
- Midatronics boards
- 7. RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed).
+ 7. RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed) or [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico).
8. RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Arduino-mbed RP2040** core](https://github.com/arduino/ArduinoCore-mbed) or [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico).
@@ -202,11 +205,11 @@ This [**WiFiManager_Generic_Lite** library](https://github.com/khoih-prog/WiFiMa
#### Currently supported WiFi shields/modules
-1. WiFiNINA using [`WiFiNINA_Generic library`](https://github.com/khoih-prog/WiFiNINA_Generic)
+1. WiFiNINA using [`WiFiNINA_Generic library v1.8.14-3+`](https://github.com/khoih-prog/WiFiNINA_Generic)
2. WiFi101 using [`WiFi101 library v0.16.1+`](https://github.com/arduino-libraries/WiFi101)
3. u-blox W101, W102 using [`WiFiNINA_Generic library`](https://github.com/khoih-prog/WiFiNINA_Generic)
-4. ESP826-AT command using [`WiFiEspAT library v1.3.0+`](https://github.com/jandrassy/WiFiEspAT)
-5. ESP8266/ESP32-AT command using [`ESP_AT_Lib library v1.0.0+`](https://github.com/khoih-prog/ESP_AT_Lib) and [`ESP8266_AT_WebServer`](ESP8266_AT_WebServer)
+4. ESP826-AT command using [`WiFiEspAT library v1.3.2+`](https://github.com/jandrassy/WiFiEspAT)
+5. ESP8266/ESP32-AT command using [`ESP_AT_Lib library v1.4.1+`](https://github.com/khoih-prog/ESP_AT_Lib) and [`ESP8266_AT_WebServer`](ESP8266_AT_WebServer)
---
@@ -214,23 +217,23 @@ This [**WiFiManager_Generic_Lite** library](https://github.com/khoih-prog/WiFiMa
## Prerequisites
- 1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software)
- 2. [`Arduino Core for STM32 v2.1.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32 boards. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest)
+ 1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software)
+ 2. [`Arduino Core for STM32 v2.2.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32 boards. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest)
3. [`Teensy core 1.55+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0, LC) boards
4. [`Arduino SAM DUE core 1.6.12+`](https://github.com/arduino/ArduinoCore-sam) for SAM DUE ARM Cortex-M3 boards
- 5. [`Arduino SAMD core 1.8.11+`](https://www.arduino.cc/en/Guide/ArduinoM0) for SAMD ARM Cortex-M0+ boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-samd.svg)](https://github.com/arduino/ArduinoCore-samd/releases/latest)
+ 5. [`Arduino SAMD core 1.8.12+`](https://www.arduino.cc/en/Guide/ArduinoM0) for SAMD ARM Cortex-M0+ boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-samd.svg)](https://github.com/arduino/ArduinoCore-samd/releases/latest)
6. [`Adafruit SAMD core 1.7.5+`](https://www.adafruit.com/) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [![GitHub release](https://img.shields.io/github/release/adafruit/ArduinoCore-samd.svg)](https://github.com/adafruit/ArduinoCore-samd/releases/latest)
7. [`Seeeduino SAMD core 1.8.2+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [![Latest release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-samd.svg)](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/)
- 8. [`Adafruit nRF52 v1.1.0+`](https://www.adafruit.com) for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, **NINA_B302_ublox**, etc. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest).
- 9. [`Arduino mbed_rp2040 core 2.5.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
-10. [`Earle Philhower's arduino-pico core v1.9.5+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
+ 8. [`Adafruit nRF52 v1.2.0+`](https://www.adafruit.com) for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, **NINA_B302_ublox**, etc. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest).
+ 9. [`Arduino mbed_rp2040 core 2.6.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
+10. [`Earle Philhower's arduino-pico core v1.9.13+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
11. [`Functional-VLPP library v1.0.2+`](https://github.com/khoih-prog/functional-vlpp) to use server's lambda function. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/Functional-Vlpp.svg?)](https://www.ardu-badge.com/Functional-Vlpp)
-12. [`WiFiNINA_Generic library v1.8.13+`](https://github.com/khoih-prog/WiFiNINA_Generic). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WiFiNINA_Generic.svg?)](https://www.ardu-badge.com/WiFiNINA_Generic)
-13. [`WiFiWebServer library v1.4.2+`](https://github.com/khoih-prog/WiFiWebServer). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WiFiWebServer.svg?)](https://www.ardu-badge.com/WiFiWebServer)
-14. [`ESP8266_AT_WebServer library v1.4.0+`](https://github.com/khoih-prog/ESP8266_AT_WebServer) to be able to support ESP32-AT shields. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP8266_AT_WebServer.svg?)](https://www.ardu-badge.com/ESP8266_AT_WebServer)
+12. [`WiFiNINA_Generic library v1.8.14-3+`](https://github.com/khoih-prog/WiFiNINA_Generic). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WiFiNINA_Generic.svg?)](https://www.ardu-badge.com/WiFiNINA_Generic)
+13. [`WiFiWebServer library v1.5.3+`](https://github.com/khoih-prog/WiFiWebServer). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WiFiWebServer.svg?)](https://www.ardu-badge.com/WiFiWebServer)
+14. [`ESP8266_AT_WebServer library v1.5.2+`](https://github.com/khoih-prog/ESP8266_AT_WebServer) to be able to support ESP32-AT shields. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP8266_AT_WebServer.svg?)](https://www.ardu-badge.com/ESP8266_AT_WebServer)
15. [`ESP_AT_Lib library v1.4.1+`](https://github.com/khoih-prog/ESP_AT_Lib) if using ESP8288/ESP32-AT shields. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_AT_Lib.svg?)](https://www.ardu-badge.com/ESP_AT_Lib).
16. [`Modified WiFi101 Library v0.16.1+`](https://github.com/khoih-prog/WiFi101) to use SAMD MKR1000, etc. boards with WiFi101.
-17. [`WiFiEspAT library v1.3.1+`](https://github.com/jandrassy/WiFiEspAT) if using ESP8288/ESP32-AT shields. [![GitHub release](https://img.shields.io/github/release/jandrassy/WiFiEspAT.svg)](https://github.com/jandrassy/WiFiEspAT/releases/latest)
+17. [`WiFiEspAT library v1.3.2+`](https://github.com/jandrassy/WiFiEspAT) if using ESP8288/ESP32-AT shields. [![GitHub release](https://img.shields.io/github/release/jandrassy/WiFiEspAT.svg)](https://github.com/jandrassy/WiFiEspAT/releases/latest)
18. [`FlashStorage_SAMD library v1.2.1+`](https://github.com/khoih-prog/FlashStorage_SAMD) for SAMD21 and SAMD51 boards (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit Itsy-Bitsy M4, etc.). [![GitHub release](https://img.shields.io/github/release/khoih-prog/FlashStorage_SAMD.svg)](https://github.com/khoih-prog/FlashStorage_SAMD/releases/latest)
19. [`FlashStorage_STM32 library v1.1.0+`](https://github.com/khoih-prog/FlashStorage_STM32) for STM32F/L/H/G/WB/MP1 boards. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/FlashStorage_STM32.svg?)](https://www.ardu-badge.com/FlashStorage_STM32)
20. [`DueFlashStorage library v1.0.0+`](https://github.com/sebnil/DueFlashStorage) for SAM DUE. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/DueFlashStorage.svg?)](https://www.ardu-badge.com/DueFlashStorage)
@@ -268,19 +271,19 @@ You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/
#### 1. For Adafruit nRF52840 and nRF52832 boards
-**To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards**, you have to copy the whole [nRF52 Packages_Patches](Packages_Patches/adafruit/hardware/nrf52/1.1.0) directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0).
+**To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards**, you have to copy the whole [nRF52 Packages_Patches](Packages_Patches/adafruit/hardware/nrf52/1.2.0) directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0).
-Supposing the Adafruit nRF52 version is 1.1.0. These files must be copied into the directory:
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/platform.txt`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/boards.txt`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Udp.h`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Print.h`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Print.cpp`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B302_ublox/variant.h`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B302_ublox/variant.cpp`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B112_ublox/variant.h`
-- `~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B112_ublox/variant.cpp`
-- **`~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Udp.h`**
+Supposing the Adafruit nRF52 version is 1.2.0. These files must be copied into the directory:
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/platform.txt`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/boards.txt`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/cores/nRF5/Udp.h`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/cores/nRF5/Print.h`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/cores/nRF5/Print.cpp`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/variants/NINA_B302_ublox/variant.h`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/variants/NINA_B302_ublox/variant.cpp`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/variants/NINA_B112_ublox/variant.h`
+- `~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/variants/NINA_B112_ublox/variant.cpp`
+- **`~/.arduino15/packages/adafruit/hardware/nrf52/1.2.0/cores/nRF5/Udp.h`**
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z
These files must be copied into the directory:
@@ -298,14 +301,14 @@ These files must be copied into the directory:
#### 2. For Teensy boards
- **To be able to compile and run on Teensy boards**, you have to copy the files in [**Packages_Patches for Teensy directory**](Packages_Patches/hardware/teensy/avr) into Teensy hardware directory (./arduino-1.8.15/hardware/teensy/avr/boards.txt).
+ **To be able to compile and run on Teensy boards**, you have to copy the files in [**Packages_Patches for Teensy directory**](Packages_Patches/hardware/teensy/avr) into Teensy hardware directory (./arduino-1.8.19/hardware/teensy/avr/boards.txt).
-Supposing the Arduino version is 1.8.15. These files must be copied into the directory:
+Supposing the Arduino version is 1.8.19. These files must be copied into the directory:
-- `./arduino-1.8.15/hardware/teensy/avr/boards.txt`
-- `./arduino-1.8.15/hardware/teensy/avr/cores/teensy/Stream.h`
-- `./arduino-1.8.15/hardware/teensy/avr/cores/teensy3/Stream.h`
-- `./arduino-1.8.15/hardware/teensy/avr/cores/teensy4/Stream.h`
+- `./arduino-1.8.19/hardware/teensy/avr/boards.txt`
+- `./arduino-1.8.19/hardware/teensy/avr/cores/teensy/Stream.h`
+- `./arduino-1.8.19/hardware/teensy/avr/cores/teensy3/Stream.h`
+- `./arduino-1.8.19/hardware/teensy/avr/cores/teensy4/Stream.h`
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
These files must be copied into the directory:
@@ -413,12 +416,12 @@ To use LAN8720 on some STM32 boards
- **Discovery (DISCO_F746NG)**
- **STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)**
-you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.1.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.1.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system) to overwrite the old files.
+you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files.
-Supposing the STM32 stm32 core version is 2.1.0. These files must be copied into the directory:
+Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory:
-- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4.
-- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7.
+- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4.
+- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7.
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz,
theses files must be copied into the corresponding directory:
@@ -429,12 +432,12 @@ theses files must be copied into the corresponding directory:
#### 7.2 For STM32 boards to use Serial1
-**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.1.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.1.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.
+**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.2.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.
-Supposing the STM32 stm32 core version is 2.1.0. These files must be copied into the directory:
+Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory:
-- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI.
-- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8.
+- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI.
+- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8.
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz,
theses files must be copied into the corresponding directory:
@@ -477,12 +480,12 @@ With core after v1.5.0, this step is not necessary anymore thanks to the PR [Add
#### 9. For Portenta_H7 boards using Arduino IDE in Linux
- **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/2.5.2/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/2.5.2/portenta_post_install.sh).
+ **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/2.6.1/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/portenta_post_install.sh).
Then run the following command using `sudo`
```
-$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.5.2
+$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh
```
@@ -495,9 +498,9 @@ This will create the file `/etc/udev/rules.d/49-portenta_h7.rules` as follows:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
```
-Supposing the ArduinoCore-mbed core version is 2.5.2. Now only one file must be copied into the directory:
+Supposing the ArduinoCore-mbed core version is 2.6.1. Now only one file must be copied into the directory:
-- `~/.arduino15/packages/arduino/hardware/mbed_portenta/2.5.2/portenta_post_install.sh`
+- `~/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/portenta_post_install.sh`
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
@@ -740,6 +743,37 @@ The maximum number of SSIDs in the list is selectable from 2 to 15 (for ESP8266/
#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
+```
+
---
---
@@ -1179,7 +1213,7 @@ void loop()
#define DEBUG_WIFI_WEBSERVER_PORT Serial
#define WIFI_GENERIC_DEBUG_OUTPUT Serial
-#define _WIFI_GENERIC_LOGLEVEL_ 1
+#define _WIFI_GENERIC_LOGLEVEL_ 4
#define DRD_GENERIC_DEBUG true
@@ -1388,7 +1422,19 @@ 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
@@ -1595,7 +1641,7 @@ This is the terminal output when running [**SAMD_WiFi**](examples/SAMD_WiFi) exa
```
Start SAMD_WiFi on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[WG] Hostname=SAMD-Master-Controller
Flag read = 0xffffffff
No doubleResetDetected
@@ -1696,7 +1742,7 @@ FFFFFFFFF
```
Start SAMD_WiFi on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[WG] Hostname=SAMD-Master-Controller
Flag read = 0xd0d04321
No doubleResetDetected
@@ -1760,7 +1806,7 @@ HHHHHHHHHH HHHHHHHHHH
```
Start SAMD_WiFi on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[WG] Hostname=SAMD-Master-Controller
Flag read = 0xd0d04321
No doubleResetDetected
@@ -1824,7 +1870,7 @@ FF
```
Start SAMD_WiFi on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[WG] Hostname=SAMD-Master-Controller
Flag read = 0xd0d04321
No doubleResetDetected
@@ -1880,7 +1926,7 @@ HHHHHHHHH HHHHHHHHHH
```
Start SAMD_WiFi on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[WG] Hostname=SAMD-Master-Controller
Flag read = 0xd0d01234
doubleResetDetected
@@ -1941,7 +1987,7 @@ This is the terminal output when running [**SAMD_WiFi**](examples/SAMD_WiFi) exa
```
Start SAMD_WiFi on ITSYBITSY_M4 with Custom using Custom WiFi Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[ESP_AT] Use ES8266-AT Command
WiFi shield init done
[WG] Hostname=SAMD-Master-Controller
@@ -1980,7 +2026,7 @@ F
```
Start SAMD_WiFi on ITSYBITSY_M4 with Custom using Custom WiFi Library
-WiFiManager_Generic_Lite v1.4.1
+WiFiManager_Generic_Lite v1.5.0
[ESP_AT] Use ES8266-AT Command
WiFi shield init done
[WG] Hostname=SAMD-Master-Controller
@@ -2081,6 +2127,9 @@ Submit issues to: [WiFiManager_Generic_Lite issues](https://github.com/khoih-pro
27. Add support to RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico).
28. Add support to RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Arduino-mbed RP2040** core](https://github.com/arduino/ArduinoCore-mbed)
29. Add `LibraryPatches` for [**Adafruit_MQTT_Library**](https://github.com/adafruit/Adafruit_MQTT_Library) to fix compiler error for RP2040-based and many other boards.
+30. Add support to **Arduino Nano RP2040 Connect** using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico).
+31. Fix the blocking issue in loop() with configurable `WIFI_RECON_INTERVAL`
+
---
---
@@ -2095,12 +2144,13 @@ Please help contribute to this project and add your name here.
- [WiFiManager connection attempt to unconfigured ("blank") SSID after restart on SAMD #8](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/8) leading to v1.1.3 and v1.2.0
3. Again thanks to [Michael H. "bizprof"](https://github.com/bizprof) to be `collaborator, co-author/maintainer` of this library. With the impressive new feature :
- `Enable scan of WiFi networks for selection in Configuration Portal`. Check [PR for v1.3.0 - Enable scan of WiFi networks #10](https://github.com/khoih-prog/WiFiManager_NINA_Lite/pull/10) leading to v1.3.0
-
+4. Thanks to [tomtobback](https://github.com/tomtobback) to report issue [retries block the main loop #18](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/18) leading to version v1.5.0 to fix the blocking issue in loop() with `WIFI_RECON_INTERVAL`.
diff --git a/changelog.md b/changelog.md
index bad24f45..0a28570f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -12,6 +12,7 @@
## Table of Contents
* [Changelog](#changelog)
+ * [Major Release v1.5.0](#major-release-v150)
* [Release v1.4.1](#release-v141)
* [Major Release v1.4.0](#major-release-v140)
* [Major Release v1.3.0](#major-release-v130)
@@ -29,6 +30,13 @@
## Changelog
+### 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](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. Update `Packages' Patches`
+
### Release v1.4.1
1. Update `platform.ini` and `library.json` to use original `khoih-prog` instead of `khoih.prog` after PIO fix
diff --git a/examples/MKR1000_WiFi101/defines.h b/examples/MKR1000_WiFi101/defines.h
index 1bae1b6a..78bc9640 100644
--- a/examples/MKR1000_WiFi101/defines.h
+++ b/examples/MKR1000_WiFi101/defines.h
@@ -89,9 +89,21 @@
// 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
+#define REQUIRE_ONE_SET_SSID_PW true //false
-#define USE_DYNAMIC_PARAMETERS true
+// 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
+
+/////////////////////////////////////////////
+
+#define USE_DYNAMIC_PARAMETERS true
/////////////////////////////////////////////
diff --git a/examples/MKR1000_WiFi101_MQTT/defines.h b/examples/MKR1000_WiFi101_MQTT/defines.h
index 7e3766d2..c9787c21 100644
--- a/examples/MKR1000_WiFi101_MQTT/defines.h
+++ b/examples/MKR1000_WiFi101_MQTT/defines.h
@@ -89,9 +89,21 @@
// 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
+#define REQUIRE_ONE_SET_SSID_PW true //false
-#define USE_DYNAMIC_PARAMETERS true
+// 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
+
+/////////////////////////////////////////////
+
+#define USE_DYNAMIC_PARAMETERS true
/////////////////////////////////////////////
diff --git a/examples/RP2040_WiFi/defines.h b/examples/RP2040_WiFi/defines.h
index 0f036bb0..f4869342 100644
--- a/examples/RP2040_WiFi/defines.h
+++ b/examples/RP2040_WiFi/defines.h
@@ -143,7 +143,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/RP2040_WiFi_MQTT/defines.h b/examples/RP2040_WiFi_MQTT/defines.h
index a2f24a78..08973991 100644
--- a/examples/RP2040_WiFi_MQTT/defines.h
+++ b/examples/RP2040_WiFi_MQTT/defines.h
@@ -150,7 +150,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/SAMD_WiFi/defines.h b/examples/SAMD_WiFi/defines.h
index e44598a3..36a04d12 100644
--- a/examples/SAMD_WiFi/defines.h
+++ b/examples/SAMD_WiFi/defines.h
@@ -226,7 +226,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/SAMD_WiFi_MQTT/defines.h b/examples/SAMD_WiFi_MQTT/defines.h
index b948a5c5..dfaef28d 100644
--- a/examples/SAMD_WiFi_MQTT/defines.h
+++ b/examples/SAMD_WiFi_MQTT/defines.h
@@ -242,7 +242,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/SAM_DUE_WiFi/defines.h b/examples/SAM_DUE_WiFi/defines.h
index 53784cf7..fe5c6b0d 100644
--- a/examples/SAM_DUE_WiFi/defines.h
+++ b/examples/SAM_DUE_WiFi/defines.h
@@ -142,7 +142,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/SAM_DUE_WiFi_MQTT/defines.h b/examples/SAM_DUE_WiFi_MQTT/defines.h
index 7e3980d5..705d83e8 100644
--- a/examples/SAM_DUE_WiFi_MQTT/defines.h
+++ b/examples/SAM_DUE_WiFi_MQTT/defines.h
@@ -143,7 +143,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/STM32_WiFi/defines.h b/examples/STM32_WiFi/defines.h
index d353bde5..a978852a 100644
--- a/examples/STM32_WiFi/defines.h
+++ b/examples/STM32_WiFi/defines.h
@@ -205,7 +205,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/STM32_WiFi_MQTT/defines.h b/examples/STM32_WiFi_MQTT/defines.h
index a4e35e1c..f9ef55af 100644
--- a/examples/STM32_WiFi_MQTT/defines.h
+++ b/examples/STM32_WiFi_MQTT/defines.h
@@ -206,7 +206,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/Teensy_WiFi/defines.h b/examples/Teensy_WiFi/defines.h
index 5cf1e9ff..a424672a 100644
--- a/examples/Teensy_WiFi/defines.h
+++ b/examples/Teensy_WiFi/defines.h
@@ -154,7 +154,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/Teensy_WiFi_MQTT/defines.h b/examples/Teensy_WiFi_MQTT/defines.h
index 0d9fb63c..ad37de80 100644
--- a/examples/Teensy_WiFi_MQTT/defines.h
+++ b/examples/Teensy_WiFi_MQTT/defines.h
@@ -155,7 +155,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/nRF52_WiFi/defines.h b/examples/nRF52_WiFi/defines.h
index 7f7bf6eb..d448d6eb 100644
--- a/examples/nRF52_WiFi/defines.h
+++ b/examples/nRF52_WiFi/defines.h
@@ -162,7 +162,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/examples/nRF52_WiFi_MQTT/defines.h b/examples/nRF52_WiFi_MQTT/defines.h
index 809e56d3..0c6865f9 100644
--- a/examples/nRF52_WiFi_MQTT/defines.h
+++ b/examples/nRF52_WiFi_MQTT/defines.h
@@ -161,7 +161,19 @@
// 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
+#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
+
+/////////////////////////////////////////////
#define USE_DYNAMIC_PARAMETERS true
diff --git a/library.json b/library.json
index efa08a01..0c7eaf8d 100644
--- a/library.json
+++ b/library.json
@@ -1,6 +1,6 @@
{
"name": "WiFiManager_Generic_Lite",
- "version": "1.4.1",
+ "version": "1.5.0",
"keywords": "wifi, multi-wifi, WiFiNINA, WiFi101, ESP32-AT, ESP8266-AT, Teensy, SAM-DUE, SAMD, STM32, nRF52, rpi-pico, rp2040, nano-rp2040-connect, config-portal, Double-Reset, dynamic-params, LittleFS, FlashStorage-SAMD, FlashStorage-STM32, Credentials, wi-fi, FlashStorage",
"description": "Library to configure MultiWiFi/Credentials at runtime for Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52, RP2040-based (Nano RP2040 Connect, RASPBERRY_PI_PICO) boards, etc. using Generic WiFi (WiFiNINA, WiFi101, ESP8266-AT, ESP32-AT, etc.) modules/shields. You can also specify DHCP HostName, static AP and STA IP. Use much less memory compared to full-fledge WiFiManager. Config Portal will be auto-adjusted to match the number of dynamic custom parameters. Optional default Credentials to be autoloaded into Config Portal to use or change instead of manually input. Credentials are saved in LittleFS/InternalFS, (emulated-)EEPROM, FlashStorage_SAMD, FlashStorage_STM32 or DueFlashStorage. New powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. DoubleDetectDetector as well as Virtual Switches feature permits entering Config Portal as requested.",
"authors":
@@ -27,7 +27,7 @@
{
"owner": "khoih-prog",
"name": "WiFiNINA_Generic",
- "version": "^1.8.13",
+ "version": "^1.8.14-3",
"platforms": ["*"]
},
{
@@ -57,13 +57,13 @@
{
"owner": "khoih-prog",
"name": "WiFiWebServer",
- "version": "^1.4.1",
+ "version": "^1.5.3",
"platforms": ["*"]
},
{
"owner": "khoih-prog",
"name": "ESP8266_AT_WebServer",
- "version": "^1.4.0",
+ "version": "^1.5.2",
"platforms": ["*"]
},
{
diff --git a/library.properties b/library.properties
index 67a8b92f..141ee703 100644
--- a/library.properties
+++ b/library.properties
@@ -1,5 +1,5 @@
name=WiFiManager_Generic_Lite
-version=1.4.1
+version=1.5.0
author=Khoi Hoang
maintainer=Khoi Hoang
license=MIT
diff --git a/platformio/platformio.ini b/platformio/platformio.ini
index cae17eba..0aff819c 100644
--- a/platformio/platformio.ini
+++ b/platformio/platformio.ini
@@ -38,23 +38,23 @@ lib_compat_mode = strict
lib_deps =
; PlatformIO 4.x
- WiFiNINA_Generic@>=1.8.13
- WiFiWebServer@>=1.4.2
- ESP8266_AT_WebServer@>=1.4.0
- Functional-Vlpp@>=1.0.2
- DoubleResetDetector_Generic@>=1.7.3
- FlashStorage_SAMD@>=1.2.1
- FlashStorage_STM32@>=1.1.0
- https://github.com/khoih-prog/WiFi101
+; WiFiNINA_Generic@>=1.8.14-3
+; WiFiWebServer@>=1.5.3
+; ESP8266_AT_WebServer@>=1.5.2
+; Functional-Vlpp@>=1.0.2
+; DoubleResetDetector_Generic@>=1.7.3
+; FlashStorage_SAMD@>=1.2.1
+; FlashStorage_STM32@>=1.1.0
+; https://github.com/khoih-prog/WiFi101
; PlatformIO 5.x
-; khoih-prog/WiFiNINA_Generic@>=1.8.13
-; khoih-prog/WiFiWebServer@>=1.4.2
-; khoih-prog/ESP8266_AT_WebServer@>=1.4.0
-; khoih-prog/Functional-Vlpp@>=1.0.2
-; khoih-prog/DoubleResetDetector_Generic@>=1.7.3
-; khoih-prog/FlashStorage_SAMD@>=1.2.1
-; khoih-prog/FlashStorage_STM32@>=1.1.0
-; https://github.com/khoih-prog/WiFi101
+ khoih-prog/WiFiNINA_Generic@>=1.8.14-3
+ khoih-prog/WiFiWebServer@>=1.5.3
+ khoih-prog/ESP8266_AT_WebServer@>=1.5.2
+ khoih-prog/Functional-Vlpp@>=1.0.2
+ khoih-prog/DoubleResetDetector_Generic@>=1.7.3
+ khoih-prog/FlashStorage_SAMD@>=1.2.1
+ khoih-prog/FlashStorage_STM32@>=1.1.0
+ https://github.com/khoih-prog/WiFi101
build_flags =
; set your debug output (default=Serial)
diff --git a/src/WiFiManager_Generic_Lite_DUE.h b/src/WiFiManager_Generic_Lite_DUE.h
index b8622e1b..3d55ce05 100644
--- a/src/WiFiManager_Generic_Lite_DUE.h
+++ b/src/WiFiManager_Generic_Lite_DUE.h
@@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -22,7 +22,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_DUE_h
@@ -38,7 +39,7 @@
#error This code is intended to run on the SAM DUE platform! Please check your Tools->Board setting.
#endif
-#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.4.1"
+#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.5.0"
#if (USE_WIFI_NINA || USE_WIFI101)
#include
@@ -436,6 +437,16 @@ class WiFiManager_Generic_Lite
#endif
#endif
+#if !defined(WIFI_RECON_INTERVAL)
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
+#else
+ #if (WIFI_RECON_INTERVAL < 0)
+ #define WIFI_RECON_INTERVAL 0
+ #elif (WIFI_RECON_INTERVAL > 600000)
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
+ #endif
+#endif
+
void run()
{
static int retryTimes = 0;
@@ -447,6 +458,10 @@ class WiFiManager_Generic_Lite
static unsigned long checkstatus_timeout = 0;
#define WIFI_STATUS_CHECK_INTERVAL 5000L
+ static uint32_t curMillis;
+
+ curMillis = millis();
+
//// New DRD ////
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
@@ -455,7 +470,7 @@ class WiFiManager_Generic_Lite
drd->loop();
//// New DRD ////
- if ( !configuration_mode && (millis() > checkstatus_timeout) )
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
{
if (WiFi.status() == WL_CONNECTED)
{
@@ -475,7 +490,7 @@ class WiFiManager_Generic_Lite
}
}
- checkstatus_timeout = millis() + WIFI_STATUS_CHECK_INTERVAL;
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
}
// Lost connection in running. Give chance to reconfig.
@@ -516,12 +531,31 @@ class WiFiManager_Generic_Lite
// Not in config mode, try reconnecting before forcing to config mode
if ( !wifi_connected )
{
+
+
+#if (WIFI_RECON_INTERVAL > 0)
+
+ static uint32_t lastMillis = 0;
+
+ if ( (lastMillis == 0) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
+ {
+ lastMillis = curMillis;
+
+ WG_LOGERROR(F("r:WLost.ReconW"));
+
+ if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
+ {
+ WG_LOGERROR(F("r:WOK"));
+ }
+ }
+#else
WG_LOGERROR(F("r:WLost.ReconW"));
if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
{
WG_LOGERROR(F("r:WOK"));
}
+#endif
}
}
}
@@ -1387,6 +1421,16 @@ class WiFiManager_Generic_Lite
//////////////////////////////////////////////
+// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
+// Default 1 and minimum 1.
+#if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+#else
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+ #endif
+#endif
+
// New connection logic from v1.2.0
bool connectMultiWiFi(int retry_time)
{
@@ -1446,7 +1490,9 @@ class WiFiManager_Generic_Lite
uint8_t numIndexTried = 0;
- while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) )
+ uint8_t numWiFiReconTries = 0;
+
+ while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
{
while ( 0 < retry_time )
{
diff --git a/src/WiFiManager_Generic_Lite_Debug.h b/src/WiFiManager_Generic_Lite_Debug.h
index 15439d12..f223b531 100644
--- a/src/WiFiManager_Generic_Lite_Debug.h
+++ b/src/WiFiManager_Generic_Lite_Debug.h
@@ -9,7 +9,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -23,7 +23,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_Debug_h
diff --git a/src/WiFiManager_Generic_Lite_RP2040.h b/src/WiFiManager_Generic_Lite_RP2040.h
index 865bf338..7efb5b8e 100644
--- a/src/WiFiManager_Generic_Lite_RP2040.h
+++ b/src/WiFiManager_Generic_Lite_RP2040.h
@@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -22,7 +22,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_RP2040_h
@@ -38,7 +39,7 @@
#error This code is intended to run on the RP2040 platform! Please check your Tools->Board setting.
#endif
-#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.4.1"
+#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.5.0"
#if (USE_WIFI_NINA || USE_WIFI101)
#include
@@ -438,6 +439,16 @@ class WiFiManager_Generic_Lite
#endif
#endif
+#if !defined(WIFI_RECON_INTERVAL)
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
+#else
+ #if (WIFI_RECON_INTERVAL < 0)
+ #define WIFI_RECON_INTERVAL 0
+ #elif (WIFI_RECON_INTERVAL > 600000)
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
+ #endif
+#endif
+
void run()
{
static int retryTimes = 0;
@@ -449,6 +460,10 @@ class WiFiManager_Generic_Lite
static unsigned long checkstatus_timeout = 0;
#define WIFI_STATUS_CHECK_INTERVAL 5000L
+ static uint32_t curMillis;
+
+ curMillis = millis();
+
//// New DRD ////
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
@@ -457,7 +472,7 @@ class WiFiManager_Generic_Lite
drd->loop();
//// New DRD ////
- if ( !configuration_mode && (millis() > checkstatus_timeout) )
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
{
if (WiFi.status() == WL_CONNECTED)
{
@@ -477,7 +492,7 @@ class WiFiManager_Generic_Lite
}
}
- checkstatus_timeout = millis() + WIFI_STATUS_CHECK_INTERVAL;
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
}
// Lost connection in running. Give chance to reconfig.
@@ -518,12 +533,31 @@ class WiFiManager_Generic_Lite
// Not in config mode, try reconnecting before forcing to config mode
if ( !wifi_connected )
{
+
+
+#if (WIFI_RECON_INTERVAL > 0)
+
+ static uint32_t lastMillis = 0;
+
+ if ( (lastMillis == 0) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
+ {
+ lastMillis = curMillis;
+
+ WG_LOGERROR(F("r:WLost.ReconW"));
+
+ if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
+ {
+ WG_LOGERROR(F("r:WOK"));
+ }
+ }
+#else
WG_LOGERROR(F("r:WLost.ReconW"));
if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
{
WG_LOGERROR(F("r:WOK"));
}
+#endif
}
}
}
@@ -533,7 +567,7 @@ class WiFiManager_Generic_Lite
WG_LOGERROR(F("r:gotWBack"));
}
}
-
+
//////////////////////////////////////////////
void setHostname()
@@ -942,7 +976,11 @@ class WiFiManager_Generic_Lite
#define CONFIG_PORTAL_FILENAME_BACKUP ("/fs/wm_cp.bak")
//////////////////////////////////////////////
-
+
+#if defined(ARDUINO_ARCH_MBED)
+ #warning Using Arduino-mbed core
+ // For boards using Arduino-mbed core
+
void saveForcedCP(uint32_t value)
{
// Mbed RP2040 code
@@ -1326,63 +1364,6 @@ class WiFiManager_Generic_Lite
#endif
//////////////////////////////////////////////
-
- void NULLTerminateConfig()
- {
- //#define HEADER_MAX_LEN 16
- //#define SERVER_MAX_LEN 32
- //#define TOKEN_MAX_LEN 36
-
- // NULL Terminating to be sure
- WIFI_GENERIC_config.header[HEADER_MAX_LEN - 1] = 0;
- WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid[SSID_MAX_LEN - 1] = 0;
- WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw [PASS_MAX_LEN - 1] = 0;
- WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid[SSID_MAX_LEN - 1] = 0;
- WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw [PASS_MAX_LEN - 1] = 0;
- WIFI_GENERIC_config.board_name[BOARD_NAME_MAX_LEN - 1] = 0;
- }
-
- //////////////////////////////////////////////
-
- bool isWiFiConfigValid()
- {
- #if REQUIRE_ONE_SET_SSID_PW
- // If SSID ="blank" or NULL, or PWD length < 8 (as required by standard) => return false
- // Only need 1 set of valid SSID/PWD
- if (!( ( ( strncmp(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG)) &&
- strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid) > 0 ) &&
- ( strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw) >= PASSWORD_MIN_LEN ) ) ||
- ( ( strncmp(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG)) &&
- strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid) > 0 ) &&
- ( strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw) >= PASSWORD_MIN_LEN ) ) ))
- #else
- // If SSID ="blank" or NULL, or PWD length < 8 (as required by standard) => invalid set
- // Need both sets of valid SSID/PWD
- if ( !strncmp(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
- !strncmp(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
- !strncmp(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
- !strncmp(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
- ( strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid) == 0 ) ||
- ( strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid) == 0 ) ||
- ( strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw) < PASSWORD_MIN_LEN ) ||
- ( strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw) < PASSWORD_MIN_LEN ) )
- #endif
- {
- // If SSID, PW ="blank" or NULL, set the flag
- WG_LOGERROR(F("Invalid Stored WiFi Config Data"));
-
- // Nullify the invalid data to avoid displaying garbage
- memset(&WIFI_GENERIC_config, 0, sizeof(WIFI_GENERIC_config));
-
- hadConfigData = false;
-
- return false;
- }
-
- return true;
- }
-
- //////////////////////////////////////////////
bool loadConfigData()
{
@@ -1463,180 +1444,732 @@ class WiFiManager_Generic_Lite
saveDynamicData();
#endif
}
+
+//////////////////////////////////////////////
+
+#else // #if defined(ARDUINO_ARCH_MBED)
+
+//////////////////////////////////////////////
+
+ #warning Using arduino-pico core
+ // For boards using arduino-pico core
+ // Already defined in DoubleResetDetector_Generic.h
+ // FS* filesystem = &LittleFS;
+ // #define FileFS LittleFS
- //////////////////////////////////////////////
-
- void loadAndSaveDefaultConfigData()
- {
- // Load Default Config Data from Sketch
- memcpy(&WIFI_GENERIC_config, &defaultConfig, sizeof(WIFI_GENERIC_config));
- strcpy(WIFI_GENERIC_config.header, WIFI_GENERIC_BOARD_TYPE);
-
- // Including config and dynamic data, and assume valid
- saveConfigData();
-
- WG_LOGDEBUG(F("======= Start Loaded Config Data ======="));
- displayConfigData(WIFI_GENERIC_config);
- }
-
- //////////////////////////////////////////////
+ //#define SEEK_SET SeekSet
- // Return false if init new EEPROM or SPIFFS. No more need trying to connect. Go directly to config mode
- bool getConfigData()
+ void saveForcedCP(uint32_t value)
{
- bool dynamicDataValid = true;
- int calChecksum;
-
- hadConfigData = false;
+ // Mbed RP2040 code
+ File file = filesystem->open(CONFIG_PORTAL_FILENAME, "w");
- // Use new LOAD_DEFAULT_CONFIG_DATA logic
- if (LOAD_DEFAULT_CONFIG_DATA)
- {
- // Load Config Data from Sketch
- loadAndSaveDefaultConfigData();
+ WG_LOGERROR(F("SaveCPFile "));
+
+ if (file)
+ {
+ file.seek(0, SeekSet);
+ file.write((uint8_t *) &value, sizeof(value));
+ file.close();
- // Don't need Config Portal anymore
- return true;
+ WG_LOGERROR(F("OK"));
}
else
- {
- // Load stored config data from LittleFS
- // Get config data. If "blank" or NULL, set false flag and exit
- if (!loadConfigData())
- {
- return false;
- }
-
- // Verify ChkSum
- calChecksum = calcChecksum();
-
- WG_LOGERROR3(F("CCSum=0x"), String(calChecksum, HEX),
- F(",RCSum=0x"), String(WIFI_GENERIC_config.checkSum, HEX));
-
-#if USE_DYNAMIC_PARAMETERS
- // Load stored dynamic data from LittleFS
- dynamicDataValid = checkDynamicData();
-#endif
-
- // If checksum = 0 => LittleFS has been cleared (by uploading new FW, etc) => force to CP
- // If bad checksum = 0 => force to CP
- if ( (calChecksum != 0) && (calChecksum == WIFI_GENERIC_config.checkSum) )
- {
- if (dynamicDataValid)
- {
- #if USE_DYNAMIC_PARAMETERS
- loadDynamicData();
-
- WG_LOGERROR(F("Valid Stored Dynamic Data"));
- #endif
-
- WG_LOGERROR(F("======= Start Stored Config Data ======="));
- displayConfigData(WIFI_GENERIC_config);
-
- // Don't need Config Portal anymore
- return true;
- }
- else
- {
- // Invalid Stored config data => Config Portal
- WG_LOGERROR(F("Invalid Stored Dynamic Data. Load default from Sketch"));
-
- // Load Default Config Data from Sketch, better than just "blank"
- loadAndSaveDefaultConfigData();
-
- // Need Config Portal here as data can be just dummy
- // Even if you don't open CP, you're OK on next boot if your default config data is valid
- return false;
- }
- }
- }
-
- if ( (strncmp(WIFI_GENERIC_config.header, WIFI_GENERIC_BOARD_TYPE, strlen(WIFI_GENERIC_BOARD_TYPE)) != 0) ||
- (calChecksum != WIFI_GENERIC_config.checkSum) || !dynamicDataValid ||
- ( (calChecksum == 0) && (WIFI_GENERIC_config.checkSum == 0) ) )
{
- // Including Credentials CSum
- WG_LOGERROR1(F("InitCfgFile,sz="), sizeof(WIFI_GENERIC_config));
-
- // doesn't have any configuration
- if (LOAD_DEFAULT_CONFIG_DATA)
- {
- memcpy(&WIFI_GENERIC_config, &defaultConfig, sizeof(WIFI_GENERIC_config));
- }
- else
- {
- memset(&WIFI_GENERIC_config, 0, sizeof(WIFI_GENERIC_config));
+ WG_LOGERROR(F("failed"));
+ }
-#if USE_DYNAMIC_PARAMETERS
- for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
- {
- // Actual size of pdata is [maxlen + 1]
- memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1);
- }
-#endif
-
- strcpy(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid, WM_NO_CONFIG);
- strcpy(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw, WM_NO_CONFIG);
- strcpy(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid, WM_NO_CONFIG);
- strcpy(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw, WM_NO_CONFIG);
- strcpy(WIFI_GENERIC_config.board_name, WM_NO_CONFIG);
-
-#if USE_DYNAMIC_PARAMETERS
- for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
- {
- strncpy(myMenuItems[i].pdata, WM_NO_CONFIG, myMenuItems[i].maxlen);
- }
-#endif
- }
-
- strcpy(WIFI_GENERIC_config.header, WIFI_GENERIC_BOARD_TYPE);
-
-#if USE_DYNAMIC_PARAMETERS
- for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
- {
- WG_LOGDEBUG3(F("g:myMenuItems["), i, F("]="), myMenuItems[i].pdata );
- }
-#endif
-
- // Don't need
- WIFI_GENERIC_config.checkSum = 0;
+ // Trying open redundant CP file
+ file = filesystem->open(CONFIG_PORTAL_FILENAME_BACKUP, "w");
+
+ WG_LOGERROR(F("SaveBkUpCPFile "));
- saveConfigData();
-
- return false;
- }
- else if ( !isWiFiConfigValid() )
+ if (file)
{
- // If SSID, PW ="blank" or NULL, stay in config mode forever until having config Data.
- return false;
+ file.seek(0, SeekSet);
+ file.write((uint8_t *) &value, sizeof(value));
+ file.close();
+
+ WG_LOGERROR(F("OK"));
}
else
{
- displayConfigData(WIFI_GENERIC_config);
+ WG_LOGERROR(F("failed"));
}
-
- return true;
}
//////////////////////////////////////////////
- // New connection logic from v1.2.0
- bool connectMultiWiFi(int retry_time)
+ void setForcedCP(bool isPersistent)
{
- int sleep_time = 250;
- int index = 0;
- int new_index = 0;
- uint8_t status = WL_IDLE_STATUS;
-
- static int lastConnectedIndex = 255;
-
- WG_LOGDEBUG(F("ConMultiWifi"));
-
- if (static_IP != IPAddress(0, 0, 0, 0))
- {
- WG_LOGDEBUG(F("UseStatIP"));
- WiFi.config(static_IP);
- }
+ uint32_t readForcedConfigPortalFlag = isPersistent? FORCED_PERS_CONFIG_PORTAL_FLAG_DATA : FORCED_CONFIG_PORTAL_FLAG_DATA;
+
+ WG_LOGERROR(isPersistent ? F("setForcedCP Persistent") : F("setForcedCP non-Persistent"));
+
+ saveForcedCP(readForcedConfigPortalFlag);
+ }
+
+ //////////////////////////////////////////////
+
+ void clearForcedCP()
+ {
+ uint32_t readForcedConfigPortalFlag = 0;
+
+ WG_LOGERROR(F("clearForcedCP"));
+
+ saveForcedCP(readForcedConfigPortalFlag);
+ }
+
+ //////////////////////////////////////////////
+
+ bool isForcedCP()
+ {
+ uint32_t readForcedConfigPortalFlag;
+
+ WG_LOGDEBUG(F("Check if isForcedCP"));
+
+ File file = filesystem->open(CONFIG_PORTAL_FILENAME, "r");
+
+ WG_LOGDEBUG(F("LoadCPFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+
+ // Trying open redundant config file
+ file = filesystem->open(CONFIG_PORTAL_FILENAME_BACKUP, "r");
+
+ WG_LOGDEBUG(F("LoadBkUpCPFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+ return false;
+ }
+ }
+
+ file.seek(0, SeekSet);
+ file.read((uint8_t *) &readForcedConfigPortalFlag, sizeof(readForcedConfigPortalFlag));
+ file.close();
+ WG_LOGDEBUG(F("OK"));
+
+
+ // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE)
+ // => set flag noForcedConfigPortal = false
+ if (readForcedConfigPortalFlag == FORCED_CONFIG_PORTAL_FLAG_DATA)
+ {
+ persForcedConfigPortal = false;
+ return true;
+ }
+ else if (readForcedConfigPortalFlag == FORCED_PERS_CONFIG_PORTAL_FLAG_DATA)
+ {
+ persForcedConfigPortal = true;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ //////////////////////////////////////////////
+
+#if USE_DYNAMIC_PARAMETERS
+
+ bool checkDynamicData()
+ {
+ int checkSum = 0;
+ int readCheckSum;
+ char* readBuffer = nullptr;
+
+ File file = filesystem->open(CREDENTIALS_FILENAME, "r");
+
+ WG_LOGDEBUG(F("LoadCredFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+
+ // Trying open redundant config file
+ file = filesystem->open(CREDENTIALS_FILENAME_BACKUP, "r");
+
+ WG_LOGDEBUG(F("LoadBkUpCredFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+ return false;
+ }
+ }
+
+ // Find the longest pdata, then dynamically allocate buffer. Remember to free when done
+ // This is used to store tempo data to calculate checksum to see of data is valid
+ // We dont like to destroy myMenuItems[i].pdata with invalid data
+
+ uint16_t maxBufferLength = 0;
+
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ if (myMenuItems[i].maxlen > maxBufferLength)
+ maxBufferLength = myMenuItems[i].maxlen;
+ }
+
+ if (maxBufferLength > 0)
+ {
+ readBuffer = new char[ maxBufferLength + 1 ];
+
+ // check to see NULL => stop and return false
+ if (readBuffer == NULL)
+ {
+ WG_LOGERROR(F("ChkCrR: Error can't allocate buffer."));
+ return false;
+ }
+ else
+ {
+ WG_LOGDEBUG1(F("ChkCrR: Buffer allocated, Sz="), maxBufferLength + 1);
+ }
+
+ uint16_t offset = 0;
+
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ uint8_t * _pointer = (uint8_t *) readBuffer;
+
+ // Actual size of pdata is [maxlen + 1]
+ memset(readBuffer, 0, myMenuItems[i].maxlen + 1);
+
+ // Redundant, but to be sure correct position
+ file.seek(offset, SeekSet);
+ file.read(_pointer, myMenuItems[i].maxlen);
+
+ offset += myMenuItems[i].maxlen;
+
+ WG_LOGDEBUG3(F("ChkCrR:pdata="), readBuffer, F(",len="), myMenuItems[i].maxlen);
+
+ for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++)
+ {
+ checkSum += *_pointer;
+ }
+ }
+
+ file.read((uint8_t *) &readCheckSum, sizeof(readCheckSum));
+
+ WG_LOGDEBUG(F("OK"));
+
+ file.close();
+
+ WG_LOGERROR3(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX));
+
+ if (readBuffer != nullptr)
+ {
+ // Free buffer
+ delete [] readBuffer;
+ WG_LOGDEBUG(F("Buffer freed"));
+ }
+
+ if ( checkSum == readCheckSum)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ //////////////////////////////////////////////
+
+ bool loadDynamicData()
+ {
+ int checkSum = 0;
+ int readCheckSum;
+ totalDataSize = sizeof(WIFI_GENERIC_config) + sizeof(readCheckSum);
+
+ File file = filesystem->open(CREDENTIALS_FILENAME, "r");
+
+ WG_LOGDEBUG(F("LoadCredFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+
+ // Trying open redundant config file
+ file = filesystem->open(CREDENTIALS_FILENAME_BACKUP, "r");
+
+ WG_LOGDEBUG(F("LoadBkUpCredFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+ return false;
+ }
+ }
+
+ uint16_t offset = 0;
+
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ uint8_t * _pointer = (uint8_t *) myMenuItems[i].pdata;
+ totalDataSize += myMenuItems[i].maxlen;
+
+ // Actual size of pdata is [maxlen + 1]
+ memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1);
+
+ // Redundant, but to be sure correct position
+ file.seek(offset, SeekSet);
+ file.read(_pointer, myMenuItems[i].maxlen);
+
+ offset += myMenuItems[i].maxlen;
+
+ WG_LOGDEBUG3(F("CrR:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen);
+
+ for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++)
+ {
+ checkSum += *_pointer;
+ }
+ }
+
+ file.read((uint8_t *) &readCheckSum, sizeof(readCheckSum));
+
+ WG_LOGDEBUG(F("OK"));
+
+ file.close();
+
+ WG_LOGDEBUG3(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX));
+
+ if ( checkSum != readCheckSum)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ //////////////////////////////////////////////
+
+ void saveDynamicData()
+ {
+ int checkSum = 0;
+
+ File file = filesystem->open(CREDENTIALS_FILENAME, "w");
+
+ WG_LOGDEBUG(F("SaveCredFile "));
+
+ uint16_t offset = 0;
+
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ uint8_t* _pointer = (uint8_t *) myMenuItems[i].pdata;
+
+ WG_LOGDEBUG3(F("CW1:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen);
+
+ if (file)
+ {
+ // Redundant, but to be sure correct position
+ file.seek(offset, SeekSet);
+ file.write(_pointer, myMenuItems[i].maxlen);
+
+ offset += myMenuItems[i].maxlen;
+ }
+ else
+ {
+ WG_LOGDEBUG(F("failed"));
+ }
+
+ for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++)
+ {
+ checkSum += *_pointer;
+ }
+ }
+
+ if (file)
+ {
+ file.write((uint8_t *) &checkSum, sizeof(checkSum));
+ file.close();
+
+ WG_LOGDEBUG(F("OK"));
+ }
+ else
+ {
+ WG_LOGDEBUG(F("failed"));
+ }
+
+ WG_LOGDEBUG1(F("CrWCSum=0x"), String(checkSum, HEX));
+
+ // Trying open redundant Auth file
+ file = filesystem->open(CREDENTIALS_FILENAME_BACKUP, "w");
+
+ WG_LOGDEBUG(F("SaveBkUpCredFile "));
+
+ offset = 0;
+
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ uint8_t* _pointer = (uint8_t *) myMenuItems[i].pdata;
+
+ WG_LOGDEBUG3(F("CW2:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen);
+
+ if (file)
+ {
+ file.seek(offset, SeekSet);
+ file.write(_pointer, myMenuItems[i].maxlen);
+
+ // Redundant, but to be sure correct position
+ offset += myMenuItems[i].maxlen;
+ }
+ else
+ {
+ WG_LOGDEBUG(F("failed"));
+ }
+
+ for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++)
+ {
+ checkSum += *_pointer;
+ }
+ }
+
+ if (file)
+ {
+ file.write((uint8_t *) &checkSum, sizeof(checkSum));
+ file.close();
+
+ WG_LOGDEBUG(F("OK"));
+ }
+ else
+ {
+ WG_LOGDEBUG(F("failed"));
+ }
+ }
+#endif
+
+ //////////////////////////////////////////////
+
+ bool loadConfigData()
+ {
+ WG_LOGDEBUG(F("LoadCfgFile "));
+
+ // file existed
+ File file = filesystem->open(CONFIG_FILENAME, "r");
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+
+ // Trying open redundant config file
+ file = filesystem->open(CONFIG_FILENAME_BACKUP, "r");
+
+ WG_LOGDEBUG(F("LoadBkUpCfgFile "));
+
+ if (!file)
+ {
+ WG_LOGDEBUG(F("failed"));
+ return false;
+ }
+ }
+
+ file.seek(0, SeekSet);
+ file.read((uint8_t *) &WIFI_GENERIC_config, sizeof(WIFI_GENERIC_config));
+ file.close();
+
+ WG_LOGDEBUG(F("OK"));
+
+ return isWiFiConfigValid();
+ }
+
+ //////////////////////////////////////////////
+
+ void saveConfigData()
+ {
+ WG_LOGDEBUG(F("SaveCfgFile "));
+
+ int calChecksum = calcChecksum();
+ WIFI_GENERIC_config.checkSum = calChecksum;
+ WG_LOGDEBUG1(F("WCSum=0x"), String(calChecksum, HEX));
+
+ File file = filesystem->open(CONFIG_FILENAME, "w");
+
+ if (file)
+ {
+ file.seek(0, SeekSet);
+ file.write((uint8_t *) &WIFI_GENERIC_config, sizeof(WIFI_GENERIC_config));
+ file.close();
+
+ WG_LOGDEBUG(F("OK"));
+ }
+ else
+ {
+ WG_LOGDEBUG(F("failed"));
+ }
+
+ WG_LOGDEBUG(F("SaveBkUpCfgFile "));
+
+ // Trying open redundant Auth file
+ file = filesystem->open(CONFIG_FILENAME_BACKUP, "w");
+
+ if (file)
+ {
+ file.seek(0, SeekSet);
+ file.write((uint8_t *) &WIFI_GENERIC_config, sizeof(WIFI_GENERIC_config));
+ file.close();
+
+ WG_LOGDEBUG(F("OK"));
+ }
+ else
+ {
+ WG_LOGDEBUG(F("failed"));
+ }
+
+#if USE_DYNAMIC_PARAMETERS
+ saveDynamicData();
+#endif
+ }
+
+//////////////////////////////////////////////
+
+#endif // #if defined(ARDUINO_ARCH_MBED)
+
+ //////////////////////////////////////////////
+
+ void NULLTerminateConfig()
+ {
+ //#define HEADER_MAX_LEN 16
+ //#define SERVER_MAX_LEN 32
+ //#define TOKEN_MAX_LEN 36
+
+ // NULL Terminating to be sure
+ WIFI_GENERIC_config.header[HEADER_MAX_LEN - 1] = 0;
+ WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid[SSID_MAX_LEN - 1] = 0;
+ WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw [PASS_MAX_LEN - 1] = 0;
+ WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid[SSID_MAX_LEN - 1] = 0;
+ WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw [PASS_MAX_LEN - 1] = 0;
+ WIFI_GENERIC_config.board_name[BOARD_NAME_MAX_LEN - 1] = 0;
+ }
+
+ //////////////////////////////////////////////
+
+ bool isWiFiConfigValid()
+ {
+ #if REQUIRE_ONE_SET_SSID_PW
+ // If SSID ="blank" or NULL, or PWD length < 8 (as required by standard) => return false
+ // Only need 1 set of valid SSID/PWD
+ if (!( ( ( strncmp(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG)) &&
+ strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid) > 0 ) &&
+ ( strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw) >= PASSWORD_MIN_LEN ) ) ||
+ ( ( strncmp(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG)) &&
+ strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid) > 0 ) &&
+ ( strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw) >= PASSWORD_MIN_LEN ) ) ))
+ #else
+ // If SSID ="blank" or NULL, or PWD length < 8 (as required by standard) => invalid set
+ // Need both sets of valid SSID/PWD
+ if ( !strncmp(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
+ !strncmp(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
+ !strncmp(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
+ !strncmp(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw, WM_NO_CONFIG, strlen(WM_NO_CONFIG) ) ||
+ ( strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid) == 0 ) ||
+ ( strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid) == 0 ) ||
+ ( strlen(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw) < PASSWORD_MIN_LEN ) ||
+ ( strlen(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw) < PASSWORD_MIN_LEN ) )
+ #endif
+ {
+ // If SSID, PW ="blank" or NULL, set the flag
+ WG_LOGERROR(F("Invalid Stored WiFi Config Data"));
+
+ // Nullify the invalid data to avoid displaying garbage
+ memset(&WIFI_GENERIC_config, 0, sizeof(WIFI_GENERIC_config));
+
+ hadConfigData = false;
+
+ return false;
+ }
+
+ return true;
+ }
+
+ //////////////////////////////////////////////
+
+
+ //////////////////////////////////////////////
+
+ void loadAndSaveDefaultConfigData()
+ {
+ // Load Default Config Data from Sketch
+ memcpy(&WIFI_GENERIC_config, &defaultConfig, sizeof(WIFI_GENERIC_config));
+ strcpy(WIFI_GENERIC_config.header, WIFI_GENERIC_BOARD_TYPE);
+
+ // Including config and dynamic data, and assume valid
+ saveConfigData();
+
+ WG_LOGDEBUG(F("======= Start Loaded Config Data ======="));
+ displayConfigData(WIFI_GENERIC_config);
+ }
+
+ //////////////////////////////////////////////
+
+ // Return false if init new EEPROM or SPIFFS. No more need trying to connect. Go directly to config mode
+ bool getConfigData()
+ {
+ bool dynamicDataValid = true;
+ int calChecksum;
+
+ hadConfigData = false;
+
+ // Use new LOAD_DEFAULT_CONFIG_DATA logic
+ if (LOAD_DEFAULT_CONFIG_DATA)
+ {
+ // Load Config Data from Sketch
+ loadAndSaveDefaultConfigData();
+
+ // Don't need Config Portal anymore
+ return true;
+ }
+ else
+ {
+ // Load stored config data from LittleFS
+ // Get config data. If "blank" or NULL, set false flag and exit
+ if (!loadConfigData())
+ {
+ return false;
+ }
+
+ // Verify ChkSum
+ calChecksum = calcChecksum();
+
+ WG_LOGERROR3(F("CCSum=0x"), String(calChecksum, HEX),
+ F(",RCSum=0x"), String(WIFI_GENERIC_config.checkSum, HEX));
+
+#if USE_DYNAMIC_PARAMETERS
+ // Load stored dynamic data from LittleFS
+ dynamicDataValid = checkDynamicData();
+#endif
+
+ // If checksum = 0 => LittleFS has been cleared (by uploading new FW, etc) => force to CP
+ // If bad checksum = 0 => force to CP
+ if ( (calChecksum != 0) && (calChecksum == WIFI_GENERIC_config.checkSum) )
+ {
+ if (dynamicDataValid)
+ {
+ #if USE_DYNAMIC_PARAMETERS
+ loadDynamicData();
+
+ WG_LOGERROR(F("Valid Stored Dynamic Data"));
+ #endif
+
+ WG_LOGERROR(F("======= Start Stored Config Data ======="));
+ displayConfigData(WIFI_GENERIC_config);
+
+ // Don't need Config Portal anymore
+ return true;
+ }
+ else
+ {
+ // Invalid Stored config data => Config Portal
+ WG_LOGERROR(F("Invalid Stored Dynamic Data. Load default from Sketch"));
+
+ // Load Default Config Data from Sketch, better than just "blank"
+ loadAndSaveDefaultConfigData();
+
+ // Need Config Portal here as data can be just dummy
+ // Even if you don't open CP, you're OK on next boot if your default config data is valid
+ return false;
+ }
+ }
+ }
+
+ if ( (strncmp(WIFI_GENERIC_config.header, WIFI_GENERIC_BOARD_TYPE, strlen(WIFI_GENERIC_BOARD_TYPE)) != 0) ||
+ (calChecksum != WIFI_GENERIC_config.checkSum) || !dynamicDataValid ||
+ ( (calChecksum == 0) && (WIFI_GENERIC_config.checkSum == 0) ) )
+ {
+ // Including Credentials CSum
+ WG_LOGERROR1(F("InitCfgFile,sz="), sizeof(WIFI_GENERIC_config));
+
+ // doesn't have any configuration
+ if (LOAD_DEFAULT_CONFIG_DATA)
+ {
+ memcpy(&WIFI_GENERIC_config, &defaultConfig, sizeof(WIFI_GENERIC_config));
+ }
+ else
+ {
+ memset(&WIFI_GENERIC_config, 0, sizeof(WIFI_GENERIC_config));
+
+#if USE_DYNAMIC_PARAMETERS
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ // Actual size of pdata is [maxlen + 1]
+ memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1);
+ }
+#endif
+
+ strcpy(WIFI_GENERIC_config.WiFi_Creds[0].wifi_ssid, WM_NO_CONFIG);
+ strcpy(WIFI_GENERIC_config.WiFi_Creds[0].wifi_pw, WM_NO_CONFIG);
+ strcpy(WIFI_GENERIC_config.WiFi_Creds[1].wifi_ssid, WM_NO_CONFIG);
+ strcpy(WIFI_GENERIC_config.WiFi_Creds[1].wifi_pw, WM_NO_CONFIG);
+ strcpy(WIFI_GENERIC_config.board_name, WM_NO_CONFIG);
+
+#if USE_DYNAMIC_PARAMETERS
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ strncpy(myMenuItems[i].pdata, WM_NO_CONFIG, myMenuItems[i].maxlen);
+ }
+#endif
+ }
+
+ strcpy(WIFI_GENERIC_config.header, WIFI_GENERIC_BOARD_TYPE);
+
+#if USE_DYNAMIC_PARAMETERS
+ for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
+ {
+ WG_LOGDEBUG3(F("g:myMenuItems["), i, F("]="), myMenuItems[i].pdata );
+ }
+#endif
+
+ // Don't need
+ WIFI_GENERIC_config.checkSum = 0;
+
+ saveConfigData();
+
+ return false;
+ }
+ else if ( !isWiFiConfigValid() )
+ {
+ // If SSID, PW ="blank" or NULL, stay in config mode forever until having config Data.
+ return false;
+ }
+ else
+ {
+ displayConfigData(WIFI_GENERIC_config);
+ }
+
+ return true;
+ }
+
+ //////////////////////////////////////////////
+
+// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
+// Default 1 and minimum 1.
+#if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+#else
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+ #endif
+#endif
+
+ // New connection logic from v1.2.0
+ bool connectMultiWiFi(int retry_time)
+ {
+ int sleep_time = 250;
+ int index = 0;
+ int new_index = 0;
+ uint8_t status = WL_IDLE_STATUS;
+
+ static int lastConnectedIndex = 255;
+
+ WG_LOGDEBUG(F("ConMultiWifi"));
+
+ if (static_IP != IPAddress(0, 0, 0, 0))
+ {
+ WG_LOGDEBUG(F("UseStatIP"));
+ WiFi.config(static_IP);
+ }
if (lastConnectedIndex != 255)
{
@@ -1679,7 +2212,9 @@ class WiFiManager_Generic_Lite
uint8_t numIndexTried = 0;
- while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) )
+ uint8_t numWiFiReconTries = 0;
+
+ while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
{
while ( 0 < retry_time )
{
@@ -1744,7 +2279,7 @@ class WiFiManager_Generic_Lite
return wifi_connected;
}
-
+
//////////////////////////////////////////////
// NEW
diff --git a/src/WiFiManager_Generic_Lite_SAMD.h b/src/WiFiManager_Generic_Lite_SAMD.h
index 7d301859..bcda8b3e 100644
--- a/src/WiFiManager_Generic_Lite_SAMD.h
+++ b/src/WiFiManager_Generic_Lite_SAMD.h
@@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -22,7 +22,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_SAMD_h
@@ -41,7 +42,7 @@
#error This code is intended to run on the SAMD platform! Please check your Tools->Board setting.
#endif
-#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.4.1"
+#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.5.0"
#if (USE_WIFI_NINA || USE_WIFI101)
#include
@@ -436,6 +437,16 @@ class WiFiManager_Generic_Lite
#endif
#endif
+#if !defined(WIFI_RECON_INTERVAL)
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
+#else
+ #if (WIFI_RECON_INTERVAL < 0)
+ #define WIFI_RECON_INTERVAL 0
+ #elif (WIFI_RECON_INTERVAL > 600000)
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
+ #endif
+#endif
+
void run()
{
static int retryTimes = 0;
@@ -447,6 +458,10 @@ class WiFiManager_Generic_Lite
static unsigned long checkstatus_timeout = 0;
#define WIFI_STATUS_CHECK_INTERVAL 5000L
+ static uint32_t curMillis;
+
+ curMillis = millis();
+
//// New DRD ////
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
@@ -455,7 +470,7 @@ class WiFiManager_Generic_Lite
drd->loop();
//// New DRD ////
- if ( !configuration_mode && (millis() > checkstatus_timeout) )
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
{
if (WiFi.status() == WL_CONNECTED)
{
@@ -475,7 +490,7 @@ class WiFiManager_Generic_Lite
}
}
- checkstatus_timeout = millis() + WIFI_STATUS_CHECK_INTERVAL;
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
}
// Lost connection in running. Give chance to reconfig.
@@ -516,12 +531,31 @@ class WiFiManager_Generic_Lite
// Not in config mode, try reconnecting before forcing to config mode
if ( !wifi_connected )
{
+
+
+#if (WIFI_RECON_INTERVAL > 0)
+
+ static uint32_t lastMillis = 0;
+
+ if ( (lastMillis == 0) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
+ {
+ lastMillis = curMillis;
+
+ WG_LOGERROR(F("r:WLost.ReconW"));
+
+ if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
+ {
+ WG_LOGERROR(F("r:WOK"));
+ }
+ }
+#else
WG_LOGERROR(F("r:WLost.ReconW"));
if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
{
WG_LOGERROR(F("r:WOK"));
}
+#endif
}
}
}
@@ -1364,6 +1398,16 @@ class WiFiManager_Generic_Lite
//////////////////////////////////////////////
+// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
+// Default 1 and minimum 1.
+#if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+#else
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+ #endif
+#endif
+
// New connection logic from v1.2.0
bool connectMultiWiFi(int retry_time)
{
@@ -1423,7 +1467,9 @@ class WiFiManager_Generic_Lite
uint8_t numIndexTried = 0;
- while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) )
+ uint8_t numWiFiReconTries = 0;
+
+ while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
{
while ( 0 < retry_time )
{
diff --git a/src/WiFiManager_Generic_Lite_STM32.h b/src/WiFiManager_Generic_Lite_STM32.h
index 9a095006..fc00210b 100644
--- a/src/WiFiManager_Generic_Lite_STM32.h
+++ b/src/WiFiManager_Generic_Lite_STM32.h
@@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -22,7 +22,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_STM32_h
@@ -41,7 +42,7 @@
#error This code is intended to run on STM32 platform! Please check your Tools->Board setting.
#endif
-#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.4.1"
+#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.5.0"
#if (USE_WIFI_NINA || USE_WIFI101)
#include
@@ -436,6 +437,16 @@ class WiFiManager_Generic_Lite
#endif
#endif
+#if !defined(WIFI_RECON_INTERVAL)
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
+#else
+ #if (WIFI_RECON_INTERVAL < 0)
+ #define WIFI_RECON_INTERVAL 0
+ #elif (WIFI_RECON_INTERVAL > 600000)
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
+ #endif
+#endif
+
void run()
{
static int retryTimes = 0;
@@ -447,6 +458,10 @@ class WiFiManager_Generic_Lite
static unsigned long checkstatus_timeout = 0;
#define WIFI_STATUS_CHECK_INTERVAL 5000L
+ static uint32_t curMillis;
+
+ curMillis = millis();
+
//// New DRD ////
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
@@ -455,7 +470,7 @@ class WiFiManager_Generic_Lite
drd->loop();
//// New DRD ////
- if ( !configuration_mode && (millis() > checkstatus_timeout) )
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
{
if (WiFi.status() == WL_CONNECTED)
{
@@ -475,7 +490,7 @@ class WiFiManager_Generic_Lite
}
}
- checkstatus_timeout = millis() + WIFI_STATUS_CHECK_INTERVAL;
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
}
// Lost connection in running. Give chance to reconfig.
@@ -516,12 +531,31 @@ class WiFiManager_Generic_Lite
// Not in config mode, try reconnecting before forcing to config mode
if ( !wifi_connected )
{
+
+
+#if (WIFI_RECON_INTERVAL > 0)
+
+ static uint32_t lastMillis = 0;
+
+ if ( (lastMillis == 0) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
+ {
+ lastMillis = curMillis;
+
+ WG_LOGERROR(F("r:WLost.ReconW"));
+
+ if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
+ {
+ WG_LOGERROR(F("r:WOK"));
+ }
+ }
+#else
WG_LOGERROR(F("r:WLost.ReconW"));
if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
{
WG_LOGERROR(F("r:WOK"));
}
+#endif
}
}
}
@@ -1358,6 +1392,16 @@ class WiFiManager_Generic_Lite
//////////////////////////////////////////////
+// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
+// Default 1 and minimum 1.
+#if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+#else
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+ #endif
+#endif
+
// New connection logic from v1.2.0
bool connectMultiWiFi(int retry_time)
{
@@ -1417,7 +1461,9 @@ class WiFiManager_Generic_Lite
uint8_t numIndexTried = 0;
- while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) )
+ uint8_t numWiFiReconTries = 0;
+
+ while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
{
while ( 0 < retry_time )
{
diff --git a/src/WiFiManager_Generic_Lite_Teensy.h b/src/WiFiManager_Generic_Lite_Teensy.h
index 08e47a47..ffb11897 100644
--- a/src/WiFiManager_Generic_Lite_Teensy.h
+++ b/src/WiFiManager_Generic_Lite_Teensy.h
@@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -22,7 +22,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_Teensy_h
@@ -42,7 +43,7 @@
#error Teensy 2.0 not supported yet
#endif
-#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.4.1"
+#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.5.0"
#if (USE_WIFI_NINA || USE_WIFI101)
#include
@@ -435,6 +436,16 @@ class WiFiManager_Generic_Lite
#endif
#endif
+#if !defined(WIFI_RECON_INTERVAL)
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
+#else
+ #if (WIFI_RECON_INTERVAL < 0)
+ #define WIFI_RECON_INTERVAL 0
+ #elif (WIFI_RECON_INTERVAL > 600000)
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
+ #endif
+#endif
+
void run()
{
static int retryTimes = 0;
@@ -446,6 +457,10 @@ class WiFiManager_Generic_Lite
static unsigned long checkstatus_timeout = 0;
#define WIFI_STATUS_CHECK_INTERVAL 5000L
+ static uint32_t curMillis;
+
+ curMillis = millis();
+
//// New DRD ////
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
@@ -454,7 +469,7 @@ class WiFiManager_Generic_Lite
drd->loop();
//// New DRD ////
- if ( !configuration_mode && (millis() > checkstatus_timeout) )
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
{
if (WiFi.status() == WL_CONNECTED)
{
@@ -474,7 +489,7 @@ class WiFiManager_Generic_Lite
}
}
- checkstatus_timeout = millis() + WIFI_STATUS_CHECK_INTERVAL;
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
}
// Lost connection in running. Give chance to reconfig.
@@ -515,12 +530,31 @@ class WiFiManager_Generic_Lite
// Not in config mode, try reconnecting before forcing to config mode
if ( !wifi_connected )
{
+
+
+#if (WIFI_RECON_INTERVAL > 0)
+
+ static uint32_t lastMillis = 0;
+
+ if ( (lastMillis == 0) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
+ {
+ lastMillis = curMillis;
+
+ WG_LOGERROR(F("r:WLost.ReconW"));
+
+ if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
+ {
+ WG_LOGERROR(F("r:WOK"));
+ }
+ }
+#else
WG_LOGERROR(F("r:WLost.ReconW"));
if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
{
WG_LOGERROR(F("r:WOK"));
}
+#endif
}
}
}
@@ -1380,6 +1414,16 @@ class WiFiManager_Generic_Lite
//////////////////////////////////////////////
+// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
+// Default 1 and minimum 1.
+#if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+#else
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+ #endif
+#endif
+
// New connection logic from v1.2.0
bool connectMultiWiFi(int retry_time)
{
@@ -1439,7 +1483,9 @@ class WiFiManager_Generic_Lite
uint8_t numIndexTried = 0;
- while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) )
+ uint8_t numWiFiReconTries = 0;
+
+ while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
{
while ( 0 < retry_time )
{
diff --git a/src/WiFiManager_Generic_Lite_nRF52.h b/src/WiFiManager_Generic_Lite_nRF52.h
index 2ddeeb64..97e3778d 100644
--- a/src/WiFiManager_Generic_Lite_nRF52.h
+++ b/src/WiFiManager_Generic_Lite_nRF52.h
@@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
- Version: 1.4.1
+ Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -22,7 +22,8 @@
1.2.0 K Hoang 14/04/2021 Optional one set of WiFi Credentials. Enforce WiFi PWD minimum 8 chars
1.3.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.4.0 K Hoang 29/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or Arduino-pico core
- 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.4.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json`
+ 1.5.0 K Hoang 07/01/2022 Configurable WIFI_RECON_INTERVAL. Add support to RP2040 using arduino-pico core
********************************************************************************************************************************/
#ifndef WiFiManager_Generic_Lite_nRF52_h
@@ -39,7 +40,7 @@
#error This code is intended to run on the nRF52 platform! Please check your Tools->Board setting.
#endif
-#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.4.1"
+#define WIFI_MANAGER_GENERIC_LITE_VERSION "WiFiManager_Generic_Lite v1.5.0"
#if (USE_WIFI_NINA || USE_WIFI101)
#include
@@ -440,6 +441,16 @@ class WiFiManager_Generic_Lite
#endif
#endif
+#if !defined(WIFI_RECON_INTERVAL)
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
+#else
+ #if (WIFI_RECON_INTERVAL < 0)
+ #define WIFI_RECON_INTERVAL 0
+ #elif (WIFI_RECON_INTERVAL > 600000)
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
+ #endif
+#endif
+
void run()
{
static int retryTimes = 0;
@@ -451,6 +462,10 @@ class WiFiManager_Generic_Lite
static unsigned long checkstatus_timeout = 0;
#define WIFI_STATUS_CHECK_INTERVAL 5000L
+ static uint32_t curMillis;
+
+ curMillis = millis();
+
//// New DRD ////
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
@@ -459,7 +474,7 @@ class WiFiManager_Generic_Lite
drd->loop();
//// New DRD ////
- if ( !configuration_mode && (millis() > checkstatus_timeout) )
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
{
if (WiFi.status() == WL_CONNECTED)
{
@@ -479,7 +494,7 @@ class WiFiManager_Generic_Lite
}
}
- checkstatus_timeout = millis() + WIFI_STATUS_CHECK_INTERVAL;
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
}
// Lost connection in running. Give chance to reconfig.
@@ -520,12 +535,31 @@ class WiFiManager_Generic_Lite
// Not in config mode, try reconnecting before forcing to config mode
if ( !wifi_connected )
{
+
+
+#if (WIFI_RECON_INTERVAL > 0)
+
+ static uint32_t lastMillis = 0;
+
+ if ( (lastMillis == 0) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
+ {
+ lastMillis = curMillis;
+
+ WG_LOGERROR(F("r:WLost.ReconW"));
+
+ if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
+ {
+ WG_LOGERROR(F("r:WOK"));
+ }
+ }
+#else
WG_LOGERROR(F("r:WLost.ReconW"));
if (connectMultiWiFi(RETRY_TIMES_RECONNECT_WIFI))
{
WG_LOGERROR(F("r:WOK"));
}
+#endif
}
}
}
@@ -1579,6 +1613,16 @@ class WiFiManager_Generic_Lite
//////////////////////////////////////////////
+// Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
+// Default 1 and minimum 1.
+#if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+#else
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
+ #endif
+#endif
+
// New connection logic from v1.2.0
bool connectMultiWiFi(int retry_time)
{
@@ -1638,7 +1682,9 @@ class WiFiManager_Generic_Lite
uint8_t numIndexTried = 0;
- while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) )
+ uint8_t numWiFiReconTries = 0;
+
+ while ( !wifi_connected && (numIndexTried++ < NUM_WIFI_CREDENTIALS) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
{
while ( 0 < retry_time )
{