diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1cb38d2..13c8741 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.19) or Platform.io version -* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.6.1, etc.) +* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.7.2, 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: @@ -28,9 +28,9 @@ Please ensure to specify the following: ``` Arduino IDE version: 1.8.19 Nano_RP2040_Connect board -ArduinoCore-mbed v2.6.1 +ArduinoCore-mbed v2.7.2 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: The board couldn't autoreconnect to Local Blynk Server after router power recycling. @@ -51,3 +51,4 @@ There are usually some outstanding feature requests in the [existing issues list ### Sending Pull Requests Pull Requests with changes and fixes are also welcome! + diff --git a/README.md b/README.md index 0ab5183..60ef45a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP_AT_WM_Lite.svg)](http://github.com/khoih-prog/ESP_AT_WM_Lite/issues) -Buy Me A Coffee +Donate to my libraries using BuyMeACoffee + --- --- @@ -59,6 +60,7 @@ * [9. To avoid blocking in loop when WiFi is lost](#9-To-avoid-blocking-in-loop-when-wifi-is-lost) * [9.1 Max times to try WiFi per loop](#91-max-times-to-try-wifi-per-loop) * [9.2 Interval between reconnection WiFi if lost](#92-interval-between-reconnection-wifi-if-lost) + * [10. Not using Board_Name on Config_Portal](#10-Not-using-Board_Name-on-Config_Portal) * [Important Notes for using Dynamic Parameters' ids](#important-notes-for-using-dynamic-parameters-ids) * [Examples](#examples) * [ 1. Mega_ESP8266Shield](examples/Mega_ESP8266Shield) @@ -192,16 +194,16 @@ This [**ESP_AT_WM_Lite** library](https://github.com/khoih-prog/ESP_AT_WM_Lite) ## Prerequisites 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) - 2. [`Arduino AVR core 1.8.3+`](https://github.com/arduino/ArduinoCore-avr) for Arduino (Use Arduino Board Manager) for AVR boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest) + 2. [`Arduino AVR core 1.8.5+`](https://github.com/arduino/ArduinoCore-avr) for Arduino (Use Arduino Board Manager) for AVR boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest) 3. [`Arduino Core for STM32 v2.2.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32F/L/H/G/WB/MP1 boards (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.). [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) 4. [`Teensy core 1.56+`](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 5. [`Arduino SAM DUE core v1.6.12+`](https://github.com/arduino/ArduinoCore-sam) for SAM DUE ARM Cortex-M3 boards. 6. [`Arduino SAMD core 1.8.12+`](https://github.com/arduino/ArduinoCore-samd) 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) - 7. [`Adafruit SAMD core 1.7.8+`](https://github.com/adafruit/ArduinoCore-samd) 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. [`Adafruit SAMD core 1.7.9+`](https://github.com/adafruit/ArduinoCore-samd) 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) 8. [`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/) 9. [`Adafruit nRF52 v1.3.0+`](https://github.com/adafruit/Adafruit_nRF52_Arduino) 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) -10. [`Arduino mbed_rp2040 core 2.6.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino 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) -11. [`Earle Philhower's arduino-pico core v1.10.0+`](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) +10. [`Arduino mbed_rp2040 core 2.7.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino 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) +11. [`Earle Philhower's arduino-pico core v1.12.0+`](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) 12. [`ESP8266_AT_WebServer library v1.5.3+`](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) 13. [`FlashStorage_SAMD library v1.3.2+`](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.). To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/FlashStorage_SAMD.svg?)](https://www.ardu-badge.com/FlashStorage_SAMD) 14. [`FlashStorage_STM32F1 library v1.1.0+`](https://github.com/khoih-prog/FlashStorage_STM32F1) for STM32F1/F3 boards. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/FlashStorage_STM32F1.svg?)](https://www.ardu-badge.com/FlashStorage_STM32F1) @@ -413,13 +415,13 @@ Whenever the above-mentioned compiler error issue is fixed with the new Arduino #### 5. For Adafruit SAMD boards - ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.7) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.7). + ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.9) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.9). -Supposing the Adafruit SAMD core version is 1.7.7. This file must be copied into the directory: +Supposing the Adafruit SAMD core version is 1.7.9. This file must be copied into the directory: -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.7/platform.txt` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.7/cores/arduino/Print.h` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.7/cores/arduino/Print.cpp` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/platform.txt` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/cores/arduino/Print.h` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/cores/arduino/Print.cpp` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: @@ -521,12 +523,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.6.1/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/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.7.2/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/2.7.2/portenta_post_install.sh). Then run the following command using `sudo` ``` -$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1 +$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.7.2 $ chmod 755 portenta_post_install.sh $ sudo ./portenta_post_install.sh ``` @@ -539,9 +541,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.6.1. Now only one file must be copied into the directory: +Supposing the ArduinoCore-mbed core version is 2.7.2. Now only one file must be copied into the directory: -- `~/.arduino15/packages/arduino/hardware/mbed_portenta/2.6.1/portenta_post_install.sh` +- `~/.arduino15/packages/arduino/hardware/mbed_portenta/2.7.2/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 @@ -781,6 +783,13 @@ Check [retries block the main loop #18](https://github.com/khoih-prog/WiFiManage #define WIFI_RECON_INTERVAL 30000 // 30s ``` + +#### 10. Not using Board_Name on Config_Portal + +Default is `true`. Just change to `false` to not using `Board_Name` on Config_Portal + + + --- --- diff --git a/changelog.md b/changelog.md index 47433ad..840336a 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Release v1.5.2](#release-v152) * [Release v1.5.1](#release-v151) * [Release v1.5.0](#release-v150) * [Release v1.4.1](#release-v141) @@ -29,6 +30,13 @@ ## Changelog +### Release v1.5.2 + +1. Optimize code by using passing by `reference` instead of by `value` +2. Optional `Board_Name` in Menu. Check [option to remove board name from web page #25](https://github.com/khoih-prog/WiFiManager_NINA_Lite/issues/25) +3. Add function `isConfigMode()` to signal system is in Config Portal mode. +4. Update `Packages' Patches` + ### Release v1.5.1 1. Update to be compatible with new `FlashStorage_SAMD` diff --git a/examples/Mega_ESP8266Shield/Mega_ESP8266Shield.ino b/examples/Mega_ESP8266Shield/Mega_ESP8266Shield.ino index b4e983a..3839c0d 100644 --- a/examples/Mega_ESP8266Shield/Mega_ESP8266Shield.ino +++ b/examples/Mega_ESP8266Shield/Mega_ESP8266Shield.ino @@ -20,10 +20,22 @@ void heartBeatPrint() { static int num = 1; + if (ESP_AT_WiFiManager->getWiFiStatus()) + Serial.print("H"); // H means connected to WiFi + else + { + if (ESP_AT_WiFiManager->isConfigMode()) + Serial.print("C"); // C means in Config Mode + else + Serial.print("F"); // F means not connected to WiFi + } + +#if 0 if (WiFi.status() == WL_CONNECTED) Serial.print(F("H")); // H means connected to WiFi else Serial.print(F("F")); // F means not connected to WiFi +#endif if (num == 80) { diff --git a/examples/Mega_ESP8266Shield/defines.h b/examples/Mega_ESP8266Shield/defines.h index d285f22..cf201cc 100644 --- a/examples/Mega_ESP8266Shield/defines.h +++ b/examples/Mega_ESP8266Shield/defines.h @@ -72,6 +72,28 @@ ///////////////////////////////////////////// +// Optional, to use Board Name in Menu +#define USING_BOARD_NAME false //true + +///////////////////////////////////////////// + +// Optional, to use Board Name in Menu +#define USING_CONFIG_MODE_LED true + +#if USING_CONFIG_MODE_LED + #if defined(LED_BUILTIN) + #define CONFIG_MODE_LED LED_BUILTIN + #else + // Using default pin 13 for CONFIG_MODE_LED. To be changed as necessary + #define CONFIG_MODE_LED 13 + #endif + + #define LED_ON HIGH + #define LED_OFF LOW +#endif + +///////////////////////////////////////////// + #include #define HOST_NAME "Mega-ESP_AT" diff --git a/examples/RPi_Pico_ESP8266Shield/RPi_Pico_ESP8266Shield.ino b/examples/RPi_Pico_ESP8266Shield/RPi_Pico_ESP8266Shield.ino index 0bc4320..728ba89 100644 --- a/examples/RPi_Pico_ESP8266Shield/RPi_Pico_ESP8266Shield.ino +++ b/examples/RPi_Pico_ESP8266Shield/RPi_Pico_ESP8266Shield.ino @@ -23,7 +23,12 @@ void heartBeatPrint() if (ESP_AT_WiFiManager->getWiFiStatus()) Serial.print("H"); // H means connected to WiFi else - Serial.print("F"); // F means not connected to WiFi + { + if (ESP_AT_WiFiManager->isConfigMode()) + Serial.print("C"); // C means in Config Mode + else + Serial.print("F"); // F means not connected to WiFi + } if (num == 80) { diff --git a/examples/RPi_Pico_ESP8266Shield/defines.h b/examples/RPi_Pico_ESP8266Shield/defines.h index 8c93165..ca6af88 100644 --- a/examples/RPi_Pico_ESP8266Shield/defines.h +++ b/examples/RPi_Pico_ESP8266Shield/defines.h @@ -125,6 +125,28 @@ ///////////////////////////////////////////// +// Optional, to use Board Name in Menu +#define USING_BOARD_NAME false //true + +///////////////////////////////////////////// + +// Optional, to use Board Name in Menu +#define USING_CONFIG_MODE_LED true + +#if USING_CONFIG_MODE_LED + #if defined(LED_BUILTIN) + #define CONFIG_MODE_LED LED_BUILTIN + #else + // Using default pin 13 for CONFIG_MODE_LED. To be changed as necessary + #define CONFIG_MODE_LED 13 + #endif + + #define LED_ON HIGH + #define LED_OFF LOW +#endif + +///////////////////////////////////////////// + #if ESP8266_AT_USE_RP2040 #include diff --git a/examples/SAMD_ESP8266Shield/SAMD_ESP8266Shield.ino b/examples/SAMD_ESP8266Shield/SAMD_ESP8266Shield.ino index 5c84b1b..9d3d832 100644 --- a/examples/SAMD_ESP8266Shield/SAMD_ESP8266Shield.ino +++ b/examples/SAMD_ESP8266Shield/SAMD_ESP8266Shield.ino @@ -23,7 +23,12 @@ void heartBeatPrint() if (ESP_AT_WiFiManager->getWiFiStatus()) Serial.print("H"); // H means connected to WiFi else - Serial.print("F"); // F means not connected to WiFi + { + if (ESP_AT_WiFiManager->isConfigMode()) + Serial.print("C"); // C means in Config Mode + else + Serial.print("F"); // F means not connected to WiFi + } if (num == 80) { diff --git a/examples/SAMD_ESP8266Shield/defines.h b/examples/SAMD_ESP8266Shield/defines.h index ad62451..580df44 100644 --- a/examples/SAMD_ESP8266Shield/defines.h +++ b/examples/SAMD_ESP8266Shield/defines.h @@ -134,6 +134,28 @@ ///////////////////////////////////////////// +// Optional, to use Board Name in Menu +#define USING_BOARD_NAME false //true + +///////////////////////////////////////////// + +// Optional, to use Board Name in Menu +#define USING_CONFIG_MODE_LED true + +#if USING_CONFIG_MODE_LED + #if defined(LED_BUILTIN) + #define CONFIG_MODE_LED LED_BUILTIN + #else + // Using default pin 13 for CONFIG_MODE_LED. To be changed as necessary + #define CONFIG_MODE_LED 13 + #endif + + #define LED_ON HIGH + #define LED_OFF LOW +#endif + +///////////////////////////////////////////// + #include #define HOST_NAME "SAMD_ESP_AT" diff --git a/examples/SAM_DUE_ESP8266Shield/SAM_DUE_ESP8266Shield.ino b/examples/SAM_DUE_ESP8266Shield/SAM_DUE_ESP8266Shield.ino index 4700aab..16a17d5 100644 --- a/examples/SAM_DUE_ESP8266Shield/SAM_DUE_ESP8266Shield.ino +++ b/examples/SAM_DUE_ESP8266Shield/SAM_DUE_ESP8266Shield.ino @@ -23,7 +23,12 @@ void heartBeatPrint() if (ESP_AT_WiFiManager->getWiFiStatus()) Serial.print("H"); // H means connected to WiFi else - Serial.print("F"); // F means not connected to WiFi + { + if (ESP_AT_WiFiManager->isConfigMode()) + Serial.print("C"); // C means in Config Mode + else + Serial.print("F"); // F means not connected to WiFi + } if (num == 80) { diff --git a/examples/SAM_DUE_ESP8266Shield/defines.h b/examples/SAM_DUE_ESP8266Shield/defines.h index 2bd1fd4..6890ff4 100644 --- a/examples/SAM_DUE_ESP8266Shield/defines.h +++ b/examples/SAM_DUE_ESP8266Shield/defines.h @@ -92,6 +92,28 @@ ///////////////////////////////////////////// +// Optional, to use Board Name in Menu +#define USING_BOARD_NAME false //true + +///////////////////////////////////////////// + +// Optional, to use Board Name in Menu +#define USING_CONFIG_MODE_LED true + +#if USING_CONFIG_MODE_LED + #if defined(LED_BUILTIN) + #define CONFIG_MODE_LED LED_BUILTIN + #else + // Using default pin 13 for CONFIG_MODE_LED. To be changed as necessary + #define CONFIG_MODE_LED 13 + #endif + + #define LED_ON HIGH + #define LED_OFF LOW +#endif + +///////////////////////////////////////////// + #include #define HOST_NAME "SAM_DUE-ESP_AT" diff --git a/examples/STM32_ESP8266Shield/STM32_ESP8266Shield.ino b/examples/STM32_ESP8266Shield/STM32_ESP8266Shield.ino index d1ee853..c2ea149 100644 --- a/examples/STM32_ESP8266Shield/STM32_ESP8266Shield.ino +++ b/examples/STM32_ESP8266Shield/STM32_ESP8266Shield.ino @@ -23,7 +23,12 @@ void heartBeatPrint() if (ESP_AT_WiFiManager->getWiFiStatus()) Serial.print("H"); // H means connected to WiFi else - Serial.print("F"); // F means not connected to WiFi + { + if (ESP_AT_WiFiManager->isConfigMode()) + Serial.print("C"); // C means in Config Mode + else + Serial.print("F"); // F means not connected to WiFi + } if (num == 80) { diff --git a/examples/STM32_ESP8266Shield/defines.h b/examples/STM32_ESP8266Shield/defines.h index de1568d..4c6a40a 100644 --- a/examples/STM32_ESP8266Shield/defines.h +++ b/examples/STM32_ESP8266Shield/defines.h @@ -156,6 +156,28 @@ ///////////////////////////////////////////// +// Optional, to use Board Name in Menu +#define USING_BOARD_NAME false //true + +///////////////////////////////////////////// + +// Optional, to use Board Name in Menu +#define USING_CONFIG_MODE_LED true + +#if USING_CONFIG_MODE_LED + #if defined(LED_BUILTIN) + #define CONFIG_MODE_LED LED_BUILTIN + #else + // Using default pin 13 for CONFIG_MODE_LED. To be changed as necessary + #define CONFIG_MODE_LED 13 + #endif + + #define LED_ON HIGH + #define LED_OFF LOW +#endif + +///////////////////////////////////////////// + #include diff --git a/examples/nRF52_ESP8266Shield/defines.h b/examples/nRF52_ESP8266Shield/defines.h index 7b1675d..d3cb58a 100644 --- a/examples/nRF52_ESP8266Shield/defines.h +++ b/examples/nRF52_ESP8266Shield/defines.h @@ -113,6 +113,28 @@ ///////////////////////////////////////////// +// Optional, to use Board Name in Menu +#define USING_BOARD_NAME false //true + +///////////////////////////////////////////// + +// Optional, to use Board Name in Menu +#define USING_CONFIG_MODE_LED true + +#if USING_CONFIG_MODE_LED + #if defined(LED_BUILTIN) + #define CONFIG_MODE_LED LED_BUILTIN + #else + // Using default pin 13 for CONFIG_MODE_LED. To be changed as necessary + #define CONFIG_MODE_LED 13 + #endif + + #define LED_ON HIGH + #define LED_OFF LOW +#endif + +///////////////////////////////////////////// + #include #define HOST_NAME "nRF52-ESP_AT" diff --git a/examples/nRF52_ESP8266Shield/nRF52_ESP8266Shield.ino b/examples/nRF52_ESP8266Shield/nRF52_ESP8266Shield.ino index 1b09e50..7e86465 100644 --- a/examples/nRF52_ESP8266Shield/nRF52_ESP8266Shield.ino +++ b/examples/nRF52_ESP8266Shield/nRF52_ESP8266Shield.ino @@ -23,7 +23,12 @@ void heartBeatPrint() if (ESP_AT_WiFiManager->getWiFiStatus()) Serial.print("H"); // H means connected to WiFi else - Serial.print("F"); // F means not connected to WiFi + { + if (ESP_AT_WiFiManager->isConfigMode()) + Serial.print("C"); // C means in Config Mode + else + Serial.print("F"); // F means not connected to WiFi + } if (num == 80) { diff --git a/keywords.txt b/keywords.txt index e0ccf4c..edfec3f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -57,3 +57,8 @@ ESP_AT_HTML_SCRIPT_ITEM LITERAL1 ESP_AT_HTML_SCRIPT_END LITERAL1 ESP_AT_HTML_END LITERAL1 +LED_ON LITERAL1 +LED_OFF LITERAL1 + +USING_BOARD_NAME LITERAL1 + diff --git a/library.json b/library.json index 178c192..94f28e3 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ESP_AT_WM_Lite", - "version": "1.5.1", + "version": "1.5.2", "keywords": "wifi, MultiWiFi, ESP8266-AT, ESP32-AT, SAM DUE, SAMD, nRF52, STM32, rpi-pico, rp2040, nano-rp2040-connect, Credentials, config-portal, dynamic-params, EEPROM, FlashStorage-SAMD, FlashStorage-STM32, LittleFS, DueFlashStorage, AVR Mega, Double-Reset, FlashStorage, light-weight", "description": "Light-Weight WiFi/Credentials Manager for AVR Mega, SAM DUE, SAMD21, SAMD51, nRF52, STM32, RP2040-based Nano_RP2040_connect, RASPBERRY_PI_PICO boards, etc. using ESP8266/ESP32-AT-command shields with web configuration portal. Powerful-yet-simple-to-use feature to enable adding dynamic custom parameters. You can also specify 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. Credentials and dynamic custom parameters are saved in EPROM, FlashStorage_SAMD, FlashStorage_STM32, FlashStorage_STM32F1, DueFlashStorage or nRF52/RP2040 LittleFS.", "authors": diff --git a/library.properties b/library.properties index 6680ba5..e716242 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP_AT_WM_Lite -version=1.5.1 +version=1.5.2 author=Khoi Hoang maintainer=Khoi Hoang license=MIT diff --git a/src/Esp8266_AT_WM_Lite.h b/src/Esp8266_AT_WM_Lite.h index 751ed27..5286b63 100644 --- a/src/Esp8266_AT_WM_Lite.h +++ b/src/Esp8266_AT_WM_Lite.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_h @@ -41,13 +32,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -140,7 +131,7 @@ extern ESP8266_AT_Configuration defaultConfig; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -225,7 +216,13 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif - + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif + //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); bool useConfigPortal = false; @@ -344,6 +341,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -432,12 +434,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -447,7 +454,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 12 // Channel 13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -462,7 +469,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -470,7 +477,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } @@ -556,6 +563,13 @@ class ESP_AT_WiFiManager_Lite return hadConfigData; } + ////////////////////////////////////////////// + + bool isConfigMode() + { + return configuration_mode; + } + ////////////////////////////////////////////// void resetFunc() @@ -591,7 +605,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.wifi_ssid, F(",PW="), configData.wifi_pw); @@ -1119,8 +1133,6 @@ class ESP_AT_WiFiManager_Lite String pitem; - - #if USE_DYNAMIC_PARAMETERS if (NUM_MENU_ITEMS > 0) { @@ -1338,6 +1350,11 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif + WiFi.configAP(portal_apIP); if ( (portal_ssid == "") || portal_pass == "" ) diff --git a/src/Esp8266_AT_WM_Lite_DUE.h b/src/Esp8266_AT_WM_Lite_DUE.h index 08b4126..d2f55d8 100644 --- a/src/Esp8266_AT_WM_Lite_DUE.h +++ b/src/Esp8266_AT_WM_Lite_DUE.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_DUE_h @@ -43,13 +34,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -168,10 +159,15 @@ typedef struct #define NUM_WIFI_CREDENTIALS 2 -// Configurable items besides fixed Header, just add board_name -#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#if USING_BOARD_NAME + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#else + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS )) +#endif -////////////////////////////////////////////// +//////////////// #define HEADER_MAX_LEN 16 #define BOARD_NAME_MAX_LEN 24 @@ -198,12 +194,20 @@ const char ESP_AT_HTML_HEAD_START[] /*PROGMEM*/ = "div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:#16A1E7;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}"; +#if USING_BOARD_NAME const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\
[[input_id]]
\
\
[[input_id1]]
\
\
"; // DO NOT CHANGE THIS STRING EVER!!!! +#else +const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! +#endif const char ESP_AT_HTML_INPUT_ID[] /*PROGMEM*/ = ""; const char ESP_AT_HTML_INPUT_ID1[] /*PROGMEM*/ = ""; @@ -212,12 +216,21 @@ const char ESP_AT_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_AT_FLDSET_END[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_PARAM[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_BUTTON[] /*PROGMEM*/ = "
"; -const char ESP_AT_HTML_SCRIPT[] /*PROGMEM*/ = ""; @@ -261,7 +274,7 @@ const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -357,7 +370,13 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif - + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif + //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); bool useConfigPortal = false; @@ -476,6 +495,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -564,12 +588,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -579,7 +608,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 11 // Channel 12,13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -594,7 +623,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -602,14 +631,14 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } ////////////////////////////////////////////// - String getWiFiSSID(uint8_t index) + String getWiFiSSID(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -622,7 +651,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - String getWiFiPW(uint8_t index) + String getWiFiPW(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -694,6 +723,13 @@ class ESP_AT_WiFiManager_Lite return hadConfigData; } + ////////////////////////////////////////////// + + bool isConfigMode() + { + return configuration_mode; + } + ////////////////////////////////////////////// void resetFunc() @@ -754,7 +790,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.WiFi_Creds[0].wifi_ssid, F(",PW="), configData.WiFi_Creds[0].wifi_pw); @@ -1552,7 +1588,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ESP8266_AT_config.WiFi_Creds[0].wifi_pw); result.replace("[[id1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_ssid); result.replace("[[pw1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_pw); + +#if USING_BOARD_NAME result.replace("[[nm]]", ESP8266_AT_config.board_name); +#endif } else { @@ -1560,7 +1599,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ""); result.replace("[[id1]]", ""); result.replace("[[pw1]]", ""); + +#if USING_BOARD_NAME result.replace("[[nm]]", ""); +#endif } #if USE_DYNAMIC_PARAMETERS @@ -1621,7 +1663,10 @@ class ESP_AT_WiFiManager_Lite static bool pw_Updated = false; static bool id1_Updated = false; static bool pw1_Updated = false; + +#if USING_BOARD_NAME static bool nm_Updated = false; +#endif if (!id_Updated && (key == String("id"))) { @@ -1671,18 +1716,19 @@ class ESP_AT_WiFiManager_Lite else strncpy(ESP8266_AT_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(ESP8266_AT_config.WiFi_Creds[1].wifi_pw) - 1); } +#if USING_BOARD_NAME else if (!nm_Updated && (key == String("nm"))) { ESP_AT_LOGDEBUG(F("h:repl nm")); nm_Updated = true; number_items_Updated++; - if (strlen(value.c_str()) < sizeof(ESP8266_AT_config.board_name) - 1) strcpy(ESP8266_AT_config.board_name, value.c_str()); else strncpy(ESP8266_AT_config.board_name, value.c_str(), sizeof(ESP8266_AT_config.board_name) - 1); - } + } +#endif else { @@ -1746,8 +1792,13 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { // ReInitialize ESP module - //WiFi.reInit(); - + //WiFi.reInit(); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif + #if SCAN_WIFI_NETWORKS configTimeout = 0; // To allow user input in CP @@ -1826,7 +1877,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - void setMinimumSignalQuality(int quality) + void setMinimumSignalQuality(const int& quality) { _minimumQuality = quality; } @@ -1834,7 +1885,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// //if this is true, remove duplicate Access Points - default true - void setRemoveDuplicateAPs(bool removeDuplicates) + void setRemoveDuplicateAPs(const bool& removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } @@ -1954,7 +2005,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - int getRSSIasQuality(int RSSI) + int getRSSIasQuality(const int& RSSI) { int quality = 0; diff --git a/src/Esp8266_AT_WM_Lite_Debug.h b/src/Esp8266_AT_WM_Lite_Debug.h index cee79c2..a4d4c73 100644 --- a/src/Esp8266_AT_WM_Lite_Debug.h +++ b/src/Esp8266_AT_WM_Lite_Debug.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL - 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_Debug_h diff --git a/src/Esp8266_AT_WM_Lite_Mbed_RPi_Pico.h b/src/Esp8266_AT_WM_Lite_Mbed_RPi_Pico.h index 55f97a9..774d935 100644 --- a/src/Esp8266_AT_WM_Lite_Mbed_RPi_Pico.h +++ b/src/Esp8266_AT_WM_Lite_Mbed_RPi_Pico.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_Mbed_RPi_Pico_h @@ -43,13 +34,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -170,10 +161,15 @@ typedef struct #define NUM_WIFI_CREDENTIALS 2 -// Configurable items besides fixed Header, just add board_name -#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#if USING_BOARD_NAME + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#else + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS )) +#endif -////////////////////////////////////////////// +//////////////// #define HEADER_MAX_LEN 16 #define BOARD_NAME_MAX_LEN 24 @@ -200,12 +196,20 @@ const char ESP_AT_HTML_HEAD_START[] /*PROGMEM*/ = "div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:#16A1E7;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}"; +#if USING_BOARD_NAME const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\
[[input_id]]
\
\
[[input_id1]]
\
\
"; // DO NOT CHANGE THIS STRING EVER!!!! +#else +const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! +#endif const char ESP_AT_HTML_INPUT_ID[] /*PROGMEM*/ = ""; const char ESP_AT_HTML_INPUT_ID1[] /*PROGMEM*/ = ""; @@ -214,12 +218,21 @@ const char ESP_AT_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_AT_FLDSET_END[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_PARAM[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_BUTTON[] /*PROGMEM*/ = "
"; -const char ESP_AT_HTML_SCRIPT[] /*PROGMEM*/ = ""; @@ -263,7 +276,7 @@ const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -359,7 +372,13 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif - + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif + //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); bool useConfigPortal = false; @@ -478,6 +497,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -566,12 +590,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -581,7 +610,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 11 // Channel 12,13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -596,7 +625,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -604,14 +633,14 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } ////////////////////////////////////////////// - String getWiFiSSID(uint8_t index) + String getWiFiSSID(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -624,7 +653,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - String getWiFiPW(uint8_t index) + String getWiFiPW(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -695,6 +724,13 @@ class ESP_AT_WiFiManager_Lite } ////////////////////////////////////////////// + + bool isConfigMode() + { + return configuration_mode; + } + + ////////////////////////////////////////////// #if 0 typedef struct @@ -797,7 +833,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.WiFi_Creds[0].wifi_ssid, F(",PW="), configData.WiFi_Creds[0].wifi_pw); @@ -834,6 +870,7 @@ class ESP_AT_WiFiManager_Lite int calcChecksum() { int checkSum = 0; + for (uint16_t index = 0; index < (sizeof(ESP8266_AT_config) - sizeof(ESP8266_AT_config.checkSum)); index++) { checkSum += * ( ( (byte*) &ESP8266_AT_config ) + index); @@ -1727,7 +1764,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ESP8266_AT_config.WiFi_Creds[0].wifi_pw); result.replace("[[id1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_ssid); result.replace("[[pw1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_pw); + +#if USING_BOARD_NAME result.replace("[[nm]]", ESP8266_AT_config.board_name); +#endif } else { @@ -1735,7 +1775,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ""); result.replace("[[id1]]", ""); result.replace("[[pw1]]", ""); + +#if USING_BOARD_NAME result.replace("[[nm]]", ""); +#endif } #if USE_DYNAMIC_PARAMETERS @@ -1796,7 +1839,10 @@ class ESP_AT_WiFiManager_Lite static bool pw_Updated = false; static bool id1_Updated = false; static bool pw1_Updated = false; + +#if USING_BOARD_NAME static bool nm_Updated = false; +#endif if (!id_Updated && (key == String("id"))) { @@ -1846,20 +1892,20 @@ class ESP_AT_WiFiManager_Lite else strncpy(ESP8266_AT_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(ESP8266_AT_config.WiFi_Creds[1].wifi_pw) - 1); } +#if USING_BOARD_NAME else if (!nm_Updated && (key == String("nm"))) { ESP_AT_LOGDEBUG(F("h:repl nm")); nm_Updated = true; number_items_Updated++; - if (strlen(value.c_str()) < sizeof(ESP8266_AT_config.board_name) - 1) strcpy(ESP8266_AT_config.board_name, value.c_str()); else strncpy(ESP8266_AT_config.board_name, value.c_str(), sizeof(ESP8266_AT_config.board_name) - 1); - } + } +#endif - #if USE_DYNAMIC_PARAMETERS else { @@ -1922,8 +1968,13 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { // ReInitialize ESP module - //WiFi.reInit(); - + //WiFi.reInit(); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif + #if SCAN_WIFI_NETWORKS configTimeout = 0; // To allow user input in CP @@ -2003,7 +2054,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - void setMinimumSignalQuality(int quality) + void setMinimumSignalQuality(const int& quality) { _minimumQuality = quality; } @@ -2011,7 +2062,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// //if this is true, remove duplicate Access Points - default true - void setRemoveDuplicateAPs(bool removeDuplicates) + void setRemoveDuplicateAPs(const bool& removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } @@ -2131,7 +2182,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - int getRSSIasQuality(int RSSI) + int getRSSIasQuality(const int& RSSI) { int quality = 0; diff --git a/src/Esp8266_AT_WM_Lite_RPi_Pico.h b/src/Esp8266_AT_WM_Lite_RPi_Pico.h index 44a5051..8d9bfb2 100644 --- a/src/Esp8266_AT_WM_Lite_RPi_Pico.h +++ b/src/Esp8266_AT_WM_Lite_RPi_Pico.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_RPi_Pico_h @@ -43,13 +34,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -172,10 +163,15 @@ typedef struct #define NUM_WIFI_CREDENTIALS 2 -// Configurable items besides fixed Header, just add board_name -#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#if USING_BOARD_NAME + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#else + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS )) +#endif -////////////////////////////////////////////// +//////////////// #define HEADER_MAX_LEN 16 #define BOARD_NAME_MAX_LEN 24 @@ -202,12 +198,20 @@ const char ESP_AT_HTML_HEAD_START[] /*PROGMEM*/ = "div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:#16A1E7;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}"; +#if USING_BOARD_NAME const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\
[[input_id]]
\
\
[[input_id1]]
\
\
"; // DO NOT CHANGE THIS STRING EVER!!!! +#else +const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! +#endif const char ESP_AT_HTML_INPUT_ID[] /*PROGMEM*/ = ""; const char ESP_AT_HTML_INPUT_ID1[] /*PROGMEM*/ = ""; @@ -216,12 +220,21 @@ const char ESP_AT_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_AT_FLDSET_END[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_PARAM[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_BUTTON[] /*PROGMEM*/ = "
"; -const char ESP_AT_HTML_SCRIPT[] /*PROGMEM*/ = ""; @@ -265,7 +278,7 @@ const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -361,6 +374,12 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); @@ -480,6 +499,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -568,12 +592,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -583,7 +612,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 11 // Channel 12,13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -598,7 +627,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -606,14 +635,14 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } ////////////////////////////////////////////// - String getWiFiSSID(uint8_t index) + String getWiFiSSID(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -626,7 +655,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - String getWiFiPW(uint8_t index) + String getWiFiPW(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -698,6 +727,13 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// + bool isConfigMode() + { + return configuration_mode; + } + + ////////////////////////////////////////////// + typedef struct { uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ @@ -798,7 +834,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.WiFi_Creds[0].wifi_ssid, F(",PW="), configData.WiFi_Creds[0].wifi_pw); @@ -1731,7 +1767,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ESP8266_AT_config.WiFi_Creds[0].wifi_pw); result.replace("[[id1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_ssid); result.replace("[[pw1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_pw); + +#if USING_BOARD_NAME result.replace("[[nm]]", ESP8266_AT_config.board_name); +#endif } else { @@ -1739,7 +1778,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ""); result.replace("[[id1]]", ""); result.replace("[[pw1]]", ""); + +#if USING_BOARD_NAME result.replace("[[nm]]", ""); +#endif } #if USE_DYNAMIC_PARAMETERS @@ -1800,7 +1842,10 @@ class ESP_AT_WiFiManager_Lite static bool pw_Updated = false; static bool id1_Updated = false; static bool pw1_Updated = false; + +#if USING_BOARD_NAME static bool nm_Updated = false; +#endif if (!id_Updated && (key == String("id"))) { @@ -1850,18 +1895,19 @@ class ESP_AT_WiFiManager_Lite else strncpy(ESP8266_AT_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(ESP8266_AT_config.WiFi_Creds[1].wifi_pw) - 1); } +#if USING_BOARD_NAME else if (!nm_Updated && (key == String("nm"))) { ESP_AT_LOGDEBUG(F("h:repl nm")); nm_Updated = true; number_items_Updated++; - if (strlen(value.c_str()) < sizeof(ESP8266_AT_config.board_name) - 1) strcpy(ESP8266_AT_config.board_name, value.c_str()); else strncpy(ESP8266_AT_config.board_name, value.c_str(), sizeof(ESP8266_AT_config.board_name) - 1); - } + } +#endif else { @@ -1925,7 +1971,12 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { // ReInitialize ESP module - //WiFi.reInit(); + //WiFi.reInit(); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif #if SCAN_WIFI_NETWORKS configTimeout = 0; // To allow user input in CP @@ -2006,7 +2057,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - void setMinimumSignalQuality(int quality) + void setMinimumSignalQuality(const int& quality) { _minimumQuality = quality; } @@ -2014,7 +2065,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// //if this is true, remove duplicate Access Points - default true - void setRemoveDuplicateAPs(bool removeDuplicates) + void setRemoveDuplicateAPs(const bool& removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } diff --git a/src/Esp8266_AT_WM_Lite_SAMD.h b/src/Esp8266_AT_WM_Lite_SAMD.h index 0297588..cfb06b1 100644 --- a/src/Esp8266_AT_WM_Lite_SAMD.h +++ b/src/Esp8266_AT_WM_Lite_SAMD.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_SAMD_h @@ -49,13 +40,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -171,10 +162,15 @@ typedef struct #define NUM_WIFI_CREDENTIALS 2 -// Configurable items besides fixed Header, just add board_name -#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#if USING_BOARD_NAME + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#else + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS )) +#endif -////////////////////////////////////////////// +//////////////// #define HEADER_MAX_LEN 16 #define BOARD_NAME_MAX_LEN 24 @@ -201,12 +197,20 @@ const char ESP_AT_HTML_HEAD_START[] /*PROGMEM*/ = "div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:#16A1E7;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}"; +#if USING_BOARD_NAME const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\
[[input_id]]
\
\
[[input_id1]]
\
\
"; // DO NOT CHANGE THIS STRING EVER!!!! +#else +const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! +#endif const char ESP_AT_HTML_INPUT_ID[] /*PROGMEM*/ = ""; const char ESP_AT_HTML_INPUT_ID1[] /*PROGMEM*/ = ""; @@ -215,12 +219,21 @@ const char ESP_AT_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_AT_FLDSET_END[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_PARAM[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_BUTTON[] /*PROGMEM*/ = "
"; -const char ESP_AT_HTML_SCRIPT[] /*PROGMEM*/ = ""; @@ -264,7 +277,7 @@ const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -360,7 +373,13 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif - + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif + //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); bool useConfigPortal = false; @@ -479,6 +498,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -567,12 +591,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -582,7 +611,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 11 // Channel 12,13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -597,7 +626,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -605,14 +634,14 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } ////////////////////////////////////////////// - String getWiFiSSID(uint8_t index) + String getWiFiSSID(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -625,7 +654,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - String getWiFiPW(uint8_t index) + String getWiFiPW(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -697,6 +726,13 @@ class ESP_AT_WiFiManager_Lite return hadConfigData; } + ////////////////////////////////////////////// + + bool isConfigMode() + { + return configuration_mode; + } + ////////////////////////////////////////////// void resetFunc() @@ -757,7 +793,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.WiFi_Creds[0].wifi_ssid, F(",PW="), configData.WiFi_Creds[0].wifi_pw); @@ -1515,7 +1551,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ESP8266_AT_config.WiFi_Creds[0].wifi_pw); result.replace("[[id1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_ssid); result.replace("[[pw1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_pw); + +#if USING_BOARD_NAME result.replace("[[nm]]", ESP8266_AT_config.board_name); +#endif } else { @@ -1523,7 +1562,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ""); result.replace("[[id1]]", ""); result.replace("[[pw1]]", ""); + +#if USING_BOARD_NAME result.replace("[[nm]]", ""); +#endif } #if USE_DYNAMIC_PARAMETERS @@ -1584,7 +1626,10 @@ class ESP_AT_WiFiManager_Lite static bool pw_Updated = false; static bool id1_Updated = false; static bool pw1_Updated = false; + +#if USING_BOARD_NAME static bool nm_Updated = false; +#endif if (!id_Updated && (key == String("id"))) { @@ -1634,18 +1679,19 @@ class ESP_AT_WiFiManager_Lite else strncpy(ESP8266_AT_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(ESP8266_AT_config.WiFi_Creds[1].wifi_pw) - 1); } +#if USING_BOARD_NAME else if (!nm_Updated && (key == String("nm"))) { ESP_AT_LOGDEBUG(F("h:repl nm")); nm_Updated = true; number_items_Updated++; - if (strlen(value.c_str()) < sizeof(ESP8266_AT_config.board_name) - 1) strcpy(ESP8266_AT_config.board_name, value.c_str()); else strncpy(ESP8266_AT_config.board_name, value.c_str(), sizeof(ESP8266_AT_config.board_name) - 1); - } + } +#endif else { @@ -1709,8 +1755,13 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { // ReInitialize ESP module - //WiFi.reInit(); - + //WiFi.reInit(); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif + #if SCAN_WIFI_NETWORKS configTimeout = 0; // To allow user input in CP @@ -1789,7 +1840,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - void setMinimumSignalQuality(int quality) + void setMinimumSignalQuality(const int& quality) { _minimumQuality = quality; } @@ -1797,7 +1848,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// //if this is true, remove duplicate Access Points - default true - void setRemoveDuplicateAPs(bool removeDuplicates) + void setRemoveDuplicateAPs(const bool& removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } @@ -1917,7 +1968,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - int getRSSIasQuality(int RSSI) + int getRSSIasQuality(const int& RSSI) { int quality = 0; diff --git a/src/Esp8266_AT_WM_Lite_STM32.h b/src/Esp8266_AT_WM_Lite_STM32.h index 71e06e3..7f44d7b 100644 --- a/src/Esp8266_AT_WM_Lite_STM32.h +++ b/src/Esp8266_AT_WM_Lite_STM32.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_STM32_h @@ -44,13 +35,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -166,10 +157,15 @@ typedef struct #define NUM_WIFI_CREDENTIALS 2 -// Configurable items besides fixed Header, just add board_name -#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#if USING_BOARD_NAME + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#else + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS )) +#endif -////////////////////////////////////////////// +//////////////// #define HEADER_MAX_LEN 16 #define BOARD_NAME_MAX_LEN 24 @@ -196,12 +192,20 @@ const char ESP_AT_HTML_HEAD_START[] /*PROGMEM*/ = "div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:#16A1E7;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}"; +#if USING_BOARD_NAME const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\
[[input_id]]
\
\
[[input_id1]]
\
\
"; // DO NOT CHANGE THIS STRING EVER!!!! +#else +const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! +#endif const char ESP_AT_HTML_INPUT_ID[] /*PROGMEM*/ = ""; const char ESP_AT_HTML_INPUT_ID1[] /*PROGMEM*/ = ""; @@ -210,12 +214,21 @@ const char ESP_AT_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_AT_FLDSET_END[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_PARAM[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_BUTTON[] /*PROGMEM*/ = "
"; -const char ESP_AT_HTML_SCRIPT[] /*PROGMEM*/ = ""; @@ -259,7 +272,7 @@ const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -355,7 +368,13 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif - + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif + //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); bool useConfigPortal = false; @@ -474,6 +493,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -562,12 +586,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -577,7 +606,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 11 // Channel 12,13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -592,7 +621,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -600,14 +629,14 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } ////////////////////////////////////////////// - String getWiFiSSID(uint8_t index) + String getWiFiSSID(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -620,7 +649,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - String getWiFiPW(uint8_t index) + String getWiFiPW(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -692,6 +721,13 @@ class ESP_AT_WiFiManager_Lite return hadConfigData; } + ////////////////////////////////////////////// + + bool isConfigMode() + { + return configuration_mode; + } + ////////////////////////////////////////////// void resetFunc() @@ -759,7 +795,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.WiFi_Creds[0].wifi_ssid, F(",PW="), configData.WiFi_Creds[0].wifi_pw); @@ -1556,7 +1592,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ESP8266_AT_config.WiFi_Creds[0].wifi_pw); result.replace("[[id1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_ssid); result.replace("[[pw1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_pw); + +#if USING_BOARD_NAME result.replace("[[nm]]", ESP8266_AT_config.board_name); +#endif } else { @@ -1564,7 +1603,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ""); result.replace("[[id1]]", ""); result.replace("[[pw1]]", ""); + +#if USING_BOARD_NAME result.replace("[[nm]]", ""); +#endif } #if USE_DYNAMIC_PARAMETERS @@ -1625,7 +1667,10 @@ class ESP_AT_WiFiManager_Lite static bool pw_Updated = false; static bool id1_Updated = false; static bool pw1_Updated = false; + +#if USING_BOARD_NAME static bool nm_Updated = false; +#endif if (!id_Updated && (key == String("id"))) { @@ -1675,18 +1720,19 @@ class ESP_AT_WiFiManager_Lite else strncpy(ESP8266_AT_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(ESP8266_AT_config.WiFi_Creds[1].wifi_pw) - 1); } +#if USING_BOARD_NAME else if (!nm_Updated && (key == String("nm"))) { ESP_AT_LOGDEBUG(F("h:repl nm")); nm_Updated = true; number_items_Updated++; - if (strlen(value.c_str()) < sizeof(ESP8266_AT_config.board_name) - 1) strcpy(ESP8266_AT_config.board_name, value.c_str()); else strncpy(ESP8266_AT_config.board_name, value.c_str(), sizeof(ESP8266_AT_config.board_name) - 1); - } + } +#endif else { @@ -1750,8 +1796,13 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { // ReInitialize ESP module - //WiFi.reInit(); - + //WiFi.reInit(); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif + #if SCAN_WIFI_NETWORKS configTimeout = 0; // To allow user input in CP @@ -1830,7 +1881,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - void setMinimumSignalQuality(int quality) + void setMinimumSignalQuality(const int& quality) { _minimumQuality = quality; } @@ -1838,7 +1889,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// //if this is true, remove duplicate Access Points - default true - void setRemoveDuplicateAPs(bool removeDuplicates) + void setRemoveDuplicateAPs(const bool& removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } @@ -1958,7 +2009,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - int getRSSIasQuality(int RSSI) + int getRSSIasQuality(const int& RSSI) { int quality = 0; diff --git a/src/Esp8266_AT_WM_Lite_nRF52.h b/src/Esp8266_AT_WM_Lite_nRF52.h index 1dab967..ad8d495 100644 --- a/src/Esp8266_AT_WM_Lite_nRF52.h +++ b/src/Esp8266_AT_WM_Lite_nRF52.h @@ -8,25 +8,16 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite Licensed under MIT license - Version: 1.5.1 + Version: 1.5.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 09/03/2020 Initial coding - 1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch - 1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars. - Permit to input special chars such as !,@,#,$,%,^,&,* into data fields. - 1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc. - Add DRD support. Add MultiWiFi support - 1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic. - Enhance MultiWiFi connection logic. Fix WiFi Status bug. - 1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials - 1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal - 1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core - 1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core - 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json` + ... 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL 1.5.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. Add support to more SAMD/STM32 boards + 1.5.2 K Hoang 22/02/2022 Optional Board_Name in Menu. Optimize code by using passing by reference + Add optional CONFIG_MODE_LED. Add function isConfigMode() ***************************************************************************************************************************************/ #ifndef Esp8266_AT_WM_Lite_nRF52_h @@ -45,13 +36,13 @@ #endif #ifndef ESP_AT_WM_LITE_VERSION - #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.1" + #define ESP_AT_WM_LITE_VERSION "ESP_AT_WM_Lite v1.5.2" #define ESP_AT_WM_LITE_VERSION_MAJOR 1 #define ESP_AT_WM_LITE_VERSION_MINOR 5 - #define ESP_AT_WM_LITE_VERSION_PATCH 1 + #define ESP_AT_WM_LITE_VERSION_PATCH 2 - #define ESP_AT_WM_LITE_VERSION_INT 1005001 + #define ESP_AT_WM_LITE_VERSION_INT 1005002 #endif @@ -173,10 +164,15 @@ typedef struct #define NUM_WIFI_CREDENTIALS 2 -// Configurable items besides fixed Header, just add board_name -#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#if USING_BOARD_NAME + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 ) +#else + // Configurable items besides fixed Header, just add board_name + #define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS )) +#endif -////////////////////////////////////////////// +//////////////// #define HEADER_MAX_LEN 16 #define BOARD_NAME_MAX_LEN 24 @@ -203,12 +199,20 @@ const char ESP_AT_HTML_HEAD_START[] /*PROGMEM*/ = "div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}button{background-color:#16A1E7;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}"; +#if USING_BOARD_NAME const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\
[[input_id]]
\
\
[[input_id1]]
\
\
"; // DO NOT CHANGE THIS STRING EVER!!!! +#else +const char ESP_AT_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! +#endif const char ESP_AT_HTML_INPUT_ID[] /*PROGMEM*/ = ""; const char ESP_AT_HTML_INPUT_ID1[] /*PROGMEM*/ = ""; @@ -217,12 +221,21 @@ const char ESP_AT_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_AT_FLDSET_END[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_PARAM[] /*PROGMEM*/ = "
"; const char ESP_AT_HTML_BUTTON[] /*PROGMEM*/ = "
"; -const char ESP_AT_HTML_SCRIPT[] /*PROGMEM*/ = ""; @@ -266,7 +279,7 @@ const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; ////////////////////////////////////////////// -String IPAddressToString(IPAddress _address) +String IPAddressToString(const IPAddress& _address) { String str = String(_address[0]); str += "."; @@ -362,7 +375,13 @@ class ESP_AT_WiFiManager_Lite if (NUM_MENU_ITEMS > 3) NUM_MENU_ITEMS = 3; #endif - + +#if USING_CONFIG_MODE_LED + //Turn OFF + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LED_OFF); +#endif + //// New DRD //// drd = new DoubleResetDetector_Generic(DRD_TIMEOUT, DRD_ADDRESS); bool useConfigPortal = false; @@ -481,6 +500,11 @@ class ESP_AT_WiFiManager_Lite if (WiFi.status() == WL_CONNECTED) { wifi_connected = true; + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } else { @@ -569,12 +593,17 @@ class ESP_AT_WiFiManager_Lite { configuration_mode = false; ESP_AT_LOGERROR(F("r:gotWBack")); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN OFF to tell us we exit configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_OFF); +#endif } } ////////////////////////////////////////////// - void setConfigPortalIP(IPAddress portalIP = IPAddress(192, 168, 4, 1)) + void setConfigPortalIP(const IPAddress& portalIP = IPAddress(192, 168, 4, 1)) { portal_apIP = portalIP; } @@ -584,7 +613,7 @@ class ESP_AT_WiFiManager_Lite #define MIN_WIFI_CHANNEL 1 #define MAX_WIFI_CHANNEL 11 // Channel 12,13 is flaky, because of bad number 13 ;-) - int setConfigPortalChannel(int channel = 1) + int setConfigPortalChannel(const int& channel = 1) { // If channel < MIN_WIFI_CHANNEL - 1 or channel > MAX_WIFI_CHANNEL => channel = 1 // If channel == 0 => will use random channel from MIN_WIFI_CHANNEL to MAX_WIFI_CHANNEL @@ -599,7 +628,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setConfigPortal(String ssid = "", String pass = "") + void setConfigPortal(const String& ssid = "", const String& pass = "") { portal_ssid = ssid; portal_pass = pass; @@ -607,14 +636,14 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - void setSTAStaticIPConfig(IPAddress ip) + void setSTAStaticIPConfig(const IPAddress& ip) { static_IP = ip; } ////////////////////////////////////////////// - String getWiFiSSID(uint8_t index) + String getWiFiSSID(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -627,7 +656,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////////// - String getWiFiPW(uint8_t index) + String getWiFiPW(const uint8_t& index) { if (index >= NUM_WIFI_CREDENTIALS) return String(""); @@ -697,6 +726,13 @@ class ESP_AT_WiFiManager_Lite return hadConfigData; } + ////////////////////////////////////////////// + + bool isConfigMode() + { + return configuration_mode; + } + ////////////////////////////////////////////// void resetFunc() @@ -761,7 +797,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////// - void displayConfigData(ESP8266_AT_Configuration configData) + void displayConfigData(const ESP8266_AT_Configuration& configData) { ESP_AT_LOGDEBUG5(F("Hdr="), configData.header, F(",SSID="), configData.WiFi_Creds[0].wifi_ssid, F(",PW="), configData.WiFi_Creds[0].wifi_pw); @@ -1684,7 +1720,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ESP8266_AT_config.WiFi_Creds[0].wifi_pw); result.replace("[[id1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_ssid); result.replace("[[pw1]]", ESP8266_AT_config.WiFi_Creds[1].wifi_pw); + +#if USING_BOARD_NAME result.replace("[[nm]]", ESP8266_AT_config.board_name); +#endif } else { @@ -1692,7 +1731,10 @@ class ESP_AT_WiFiManager_Lite result.replace("[[pw]]", ""); result.replace("[[id1]]", ""); result.replace("[[pw1]]", ""); + +#if USING_BOARD_NAME result.replace("[[nm]]", ""); +#endif } #if USE_DYNAMIC_PARAMETERS @@ -1753,7 +1795,10 @@ class ESP_AT_WiFiManager_Lite static bool pw_Updated = false; static bool id1_Updated = false; static bool pw1_Updated = false; + +#if USING_BOARD_NAME static bool nm_Updated = false; +#endif if (!id_Updated && (key == String("id"))) { @@ -1803,18 +1848,19 @@ class ESP_AT_WiFiManager_Lite else strncpy(ESP8266_AT_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(ESP8266_AT_config.WiFi_Creds[1].wifi_pw) - 1); } +#if USING_BOARD_NAME else if (!nm_Updated && (key == String("nm"))) { ESP_AT_LOGDEBUG(F("h:repl nm")); nm_Updated = true; number_items_Updated++; - if (strlen(value.c_str()) < sizeof(ESP8266_AT_config.board_name) - 1) strcpy(ESP8266_AT_config.board_name, value.c_str()); else strncpy(ESP8266_AT_config.board_name, value.c_str(), sizeof(ESP8266_AT_config.board_name) - 1); - } + } +#endif else { @@ -1878,8 +1924,13 @@ class ESP_AT_WiFiManager_Lite void startConfigurationMode() { // ReInitialize ESP module - //WiFi.reInit(); - + //WiFi.reInit(); + +#if USING_CONFIG_MODE_LED + // turn the LED_BUILTIN ON to tell us we enter configuration mode. + digitalWrite(CONFIG_MODE_LED, LED_ON); +#endif + #if SCAN_WIFI_NETWORKS configTimeout = 0; // To allow user input in CP @@ -1958,7 +2009,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - void setMinimumSignalQuality(int quality) + void setMinimumSignalQuality(const int& quality) { _minimumQuality = quality; } @@ -1966,7 +2017,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// //if this is true, remove duplicate Access Points - default true - void setRemoveDuplicateAPs(bool removeDuplicates) + void setRemoveDuplicateAPs(const bool& removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } @@ -2086,7 +2137,7 @@ class ESP_AT_WiFiManager_Lite ////////////////////////////////////////// - int getRSSIasQuality(int RSSI) + int getRSSIasQuality(const int& RSSI) { int quality = 0;