diff --git a/README.md b/README.md index 812bc3a..64425e8 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ * [Features](#features) * [Currently supported Boards](#currently-supported-boards) * [Changelog](#changelog) + * [Major Release v1.5.0](#major-release-v150) * [Release v1.4.0](#release-v140) * [Release v1.3.0](#release-v130) * [Release v1.2.0](#release-v120) @@ -59,6 +60,12 @@ * [9. To use custom Head Elements](#9-to-use-custom-head-elements) * [10. To use CORS Header](#10-to-use-cors-header) * [11. To use and input only one set of WiFi SSID and PWD](#11-to-use-and-input-only-one-set-of-wifi-ssid-and-pwd) + * [11.1 If you need to use and input only one set of WiFi SSID/PWD](#111-if-you-need-to-use-and-input-only-one-set-of-wifi-ssidpwd) + * [11.2 If you need to use both sets of WiFi SSID/PWD](#112-if-you-need-to-use-both-sets-of-wifi-ssidpwd) + * [12. To enable auto-scan of WiFi networks for selection in Configuration Portal](#12-to-enable-auto-scan-of-wifi-networks-for-selection-in-configuration-portal) + * [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) * [Examples](#examples) * [ 1. ESP_WiFi](examples/ESP_WiFi) * [ 2. ESP_WiFi_MQTT](examples/ESP_WiFi_MQTT) @@ -90,7 +97,10 @@ * [3.3 Lost a WiFi and autoconnect to another WiFi AP](#33-lost-a-wifi-and-autoconnect-to-another-wifi-ap) * [4. ESP_WiFi_MQTT on ESP32S2_DEV to demo MultiResetDetector](#4-esp_wifi_mqtt-on-esp32s2_dev-to-demo-multiresetdetector) * [4.1 MultiResetDetected => Open Config Portal](#41-multiresetdetected--open-config-portal) - * [4.2 Got valid Credentials from Config Portal then connected to WiFi](#42-got-valid-credentials-from-config-portal-then-connected-to-wifi) + * [4.2 Got valid Credentials from Config Portal then connected to WiFi](#42-got-valid-credentials-from-config-portal-then-connected-to-wifi) + * [5. ESP_WiFi_MQTT on ESP32_DEV to demo WiFi Scan](#5-esp_wifi_mqtt-on-esp32_dev-to-demo-wifi-scan) + * [5.1 MRD/DRD => Open Config Portal](#51-mrddrd--open-config-portal) + * [5.2 Config Data Saved => Connection to Adafruit MQTT](#52-config-data-saved--connection-to-adafruit-mqtt) * [Debug](#debug) * [Troubleshooting](#troubleshooting) * [Releases](#releases) @@ -135,20 +145,28 @@ New recent features: - Control Config Portal from software or Virtual Switches - To permit autoreset after configurable timeout if DRD/MRD or non-persistent forced-CP - Use new ESP32 LittleFS features +- **Scan WiFi networks** for selection in Configuration Portal #### Currently supported Boards This [**ESP_WiFiManager_Lite** library](https://github.com/khoih-prog/ESP_WiFiManager_Lite) currently supports these following boards: - 1. **ESP32 including ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.)** - 2. **ESP8266** + 1. **ESP8266 and ESP32-based boards using EEPROM, SPIFFS or LittleFS**. + 2. **ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.) using EEPROM, SPIFFS or LittleFS**. + 3. **ESP32-C3 (ARDUINO_ESP32C3_DEV) using EEPROM or SPIFFS**. --- --- ## Changelog +### Major Release v1.5.0 + +1. 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). Now you can select optional **SCAN_WIFI_NETWORKS**, **MANUAL_SSID_INPUT_ALLOWED** to be able to manually input SSID, not only from a scanned SSID lists and **MAX_SSID_IN_LIST** (from 2-6 for ESP8266-AT or 2-15 for other) +2. Minor enhancement to not display garbage when data is invalid + + ### Release v1.4.0 1. Add **LittleFS and SPIFFS** support to new **ESP32-S2** boards (**Arduino ESP32C3_DEV**). Check [HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE](#howto-install-esp32-core-for-esp32-s2-saola-ai-thinker-esp-12k-and-esp32-c3-boards-into-arduino-ide). @@ -628,7 +646,7 @@ Once Credentials / WiFi network information is saved in the host non-volatile me #### 11. To use and input only one set of WiFi SSID and PWD -#### If you need to use and input only one set of WiFi SSID/PWD. +#### 11.1 If you need to use and input only one set of WiFi SSID/PWD ``` // Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank" @@ -637,7 +655,7 @@ Once Credentials / WiFi network information is saved in the host non-volatile me ``` But it's always advisable to use and input both sets for reliability. -#### If you need to use both sets of WiFi SSID/PWD +#### 11.2 If you need to use both sets of WiFi SSID/PWD ``` // Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank" @@ -645,6 +663,37 @@ But it's always advisable to use and input both sets for reliability. #define REQUIRE_ONE_SET_SSID_PW false ``` +#### 12. To enable auto-scan of WiFi networks for selection in Configuration Portal + +#### 12.1 Enable auto-scan of WiFi networks for selection in Configuration Portal + + +``` +#define SCAN_WIFI_NETWORKS true +``` + +The manual input of SSIDs is default enabled, so that users can input arbitrary SSID, not only from the scanned list. This is for the sample use-cases in which users can input the known SSIDs of another place, then send the boards to that place. The boards can connect to WiFi without users entering Config Portal to re-configure. + +#### 12.2 Disable manually input SSIDs + +``` +// To disable manually input SSID, only from a scanned SSID lists +#define MANUAL_SSID_INPUT_ALLOWED false +``` + +This is for normal use-cases in which users can only select an SSID from a scanned list of SSIDs to avoid typo mistakes and/or security. + +#### 12.3 Select maximum number of SSIDs in the list + +The maximum number of SSIDs in the list is seletable from 2 to 15. If invalid number of SSIDs is selected, the default number of 10 will be used. + + +``` +// From 2-15 +#define MAX_SSID_IN_LIST 8 +``` + + --- --- @@ -668,10 +717,28 @@ After you connected, please, go to http://192.168.4.1 or newly configured AP IP, Enter your credentials, +### 1. Without SCAN_WIFI_NETWORKS + +Enter your credentials, + +

+ +

+ +or +

+### 2. With SCAN_WIFI_NETWORKS + + +

+ +

+ + then click `Save`.

@@ -1125,6 +1192,16 @@ void loop() ///////////////////////////////////////////// +#define SCAN_WIFI_NETWORKS true + +// To be able to manually input SSID, not from a scanned SSID lists +#define MANUAL_SSID_INPUT_ALLOWED true + +// From 2-15 + #define MAX_SSID_IN_LIST 8 + +///////////////////////////////////////////// + #include #if ESP8266 @@ -1317,7 +1394,7 @@ This is the terminal output when running [**ESP_WiFi**](examples/ESP_WiFi) examp ``` Starting ESP_WiFi using LittleFS on ESP32_DEV -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFC0003 multiResetDetectorFlag = 0xFFFC0003 @@ -1388,7 +1465,7 @@ FFFFFFFFF ``` Starting ESP_WiFi using LittleFS on ESP32_DEV -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFE0001 multiResetDetectorFlag = 0xFFFE0001 @@ -1460,7 +1537,7 @@ This is the terminal output when running [**ESP_WiFi_MQTT**](examples/ESP_WiFi_M ``` Starting ESP_WiFi_MQTT using LittleFS on ESP8266_NODEMCU -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFE0001 multiResetDetectorFlag = 0xFFFE0001 @@ -1535,7 +1612,7 @@ NNN Starting ESP_WiFi_MQTT using LittleFS on ESP8266_NODEMCU -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFE0001 multiResetDetectorFlag = 0xFFFE0001 @@ -1627,7 +1704,7 @@ This is the terminal output when running [**ESP_WiFi_MQTT**](examples/ESP_WiFi_M ``` Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFE0001 multiResetDetectorFlag = 0xFFFE0001 @@ -1740,7 +1817,7 @@ entry 0x4004c190 Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFE0001 multiResetDetectorFlag = 0xFFFE0001 @@ -1842,7 +1919,7 @@ This is the terminal output when running [**ESP_WiFi_MQTT**](examples/ESP_WiFi_M ``` Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFC0003 multiResetDetectorFlag = 0xFFFC0003 @@ -1870,7 +1947,7 @@ NNNN NNNNN NNNNN NNNNN NN[WML] h:UpdLittleFS ``` Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_DEV -ESP_WiFiManager_Lite v1.4.0 +ESP_WiFiManager_Lite v1.5.0 ESP_MultiResetDetector v1.1.1 LittleFS Flag read = 0xFFFE0001 multiResetDetectorFlag = 0xFFFE0001 @@ -1916,6 +1993,98 @@ AIO_SUB_TOPIC = /feeds/LED_Control TWTWTWTW TWTWTWTWTW TWTW ``` +--- + +### 5. [ESP_WiFi_MQTT](examples/ESP_WiFi_MQTT) on ESP32_DEV to demo WiFi Scan + +This is the terminal output when running [**ESP_WiFi**](examples/ESP_WiFi) example on **ESP32_DEV** with WiFi Scan for selection in Configuration Portal + +#### 5.1. MRD/DRD => Open Config Portal + +``` +Starting ESP_WiFi_MQTT using LittleFS on ESP32_DEV +ESP_WiFiManager_Lite v1.5.0 +ESP_MultiResetDetector v1.1.1 +LittleFS Flag read = 0xFFFC0003 +multiResetDetectorFlag = 0xFFFC0003 +lowerBytes = 0x0003, upperBytes = 0x0003 +multiResetDetected, number of times = 3 +Saving config file... +Saving config file OK +[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678 +[WML] SSID1=HueNet2,PW1=12345678 +[WML] BName=ESP32_DEV +[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678 +[WML] SSID1=HueNet2,PW1=12345678 +[WML] BName=ESP32_DEV +[WML] WiFi networks found: +[WML] 1: HueNet, -24dB +[WML] 2: HueNet1, -31dB +[WML] 3: HueNetTek, -33dB +[WML] 4: dragino-1ed63c, -33dB +[WML] 5: HueNet2, -57dB +[WML] 6: bacau, -72dB +[WML] 7: guest_24, -72dB +[WML] 8: Waterhome, -91dB +[WML] 9: BAHFAMILY, -93dB +[WML] 10: TP-LINK_2.4GHz_9A67ED, -94dB +[WML] 11: Access 2.0, -96dB +[WML] +stConf:SSID=ESP_9ABF498,PW=MyESP_9ABF498 +[WML] IP=192.168.4.1,ch=11 +N +Your stored Credentials : +AIO_SERVER = io.adafruit.com +AIO_SERVERPORT = 1883 +AIO_USERNAME = private +AIO_KEY = private +AIO_PUB_TOPIC = /feeds/Temperature +AIO_SUB_TOPIC = /feeds/LED_Control +N +``` + +### 2. Config Data Saved => Connection to Adafruit MQTT + +``` +Starting ESP_WiFi_MQTT using LittleFS on ESP32_DEV +ESP_WiFiManager_Lite v1.5.0 +ESP_MultiResetDetector v1.1.1 +LittleFS Flag read = 0xFFFE0001 +multiResetDetectorFlag = 0xFFFE0001 +lowerBytes = 0x0001, upperBytes = 0x0001 +No multiResetDetected, number of times = 1 +LittleFS Flag read = 0xFFFE0001 +Saving config file... +Saving config file OK +[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678 +[WML] SSID1=HueNet2,PW1=12345678 +[WML] BName=ESP32_DEV +[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678 +[WML] SSID1=HueNet2,PW1=12345678 +[WML] BName=ESP32_DEV +[WML] WiFi connected after time: 1 +[WML] SSID=HueNet1,RSSI=-30 +[WML] Channel=2,IP=192.168.2.45 +Stop multiResetDetecting +Saving config file... +Saving config file OK + +Creating new WiFi client object OK +Creating new MQTT object OK +AIO_SERVER = io.adafruit.com, AIO_SERVERPORT = 1883 +AIO_USERNAME = user_name, AIO_KEY = aio_key +Creating new MQTT_Pub_Topic, Temperature = user_name/feeds/Temperature +Creating new Temperature object OK +Temperature MQTT_Pub_Topic = user_name/feeds/Temperature +Creating new AIO_SUB_TOPIC, LED_Control = user_name/feeds/LED_Control +Creating new LED_Control object OK +LED_Control AIO_SUB_TOPIC = user_name/feeds/LED_Control + +Connecting to WiFi MQTT (3 attempts)... +WiFi MQTT connection successful! +TWTWTWTW TWTW +``` + --- --- @@ -1949,6 +2118,11 @@ If you get compilation errors, more often than not, you may need to install a ne ## Releases +### Major Release v1.5.0 + +1. 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). Now you can select optional **SCAN_WIFI_NETWORKS**, **MANUAL_SSID_INPUT_ALLOWED** to be able to manually input SSID, not only from a scanned SSID lists and **MAX_SSID_IN_LIST** (from 2-6 for ESP8266-AT or 2-15 for other) +2. Minor enhancement to not display garbage when data is invalid + ### Release v1.4.0 1. Add **LittleFS and SPIFFS** support to new **ESP32-S2** boards (**Arduino ESP32C3_DEV**). Check [HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE](#howto-install-esp32-core-for-esp32-s2-saola-ai-thinker-esp-12k-and-esp32-c3-boards-into-arduino-ide). @@ -2018,6 +2192,7 @@ Submit issues to: [ESP_WiFiManager_Lite issues](https://github.com/khoih-prog/ES 21. Add support to **ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.) using EEPROM, LittleFS and SPIFFS** 22. Configurable **Customs HTML Headers**, including Customs Style, Customs Head Elements, CORS Header 23. Add support to **ESP32-C3 using EEPROM and SPIFFS** +24. Enable **scan of WiFi networks** for selection in Configuration Portal --- --- @@ -2026,6 +2201,15 @@ Submit issues to: [ESP_WiFiManager_Lite issues](https://github.com/khoih-prog/ES Please help contribute to this project and add your name here. +1. Thanks to [Michael H. "bizprof"](https://github.com/bizprof). 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.5.0 + + + + + +
bizprof
⭐️⭐️ Michael H. "bizprof"

+ --- diff --git a/examples/ESP_WiFi/ESP_WiFi.ino b/examples/ESP_WiFi/ESP_WiFi.ino index 0b3786d..3943ee5 100644 --- a/examples/ESP_WiFi/ESP_WiFi.ino +++ b/examples/ESP_WiFi/ESP_WiFi.ino @@ -8,7 +8,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager_Lite Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -17,6 +17,7 @@ 1.2.0 K Hoang 22/02/2021 Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 12/04/2021 Fix invalid "blank" Config Data treated as Valid. Fix EEPROM_SIZE bug 1.4.0 K Hoang 21/04/2021 Add support to new ESP32-C3 using SPIFFS or EEPROM + 1.5.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/ESP_WiFi/defines.h b/examples/ESP_WiFi/defines.h index cbdde3c..db1e6e2 100644 --- a/examples/ESP_WiFi/defines.h +++ b/examples/ESP_WiFi/defines.h @@ -89,6 +89,16 @@ ///////////////////////////////////////////// +#define SCAN_WIFI_NETWORKS true + +// To be able to manually input SSID, not from a scanned SSID lists +#define MANUAL_SSID_INPUT_ALLOWED true + +// From 2-15 + #define MAX_SSID_IN_LIST 8 + +///////////////////////////////////////////// + #include #if ESP8266 diff --git a/examples/ESP_WiFi_MQTT/ESP_WiFi_MQTT.ino b/examples/ESP_WiFi_MQTT/ESP_WiFi_MQTT.ino index 084de67..abaae5c 100644 --- a/examples/ESP_WiFi_MQTT/ESP_WiFi_MQTT.ino +++ b/examples/ESP_WiFi_MQTT/ESP_WiFi_MQTT.ino @@ -8,7 +8,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager_Lite Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -17,6 +17,7 @@ 1.2.0 K Hoang 22/02/2021 Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 12/04/2021 Fix invalid "blank" Config Data treated as Valid. Fix EEPROM_SIZE bug 1.4.0 K Hoang 21/04/2021 Add support to new ESP32-C3 using SPIFFS or EEPROM + 1.5.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal *****************************************************************************************************************************/ /**************************************************************************************************************************** diff --git a/examples/ESP_WiFi_MQTT/defines.h b/examples/ESP_WiFi_MQTT/defines.h index e1b9182..e2c55a1 100644 --- a/examples/ESP_WiFi_MQTT/defines.h +++ b/examples/ESP_WiFi_MQTT/defines.h @@ -89,6 +89,16 @@ ///////////////////////////////////////////// +#define SCAN_WIFI_NETWORKS true + +// To be able to manually input SSID, not from a scanned SSID lists +#define MANUAL_SSID_INPUT_ALLOWED true + +// From 2-15 + #define MAX_SSID_IN_LIST 8 + +///////////////////////////////////////////// + #include #if ESP8266 diff --git a/library.json b/library.json index 6a279d5..8c52099 100644 --- a/library.json +++ b/library.json @@ -2,7 +2,7 @@ "name": "ESP_WiFiManager_Lite", "version": "1.4.0", "keywords": "wifi, wi-fi, MultiWiFi, multi-wifi, WiFiManager, esp8266, esp32, esp32-s2, esp32-c3, Communication, iot, credentials, persistent, config-portal, DoubleReset, MultiReset, DoubleResetDetector, littlefs, spiffs, eeprom, light-weight", - "description": "Library to configure MultiWiFi/Credentials at runtime for ESP32 (including ESP32-S2) and ESP8266 boards. 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, SPIFFS or EEPROM. New powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. Double or MultiDetectDetector as well as Virtual Switches feature permits entering Config Portal as requested. Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header.", + "description": "Library to configure MultiWiFi/Credentials at runtime for ESP32 (including ESP32-S2 and ESP32-C3) and ESP8266 boards. 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, SPIFFS or EEPROM. New powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. Double or MultiDetectDetector as well as Virtual Switches feature permits entering Config Portal as requested. Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header.", "authors": { "name": "Khoi Hoang", diff --git a/pics/Input.png b/pics/Input.png index 63b2d97..f28e5ef 100644 Binary files a/pics/Input.png and b/pics/Input.png differ diff --git a/pics/Input_With_Scan.png b/pics/Input_With_Scan.png new file mode 100644 index 0000000..80339cd Binary files /dev/null and b/pics/Input_With_Scan.png differ diff --git a/pics/Main.png b/pics/Main.png index b1a33f6..fb8ec16 100644 Binary files a/pics/Main.png and b/pics/Main.png differ diff --git a/src/ESP_WiFiManager_Lite.h b/src/ESP_WiFiManager_Lite.h index 804ea6a..aeccc91 100644 --- a/src/ESP_WiFiManager_Lite.h +++ b/src/ESP_WiFiManager_Lite.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager_Lite Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -18,6 +18,7 @@ 1.2.0 K Hoang 22/02/2021 Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 12/04/2021 Fix invalid "blank" Config Data treated as Valid. Fix EEPROM_SIZE bug 1.4.0 K Hoang 21/04/2021 Add support to new ESP32-C3 using SPIFFS or EEPROM + 1.5.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal *****************************************************************************************************************************/ #pragma once @@ -37,7 +38,7 @@ #define USING_ESP32_C3 true #endif -#define ESP_WIFI_MANAGER_LITE_VERSION "ESP_WiFiManager_Lite v1.4.0" +#define ESP_WIFI_MANAGER_LITE_VERSION "ESP_WiFiManager_Lite v1.5.0" #ifdef ESP8266 @@ -139,6 +140,36 @@ #include +////////////////////////////////////////////// + +// New from v1.3.0 +// KH, Some minor simplification +#if !defined(SCAN_WIFI_NETWORKS) + #define SCAN_WIFI_NETWORKS true //false +#endif + +#if SCAN_WIFI_NETWORKS + #if !defined(MANUAL_SSID_INPUT_ALLOWED) + #define MANUAL_SSID_INPUT_ALLOWED true + #endif + + #if !defined(MAX_SSID_IN_LIST) + #define MAX_SSID_IN_LIST 10 + #elif (MAX_SSID_IN_LIST < 2) + #warning Parameter MAX_SSID_IN_LIST defined must be >= 2 - Reset to 10 + #undef MAX_SSID_IN_LIST + #define MAX_SSID_IN_LIST 10 + #elif (MAX_SSID_IN_LIST > 15) + #warning Parameter MAX_SSID_IN_LIST defined must be <= 15 - Reset to 10 + #undef MAX_SSID_IN_LIST + #define MAX_SSID_IN_LIST 10 + #endif +#else + #warning SCAN_WIFI_NETWORKS disabled +#endif + +///////// NEW for DRD ///////////// + #if !defined(USING_MRD) #define USING_MRD false #endif @@ -305,12 +336,15 @@ const char ESP_WM_LITE_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;}"; -const char ESP_WM_LITE_HTML_HEAD_END[] /*PROGMEM*/ = "

\ -
\ -
\ -
\ -
\ -
"; +const char ESP_WM_LITE_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
[[input_id]]
\ +
\ +
[[input_id1]]
\ +
\ +
"; // DO NOT CHANGE THIS STRING EVER!!!! + +const char ESP_WM_LITE_HTML_INPUT_ID[] /*PROGMEM*/ = ""; +const char ESP_WM_LITE__HTML_INPUT_ID1[] /*PROGMEM*/ = ""; const char ESP_WM_LITE_FLDSET_START[] /*PROGMEM*/ = "
"; const char ESP_WM_LITE_FLDSET_END[] /*PROGMEM*/ = "
"; @@ -327,6 +361,16 @@ const char ESP_WM_LITE_HTML_SCRIPT_ITEM[] /*PROGMEM*/ = "udVal('{d}',document.g const char ESP_WM_LITE_HTML_SCRIPT_END[] /*PROGMEM*/ = "alert('Updated');}"; const char ESP_WM_LITE_HTML_END[] /*PROGMEM*/ = ""; +#if SCAN_WIFI_NETWORKS +const char ESP_WM_LITE_SELECT_START[] /*PROGMEM*/ = "" + String(ESP_WM_LITE_DATALIST_START) + "'SSIDs'>" + ListOfSSIDs + ESP_WM_LITE_DATALIST_END); + ESP_WML_LOGDEBUG1(F("pitem:"), pitem); + pitem.replace("[[input_id1]]", "" + String(ESP_WM_LITE_DATALIST_START) + "'SSIDs'>" + ListOfSSIDs + ESP_WM_LITE_DATALIST_END); + + ESP_WML_LOGDEBUG1(F("pitem:"), pitem); + +#else + pitem.replace("[[input_id]]", "" + ListOfSSIDs + ESP_WM_LITE_SELECT_END); +#endif + + root_html_template += pitem + ESP_WM_LITE_FLDSET_START; + +#else + + pitem = String(ESP_WM_LITE_HTML_HEAD_END); + pitem.replace("[[input_id]]", ESP_WM_LITE_HTML_INPUT_ID); + pitem.replace("[[input_id1]]", ESP_WM_LITE_HTML_INPUT_ID1); + root_html_template += pitem + ESP_WM_LITE_FLDSET_START; + +#endif // SCAN_WIFI_NETWORKS #if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) @@ -2279,11 +2387,22 @@ class ESP_WiFiManager_Lite result.replace("ESP_WM_Lite", ESP_WM_LITE_config.board_name); } - result.replace("[[id]]", ESP_WM_LITE_config.WiFi_Creds[0].wifi_ssid); - result.replace("[[pw]]", ESP_WM_LITE_config.WiFi_Creds[0].wifi_pw); - result.replace("[[id1]]", ESP_WM_LITE_config.WiFi_Creds[1].wifi_ssid); - result.replace("[[pw1]]", ESP_WM_LITE_config.WiFi_Creds[1].wifi_pw); - result.replace("[[nm]]", ESP_WM_LITE_config.board_name); + if (hadConfigData) + { + result.replace("[[id]]", ESP_WM_LITE_config.WiFi_Creds[0].wifi_ssid); + result.replace("[[pw]]", ESP_WM_LITE_config.WiFi_Creds[0].wifi_pw); + result.replace("[[id1]]", ESP_WM_LITE_config.WiFi_Creds[1].wifi_ssid); + result.replace("[[pw1]]", ESP_WM_LITE_config.WiFi_Creds[1].wifi_pw); + result.replace("[[nm]]", ESP_WM_LITE_config.board_name); + } + else + { + result.replace("[[id]]", ""); + result.replace("[[pw]]", ""); + result.replace("[[id1]]", ""); + result.replace("[[pw1]]", ""); + result.replace("[[nm]]", ""); + } #if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) @@ -2469,6 +2588,12 @@ class ESP_WiFiManager_Lite void startConfigurationMode() { +#if SCAN_WIFI_NETWORKS + configTimeout = 0; // To allow user input in CP + + WiFiNetworksFound = scanWifiNetworks(&indices); +#endif + // turn the LED_BUILTIN ON to tell us we are in configuration mode. digitalWrite(LED_BUILTIN, LED_ON); @@ -2538,6 +2663,179 @@ class ESP_WiFiManager_Lite configuration_mode = true; } + +#if SCAN_WIFI_NETWORKS + + // Source code adapted from https://github.com/khoih-prog/ESP_WiFiManager/blob/master/src/ESP_WiFiManager-Impl.h + + int _paramsCount = 0; + int _minimumQuality = -1; + bool _removeDuplicateAPs = true; + + ////////////////////////////////////////// + + void swap(int *thisOne, int *thatOne) + { + int tempo; + + tempo = *thatOne; + *thatOne = *thisOne; + *thisOne = tempo; + } + + ////////////////////////////////////////// + + void setMinimumSignalQuality(int quality) + { + _minimumQuality = quality; + } + + ////////////////////////////////////////// + + //if this is true, remove duplicate Access Points - default true + void setRemoveDuplicateAPs(bool removeDuplicates) + { + _removeDuplicateAPs = removeDuplicates; + } + + ////////////////////////////////////////// + + //Scan for WiFiNetworks in range and sort by signal strength + //space for indices array allocated on the heap and should be freed when no longer required + int scanWifiNetworks(int **indicesptr) + { + ESP_WML_LOGDEBUG(F("Scanning Network")); + + int n = WiFi.scanNetworks(); + + ESP_WML_LOGDEBUG1(F("scanWifiNetworks: Done, Scanned Networks n = "), n); + + //KH, Terrible bug here. WiFi.scanNetworks() returns n < 0 => malloc( negative == very big ) => crash!!! + //In .../esp32/libraries/WiFi/src/WiFiType.h + //#define WIFI_SCAN_RUNNING (-1) + //#define WIFI_SCAN_FAILED (-2) + //if (n == 0) + if (n <= 0) + { + ESP_WML_LOGDEBUG(F("No network found")); + return (0); + } + else + { + // Allocate space off the heap for indices array. + // This space should be freed when no longer required. + int* indices = (int *)malloc(n * sizeof(int)); + + if (indices == NULL) + { + ESP_WML_LOGDEBUG(F("ERROR: Out of memory")); + *indicesptr = NULL; + return (0); + } + + *indicesptr = indices; + + //sort networks + for (int i = 0; i < n; i++) + { + indices[i] = i; + } + + ESP_WML_LOGDEBUG(F("Sorting")); + + // RSSI SORT + // old sort + for (int i = 0; i < n; i++) + { + for (int j = i + 1; j < n; j++) + { + if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) + { + //std::swap(indices[i], indices[j]); + // Using locally defined swap() + swap(&indices[i], &indices[j]); + } + } + } + + ESP_WML_LOGDEBUG(F("Removing Dup")); + + // remove duplicates ( must be RSSI sorted ) + if (_removeDuplicateAPs) + { + String cssid; + + for (int i = 0; i < n; i++) + { + if (indices[i] == -1) + continue; + + cssid = WiFi.SSID(indices[i]); + + for (int j = i + 1; j < n; j++) + { + if (cssid == WiFi.SSID(indices[j])) + { + ESP_WML_LOGDEBUG1("DUP AP:", WiFi.SSID(indices[j])); + indices[j] = -1; // set dup aps to index -1 + } + } + } + } + + for (int i = 0; i < n; i++) + { + if (indices[i] == -1) + continue; // skip dups + + int quality = getRSSIasQuality(WiFi.RSSI(indices[i])); + + if (!(_minimumQuality == -1 || _minimumQuality < quality)) + { + indices[i] = -1; + ESP_WML_LOGDEBUG(F("Skipping low quality")); + } + } + + ESP_WML_LOGWARN(F("WiFi networks found:")); + + for (int i = 0; i < n; i++) + { + if (indices[i] == -1) + continue; // skip dups + else + ESP_WML_LOGWARN5(i+1,": ",WiFi.SSID(indices[i]), ", ", WiFi.RSSI(i), "dB"); + } + + return (n); + } + } + + ////////////////////////////////////////// + + int getRSSIasQuality(int RSSI) + { + int quality = 0; + + if (RSSI <= -100) + { + quality = 0; + } + else if (RSSI >= -50) + { + quality = 100; + } + else + { + quality = 2 * (RSSI + 100); + } + + return quality; + } + + ////////////////////////////////////////// + +#endif }; diff --git a/src/ESP_WiFiManager_Lite_Debug.h b/src/ESP_WiFiManager_Lite_Debug.h index cd57061..6346bc5 100644 --- a/src/ESP_WiFiManager_Lite_Debug.h +++ b/src/ESP_WiFiManager_Lite_Debug.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager_Lite Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -18,6 +18,7 @@ 1.2.0 K Hoang 22/02/2021 Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 12/04/2021 Fix invalid "blank" Config Data treated as Valid. Fix EEPROM_SIZE bug 1.4.0 K Hoang 21/04/2021 Add support to new ESP32-C3 using SPIFFS or EEPROM + 1.5.0 Michael H 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal *****************************************************************************************************************************/ #ifndef ESP_WiFiManager_Lite_Debug_h