- Why do we need this ESP_WiFiManager_Lite library
- Changelog
- Prerequisites
- Installation
- HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE
- Note for Platform IO using ESP32 LittleFS
- HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
- How It Works
- How to use
- 1. Basic usage
- 2. Add custom parameters
- 3. Not using custom parameters
- 4. To open Config Portal
- 5. To use different AP WiFi Channel
- 6. To use different static AP IP from default
- 7. To use custom DHCP HostName
- 8. To use custom HTML Style
- 9. To use custom Head Elements
- 10. To use CORS Header
- 11. To use and input only one set of WiFi SSID and PWD
- 12. To enable auto-scan of WiFi networks for selection in Configuration Portal
- Examples
- So, how it works?
- Important Notes
- How to use default Credentials and have them pre-loaded onto Config Portal
- How to add dynamic parameters from sketch
- Important Notes for using Dynamic Parameters' ids
- Example ESP_WiFi
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Releases
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need this ESP_WiFiManager_Lite library
If you have used one of the full-fledge WiFiManagers such as :
and have to write complicated callback functions to save custom parameters in SPIFFS/LittleFS/EEPROM, you'd appreciate the simplicity of this Light-Weight Credentials / WiFiManager.
This is a Credentials / WiFi Connection Manager for ESP32 and ESP8266 boards, permitting the addition of custom parameters to be configured in Config Portal. The parameters then will be saved automatically, without the complicated callback functions to handle data saving / retrieving.
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. Credentials are saved in LittleFS, SPIFFS or EEPROM.
The web configuration portal, served from the ESP32/ESP8266 WiFi
is operating as an access point (AP) with configurable static IP address or use default IP Address of 192.168.4.1
New recent features:
- MultiWiFi feature for configuring/auto(re)connecting ESP32/ESP8266 WiFi to the available MultiWiFi APs at runtime.
- Multi/DoubleDetectDetector feature to force Config Portal when multi/double reset is detected within predetermined time, default 10s.
- Powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. Config Portal will be auto-adjusted to match the number of dynamic parameters.
- Optional default Credentials as well as Dynamic parameters to be optionally autoloaded into Config Portal to use or change instead of manually input.
- Dynamic custom parameters to be saved automatically in non-volatile memory, such as LittleFS, SPIFFS or EEPROM..
- Configurable Config Portal Title to be either BoardName or default undistinguishable names.
- Examples are designed to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device.
- 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
This ESP_WiFiManager_Lite library currently supports these following boards:
- ESP8266 and ESP32-based boards using EEPROM, SPIFFS or LittleFS.
- ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.) using EEPROM, SPIFFS or LittleFS.
- ESP32-C3 (ARDUINO_ESP32C3_DEV) using EEPROM or SPIFFS.
- Enable scan of WiFi networks for selection in Configuration Portal. Check PR for v1.3.0 - Enable scan of WiFi networks #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-15)
- Minor enhancement to not display garbage when data is invalid
- 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.
- Add EEPROM and SPIFFS support to new ESP32-C3 boards (Arduino ESP32C3_DEV). Check HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE.
- Fix invalid "blank" Config Data treated as Valid.
- Permit optionally inputting one set of WiFi SSID/PWD by using
REQUIRE_ONE_SET_SSID_PW == true
- Enforce WiFi PWD minimum length of 8 chars
- Fix bug where EEPROM_SIZE truncated by DRD/MRD to 512, resulting lost and corrupted data.
- Fix crashing bug in serverSendHeaders()
- Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header.
- Fix Config Portal Bug.
- Update examples
- Add support to ESP32-S2 (ESP32-S2 Saola and AI-Thinker ESP-12K)
- Add Instructions to install ESP32-S2 core
- Initial release to support ESP32 and ESP8266.
Arduino IDE 1.8.13+
for ArduinoESP8266 Core 2.7.4+
for ESP8266-based boards.ESP32 Core 1.0.6+
for ESP32-based boards.ESP32-S2/C3 Core 1.0.6+
for ESP32-S2/C3-based boards. Must follow HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE.ESP_DoubleResetDetector v1.1.1+
if using DRD feature. To install, check .ESP_MultiResetDetector v1.1.1+
if using MRD feature. To install, check .LittleFS_esp32 v1.0.6+
for ESP32-based boards using LittleFS. To install, check . Notice: ThisLittleFS_esp32 library
has been integrated to Arduino esp32 core v1.0.6.
The best and easiest way is to use Arduino Library Manager
. Search for ESP_WiFiManager_Lite, then select / install the latest version.
You can also use this link for more detailed instructions.
- Navigate to ESP_WiFiManager_Lite page.
- Download the latest release
ESP_WiFiManager_Lite-main.zip
. - Extract the zip file to
ESP_WiFiManager_Lite-main
directory - Copy the whole
ESP_WiFiManager_Lite-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install ESP_WiFiManager_Lite library by using Library Manager. Search for ESP_WiFiManager_Lite in Platform.io Author's Libraries
- Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE
These are instructions demonstrating the steps to install esp32-s2/c3 core on Ubuntu machines. For Windows or other OS'es, just follow the the similar principles and steps.
-
Windows 10, follows these steps in Steps to install Arduino ESP32 support on Windows
-
Mac OS, follows these steps in Installation instructions for Mac OS
-
Fedora, follows these steps in Installation instructions for Fedora
-
openSUSE, follows these steps in Installation instructions for openSUSE
-
You can also try to add package_esp32_dev_index.json into Arduino IDE
File - Preferences - Additional Boards Manager URLs
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
and have Board Manager auto-install the development esp32 core. For example : esp32 core v2.0.0-alpha1
If you're already successful in testing the core, after installing by using the above procedures, you don't need to follows the hereafter manual steps.
Assuming you already installed Arduino IDE ESP32 core and the installed directory is
/home/your_account/.arduino15/packages/esp32
First, copy the whole original esp32 core to another safe place. Then delete all the sub-directories of
/home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.4
Just use Arduino IDE Board Manager to install ESP32 Arduino Release 1.0.6 based on ESP-IDF v3.3.5. This official v1.06 core doesn't have esp32-s2/s3 support. You have to download and use the latest master branch.
As of April 16th 2021, the esp32-s2/c3 board support has been included in master branch of esp32 core. Download esp32 core, master branch in the zip format.
Copy all subdirectories of esp32 core into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6
Download esp32-s2 Toolchain corresponding to your environment (linux-amd64, win64, etc.).
For example xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
, then un-archive.
Download esptool int the zip
format:
esptool-3.0.zip
Copy whole xtensa-esp32s2-elf
directory into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools
Rename esptool-3.0
directory to esptool
Copy whole esptool
directory into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools
Download esp32-c3 Toolchain corresponding to your environment (linux-amd64, win64, etc.).
For exampleriscv32-esp-elf-gcc8_4_0-crosstool-ng-1.24.0-123-g64eb9ff-linux-amd64.tar.gz
, then un-archive.
Then using the similar steps as in
then copy whole riscv32-esp-elf
directory into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools
If you haven't installed a new version with WebServer.handleClient delay PR #4350 or haven't applied the above mentioned PR, you have to use the following patch.
To be able to run Config Portal on ESP32-S2 boards, you have to copy the files in esp32-s2 WebServer Patch directory into esp32-s2 WebServer library directory (~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer).
Supposing the esp32-s2 version is 1.0.4, these files WebServer.h/cpp
must be copied into the directory to replace:
~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer/src/WebServer.h
~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer/src/WebServer.cpp
That's it. You're now ready to compile and test for ESP32-S2 and ESP32-C3 now
From esp32 core v1.0.6+, LittleFS_esp32 v1.0.6
has been included and this step is not necessary anymore.
In Platform IO, to fix the error when using LittleFS_esp32 v1.0
for ESP32-based boards with ESP32 core v1.0.4- (ESP-IDF v3.2-), uncomment the following line
from
//#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */
to
#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */
It's advisable to use the latest LittleFS_esp32 v1.0.5+
to avoid the issue.
Thanks to Roshan to report the issue in Error esp_littlefs.c 'utime_p'
Please have a look at ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to have more detailed description and solution of the issue.
- ADC1 controls ADC function for pins GPIO32-GPIO39
- ADC2 controls ADC function for pins GPIO0, 2, 4, 12-15, 25-27
Look in file adc_common.c
In ADC2, there're two locks used for different cases:
lock shared with app and Wi-Fi: ESP32: When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed. ESP32S2: The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
lock shared between tasks: when several tasks sharing the ADC2, we want to guarantee all the requests will be handled. Since conversions are short (about 31us), app returns the lock very soon, we use a spinlock to stand there waiting to do conversions one by one.
adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
- In order to use ADC2 for other functions, we have to acquire complicated firmware locks and very difficult to do
- So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).
- Use ADC1, and pins GPIO32-GPIO39
- If somehow it's a must to use those pins serviced by ADC2 (GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27), use the fix mentioned at the end of ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to work with ESP32 WiFi/BlueTooth (BT/BLE).
- The ESP_WiFi example shows how it works and should be used as the basis for a sketch that uses this library.
- The concept of ESP_WiFi is that a new
ESP32/ESP8266 WiFi
will start a WiFi configuration portal when powered up, but has no valid stored Credentials or can't connect to WiFi APs after a pre-determined time. - There are 6 more custom parameters added in the sketch which you can use in your program later. In the example, they are: 2 sets of Blynk Servers and Tokens, Blynk Port and MQTT Server.
- Using any WiFi enabled device with a browser (computer, phone, tablet) connect to the newly created AP and type in the configurable AP IP address (default 192.168.4.1). The Config Portal AP channel (default 10) is also configurable to avoid conflict with other APs.
- The Config Portal is auto-adjusted to fix the 4 static parameters (WiFi SSIDs/PWDs) as well as 6 more dynamic custom parameters.
- After the custom data entered, and Save button pressed, the configuration data will be saved in host's non-volatile memory, then the board reboots.
- If there is valid stored Credentials, it'll go directly to connect to one of the MultiWiFi APs without starting / using the Config Portal.
ESP32/ESP8266 WiFi
will try to connect. If successful, the dynamic DHCP and/or configured static IP address will be displayed in the configuration portal.- The
ESP32/ESP8266 WiFi
Config Portal network and Web Server will shutdown to return control to the sketch code. - In the operation, if the current WiFi connection is lost because of any reason, the system will auto(Re)connect to the remaining WiFi AP.
- If system can't connect to any of the 2 WiFi APs, the Config Portal will start, after some pre-determined time, to permit user to update the Credentials.
- Include in your sketch
// Must be before #include <ESP_WiFiManager_Lite.h>
#include <ESP_WiFiManager_Lite.h>
ESP_WiFiManager_Lite* ESP_WiFiManager;
- To add custom parameters, just add
#include "defines.h"
// USE_DYNAMIC_PARAMETERS defined in defined.h
/////////////// Start dynamic Credentials ///////////////
//Defined in <ESP_WiFiManager_Lite.h>
/**************************************
#define MAX_ID_LEN 5
#define MAX_DISPLAY_NAME_LEN 16
typedef struct
{
char id [MAX_ID_LEN + 1];
char displayName [MAX_DISPLAY_NAME_LEN + 1];
char *pdata;
uint8_t maxlen;
} MenuItem;
**************************************/
#if USE_DYNAMIC_PARAMETERS
#define MAX_BLYNK_SERVER_LEN 34
#define MAX_BLYNK_TOKEN_LEN 34
char Blynk_Server1 [MAX_BLYNK_SERVER_LEN + 1] = "account.duckdns.org";
char Blynk_Token1 [MAX_BLYNK_TOKEN_LEN + 1] = "token1";
char Blynk_Server2 [MAX_BLYNK_SERVER_LEN + 1] = "account.ddns.net";
char Blynk_Token2 [MAX_BLYNK_TOKEN_LEN + 1] = "token2";
#define MAX_BLYNK_PORT_LEN 6
char Blynk_Port [MAX_BLYNK_PORT_LEN + 1] = "8080";
#define MAX_MQTT_SERVER_LEN 34
char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "mqtt.duckdns.org";
MenuItem myMenuItems [] =
{
{ "sv1", "Blynk Server1", Blynk_Server1, MAX_BLYNK_SERVER_LEN },
{ "tk1", "Token1", Blynk_Token1, MAX_BLYNK_TOKEN_LEN },
{ "sv2", "Blynk Server2", Blynk_Server2, MAX_BLYNK_SERVER_LEN },
{ "tk2", "Token2", Blynk_Token2, MAX_BLYNK_TOKEN_LEN },
{ "prt", "Port", Blynk_Port, MAX_BLYNK_PORT_LEN },
{ "mqt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },
};
uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;
#else
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
#endif //USE_DYNAMIC_PARAMETERS
- If you don't need to add dynamic parameters, use the following in sketch
#define USE_DYNAMIC_PARAMETERS false
- When you want to open a config portal, just add
ESP_WiFiManager = new ESP_WiFiManager_Lite();
ESP_WiFiManager->begin();
- To not use default AP WiFi Channel 10 to avoid conflict with other WiFi APs :
ESP_WiFiManager->setConfigPortalChannel(newChannel);
- To use random AP WiFi Channel to avoid conflict with other WiFi APs :
ESP_WiFiManager->setConfigPortalChannel(0);
- To use different static AP IP (not use default
192.168.4.1
), call
ESP_WiFiManager->setConfigPortalIP(IPAddress(xxx,xxx,xxx,xxx));
- To set custom DHCP HostName :
// Set customized DHCP HostName
ESP_WiFiManager->begin("ESP32-WIFI_ABCDEF");
or just use the default Hostname, for example "ESP_ABCDEF"
//Or use default Hostname "ESPC_ABCDEF"
ESP_WiFiManager->begin();
const char NewCustomsStyle[] /*PROGMEM*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
...
ESP_WiFiManager->setCustomsStyle(NewCustomsStyle);
ESP_WiFiManager->setCustomsHeadElement("<style>html{filter: invert(10%);}</style>");
ESP_WiFiManager->setCORSHeader("Your Access-Control-Allow-Origin");
While in AP mode, connect to it using its SSID
(ESP_ABCDEF) / Password
("MyESP_ABCDEF"), then open a browser to the Portal AP IP, default 192.168.4.1
, configure wifi then click Save. The Credentials / WiFi connection information will be saved in non-volatile memory. It will then autoconnect.
Once Credentials / WiFi network information is saved in the host non-volatile memory, it will try to autoconnect to WiFi every time it is started, without requiring any function calls in the sketch.
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW true
But it's always advisable to use and input both sets for reliability.
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW false
#define 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.
// 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.
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
In Configuration Portal Mode
, it starts an AP called ESP_ABCDEF
. Connect to it using the configurable password
you can define in the code. For example, MyESP_ABCDEF
(see examples):
After you connected, please, go to http://192.168.4.1 or newly configured AP IP, you'll see this Main
page:
Enter your credentials,
Enter your credentials,
or
then click Save
.
The WiFi Credentials will be saved and the board connect to the selected WiFi AP.
If you're already connected to a listed WiFi AP and don't want to change anything, just select Exit
from the Main
page to reboot the board and connect to the previously-stored AP. The WiFi Credentials are still intact.
- Now you can use special chars such as ~, !, @, #, $, %, ^, &, _, -, space,etc. thanks to brondolin to provide the amazing fix in No save the char # at end of the wifi password to permit input special chars such as % and # into data fields.
- The SSIDs, Passwords must be input (or to make them different from blank). Otherwise, the Config Portal will re-open until those fields have been changed. If you don't need any field, just input anything or use duplicated data from similar field.
- WiFi password min length now is 8, max length is 63 chars according to WPA2 standard.
See this example and modify as necessary
1. To always load Default Credentials and override Config Portal data
// Used mostly for development and debugging. FORCES default values to be loaded each run.
// Config Portal data input will be ignored and overridden by DEFAULT_CONFIG_DATA
bool LOAD_DEFAULT_CONFIG_DATA = true;
2. To load Default Credentials when there is no valid Credentials.
Config Portal data input will be override DEFAULT_CONFIG_DATA
// Used mostly once debugged. Assumes good data already saved in device.
// Config Portal data input will be override DEFAULT_CONFIG_DATA
bool LOAD_DEFAULT_CONFIG_DATA = false;
3. Example of Default Credentials
/// Start Default Config Data //////////////////
/*
#define SSID_MAX_LEN 32
//From v1.0.3, WPA2 passwords can be up to 63 characters long.
#define PASS_MAX_LEN 64
typedef struct
{
char wifi_ssid[SSID_MAX_LEN];
char wifi_pw [PASS_MAX_LEN];
} WiFi_Credentials;
#define NUM_WIFI_CREDENTIALS 2
// Configurable items besides fixed Header, just add board_name
#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 )
////////////////
typedef struct Configuration
{
char header [16];
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
char board_name [24];
int checkSum;
} ESP_WM_LITE_Configuration;
*/
#define TO_LOAD_DEFAULT_CONFIG_DATA false
#if TO_LOAD_DEFAULT_CONFIG_DATA
// This feature is primarily used in development to force a known set of values as Config Data
// It will NOT force the Config Portal to activate. Use DRD or erase Config Data with ESP_WiFiManager.clearConfigData()
// Used mostly for development and debugging. FORCES default values to be loaded each run.
// Config Portal data input will be ignored and overridden by DEFAULT_CONFIG_DATA
//bool LOAD_DEFAULT_CONFIG_DATA = true;
// Used mostly once debugged. Assumes good data already saved in device.
// Config Portal data input will be override DEFAULT_CONFIG_DATA
bool LOAD_DEFAULT_CONFIG_DATA = false;
ESP_WM_LITE_Configuration defaultConfig =
{
//char header[16], dummy, not used
#if ESP8266
"ESP8266",
#else
"ESP32",
#endif
// WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
// WiFi_Credentials.wifi_ssid and WiFi_Credentials.wifi_pw
"SSID1", "password1",
"SSID2", "password2",
//char board_name [24];
#if ESP8266
"ESP8266-Control",
#else
"ESP32-Control",
#endif
// terminate the list
//int checkSum, dummy, not used
0
/////////// End Default Config Data /////////////
};
#else
bool LOAD_DEFAULT_CONFIG_DATA = false;
ESP_WM_LITE_Configuration defaultConfig;
#endif // TO_LOAD_DEFAULT_CONFIG_DATA
/////////// End Default Config Data /////////////
Example of Default dynamicParams
- To add custom parameters, just modify the example below
#include "defines.h"
// USE_DYNAMIC_PARAMETERS defined in defined.h
/////////////// Start dynamic Credentials ///////////////
//Defined in <ESP_WiFiManager_Lite.h>
/**************************************
#define MAX_ID_LEN 5
#define MAX_DISPLAY_NAME_LEN 16
typedef struct
{
char id [MAX_ID_LEN + 1];
char displayName [MAX_DISPLAY_NAME_LEN + 1];
char *pdata;
uint8_t maxlen;
} MenuItem;
**************************************/
#if USE_DYNAMIC_PARAMETERS
#define MAX_BLYNK_SERVER_LEN 34
#define MAX_BLYNK_TOKEN_LEN 34
char Blynk_Server1 [MAX_BLYNK_SERVER_LEN + 1] = "account.duckdns.org";
char Blynk_Token1 [MAX_BLYNK_TOKEN_LEN + 1] = "token1";
char Blynk_Server2 [MAX_BLYNK_SERVER_LEN + 1] = "account.ddns.net";
char Blynk_Token2 [MAX_BLYNK_TOKEN_LEN + 1] = "token2";
#define MAX_BLYNK_PORT_LEN 6
char Blynk_Port [MAX_BLYNK_PORT_LEN + 1] = "8080";
#define MAX_MQTT_SERVER_LEN 34
char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "mqtt.duckdns.org";
MenuItem myMenuItems [] =
{
{ "sv1", "Blynk Server1", Blynk_Server1, MAX_BLYNK_SERVER_LEN },
{ "tk1", "Token1", Blynk_Token1, MAX_BLYNK_TOKEN_LEN },
{ "sv2", "Blynk Server2", Blynk_Server2, MAX_BLYNK_SERVER_LEN },
{ "tk2", "Token2", Blynk_Token2, MAX_BLYNK_TOKEN_LEN },
{ "prt", "Port", Blynk_Port, MAX_BLYNK_PORT_LEN },
{ "mqt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },
};
uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;
#else
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
#endif //USE_DYNAMIC_PARAMETERS
- If you don't need to add dynamic parameters, use the following in sketch
#define USE_DYNAMIC_PARAMETERS false
or
/////////////// Start dynamic Credentials ///////////////
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
/////// // End dynamic Credentials ///////////
- These ids (such as "mqtt" in example) must be unique.
Please be noted that the following reserved names are already used in library:
"id" for WiFi SSID
"pw" for WiFi PW
"id1" for WiFi1 SSID
"pw1" for WiFi1 PW
"nm" for Board Name
Example ESP_WiFi
Please take a look at other examples, as well.
1. File ESP_WiFi.ino
#include "defines.h"
#include "Credentials.h"
#include "dynamicParams.h"
void heartBeatPrint()
{
static int num = 1;
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
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
//KH
#define HEARTBEAT_INTERVAL 20000L
// Print hearbeat every HEARTBEAT_INTERVAL (20) seconds.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
heartBeatPrint();
checkstatus_timeout = millis() + HEARTBEAT_INTERVAL;
}
}
ESP_WiFiManager_Lite* ESP_WiFiManager;
#if USING_CUSTOMS_STYLE
const char NewCustomsStyle[] /*PROGMEM*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
#endif
void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print(F("\nStarting ESP_WiFi using ")); Serial.print(FS_Name);
Serial.print(F(" on ")); Serial.println(ARDUINO_BOARD);
Serial.println(ESP_WIFI_MANAGER_LITE_VERSION);
#if USING_MRD
Serial.println(ESP_MULTI_RESET_DETECTOR_VERSION);
#else
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);
#endif
ESP_WiFiManager = new ESP_WiFiManager_Lite();
// Optional to change default AP IP(192.168.4.1) and channel(10)
//ESP_WiFiManager->setConfigPortalIP(IPAddress(192, 168, 120, 1));
ESP_WiFiManager->setConfigPortalChannel(0);
#if USING_CUSTOMS_STYLE
ESP_WiFiManager->setCustomsStyle(NewCustomsStyle);
#endif
#if USING_CUSTOMS_HEAD_ELEMENT
ESP_WiFiManager->setCustomsHeadElement("<style>html{filter: invert(10%);}</style>");
#endif
#if USING_CORS_FEATURE
ESP_WiFiManager->setCORSHeader("Your Access-Control-Allow-Origin");
#endif
// Set customized DHCP HostName
ESP_WiFiManager->begin(HOST_NAME);
//Or use default Hostname "ESP32-WIFI-XXXXXX"
//ESP_WiFiManager->begin();
}
#if USE_DYNAMIC_PARAMETERS
void displayCredentials()
{
Serial.println(F("\nYour stored Credentials :"));
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
{
Serial.print(myMenuItems[i].displayName);
Serial.print(F(" = "));
Serial.println(myMenuItems[i].pdata);
}
}
void displayCredentialsInLoop()
{
static bool displayedCredentials = false;
if (!displayedCredentials)
{
for (int i = 0; i < NUM_MENU_ITEMS; i++)
{
if (!strlen(myMenuItems[i].pdata))
{
break;
}
if ( i == (NUM_MENU_ITEMS - 1) )
{
displayedCredentials = true;
displayCredentials();
}
}
}
}
#endif
void loop()
{
ESP_WiFiManager->run();
check_status();
#if USE_DYNAMIC_PARAMETERS
displayCredentialsInLoop();
#endif
}
2. File defines.h
#ifndef defines_h
#define defines_h
#if !( ESP8266 || ESP32)
#error This code is intended to run only on the ESP8266/ESP32 boards ! Please check your Tools->Board setting.
#endif
/* Comment this out to disable prints and save space */
#define ESP_WM_LITE_DEBUG_OUTPUT Serial
#define _ESP_WM_LITE_LOGLEVEL_ 2
#define USING_MRD true
#if USING_MRD
#define MULTIRESETDETECTOR_DEBUG true
// Number of seconds after reset during which a
// subseqent reset will be considered a double reset.
#define MRD_TIMEOUT 10
// RTC Memory Address for the DoubleResetDetector to use
#define MRD_ADDRESS 0
#warning Using MULTI_RESETDETECTOR
#else
#define DOUBLERESETDETECTOR_DEBUG true
// Number of seconds after reset during which a
// subseqent reset will be considered a double reset.
#define DRD_TIMEOUT 10
// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
#warning Using DOUBLE_RESETDETECTOR
#endif
/////////////////////////////////////////////
// LittleFS has higher priority than SPIFFS
#if ( ARDUINO_ESP32C3_DEV )
// Currently, ESP32-C3 only supporting SPIFFS and EEPROM. Will fix to support LittleFS
#define USE_LITTLEFS false
#define USE_SPIFFS true
#else
#define USE_LITTLEFS true
#define USE_SPIFFS false
#endif
/////////////////////////////////////////////
// Add customs headers from v1.2.0
#define USING_CUSTOMS_STYLE true
#define USING_CUSTOMS_HEAD_ELEMENT true
#define USING_CORS_FEATURE true
/////////////////////////////////////////////
// Permit input only one set of WiFi SSID/PWD. The other can be "NULL or "blank"
// Default is false (if not defined) => must input 2 sets of SSID/PWD
#define REQUIRE_ONE_SET_SSID_PW false
// Force some params
#define TIMEOUT_RECONNECT_WIFI 10000L
// Permit running CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET times before reset hardware
// to permit user another chance to config. Only if Config Data is valid.
// If Config Data is invalid, this has no effect as Config Portal will persist
#define RESET_IF_CONFIG_TIMEOUT true
// Permitted range of user-defined CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET between 2-100
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
// Config Timeout 120s (default 60s). Applicable only if Config Data is Valid
#define CONFIG_TIMEOUT 120000L
#define USE_DYNAMIC_PARAMETERS true
/////////////////////////////////////////////
#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 <ESP_WiFiManager_Lite.h>
#if ESP8266
#define HOST_NAME "ESP8266-Controller"
#else
#define HOST_NAME "ESP32-Controller"
#endif
#ifdef LED_BUILTIN
#define LED_PIN LED_BUILTIN
#else
#define LED_PIN 13
#endif
#endif //defines_h
3. File Credentials.h
#ifndef Credentials_h
#define Credentials_h
#include "defines.h"
/// Start Default Config Data //////////////////
/*
#define SSID_MAX_LEN 32
//From v1.0.3, WPA2 passwords can be up to 63 characters long.
#define PASS_MAX_LEN 64
typedef struct
{
char wifi_ssid[SSID_MAX_LEN];
char wifi_pw [PASS_MAX_LEN];
} WiFi_Credentials;
#define NUM_WIFI_CREDENTIALS 2
// Configurable items besides fixed Header, just add board_name
#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 )
////////////////
typedef struct Configuration
{
char header [16];
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
char board_name [24];
int checkSum;
} ESP_WM_LITE_Configuration;
*/
#define TO_LOAD_DEFAULT_CONFIG_DATA false
#if TO_LOAD_DEFAULT_CONFIG_DATA
// This feature is primarily used in development to force a known set of values as Config Data
// It will NOT force the Config Portal to activate. Use DRD or erase Config Data with ESP_WiFiManager.clearConfigData()
// Used mostly for development and debugging. FORCES default values to be loaded each run.
// Config Portal data input will be ignored and overridden by DEFAULT_CONFIG_DATA
//bool LOAD_DEFAULT_CONFIG_DATA = true;
// Used mostly once debugged. Assumes good data already saved in device.
// Config Portal data input will be override DEFAULT_CONFIG_DATA
bool LOAD_DEFAULT_CONFIG_DATA = false;
ESP_WM_LITE_Configuration defaultConfig =
{
//char header[16], dummy, not used
#if ESP8266
"ESP8266",
#else
"ESP32",
#endif
// WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
// WiFi_Credentials.wifi_ssid and WiFi_Credentials.wifi_pw
"SSID1", "password1",
"SSID2", "password2",
//char board_name [24];
#if ESP8266
"ESP8266-Control",
#else
"ESP32-Control",
#endif
// terminate the list
//int checkSum, dummy, not used
0
/////////// End Default Config Data /////////////
};
#else
bool LOAD_DEFAULT_CONFIG_DATA = false;
ESP_WM_LITE_Configuration defaultConfig;
#endif // TO_LOAD_DEFAULT_CONFIG_DATA
/////////// End Default Config Data /////////////
#endif //Credentials_h
4. File dynamicParams.h
#ifndef dynamicParams_h
#define dynamicParams_h
#include "defines.h"
// USE_DYNAMIC_PARAMETERS defined in defined.h
/////////////// Start dynamic Credentials ///////////////
//Defined in <ESP_WiFiManager_Lite.h>
/**************************************
#define MAX_ID_LEN 5
#define MAX_DISPLAY_NAME_LEN 16
typedef struct
{
char id [MAX_ID_LEN + 1];
char displayName [MAX_DISPLAY_NAME_LEN + 1];
char *pdata;
uint8_t maxlen;
} MenuItem;
**************************************/
#if USE_DYNAMIC_PARAMETERS
#define MAX_BLYNK_SERVER_LEN 34
#define MAX_BLYNK_TOKEN_LEN 34
char Blynk_Server1 [MAX_BLYNK_SERVER_LEN + 1] = "account.duckdns.org";
char Blynk_Token1 [MAX_BLYNK_TOKEN_LEN + 1] = "token1";
char Blynk_Server2 [MAX_BLYNK_SERVER_LEN + 1] = "account.ddns.net";
char Blynk_Token2 [MAX_BLYNK_TOKEN_LEN + 1] = "token2";
#define MAX_BLYNK_PORT_LEN 6
char Blynk_Port [MAX_BLYNK_PORT_LEN + 1] = "8080";
#define MAX_MQTT_SERVER_LEN 34
char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "mqtt.duckdns.org";
MenuItem myMenuItems [] =
{
{ "sv1", "Blynk Server1", Blynk_Server1, MAX_BLYNK_SERVER_LEN },
{ "tk1", "Token1", Blynk_Token1, MAX_BLYNK_TOKEN_LEN },
{ "sv2", "Blynk Server2", Blynk_Server2, MAX_BLYNK_SERVER_LEN },
{ "tk2", "Token2", Blynk_Token2, MAX_BLYNK_TOKEN_LEN },
{ "prt", "Port", Blynk_Port, MAX_BLYNK_PORT_LEN },
{ "mqt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },
};
uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;
#else
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
#endif //USE_DYNAMIC_PARAMETERS
#endif //dynamicParams_h
1. ESP_WiFi on ESP32_DEV
This is the terminal output when running ESP_WiFi example on ESP32_DEV:
Starting ESP_WiFi 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] Multi or Double Reset Detected
[WML] Hostname=ESP32-Controller
[WML] LoadCfgFile
[WML] OK
[WML] ======= Start Stored Config Data =======
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_WM_Lite
[WML] i=0,id=sv1,data=account.duckdns.org
[WML] i=1,id=tk1,data=token1
[WML] i=2,id=sv2,data=account.ddns.net
[WML] i=3,id=tk2,data=token2
[WML] i=4,id=prt,data=8080
[WML] i=5,id=mqt,data=mqtt.duckdns.org
[WML] CCSum=0x137c,RCSum=0x137c
[WML] LoadCredFile
[WML] CrR:pdata=new.duckdns.org,len=34
[WML] CrR:pdata=token1,len=34
[WML] CrR:pdata=new.ddns.net,len=34
[WML] CrR:pdata=token2,len=34
[WML] CrR:pdata=8080,len=6
[WML] CrR:pdata=mqtt.duckdns.org,len=34
[WML] OK
[WML] CrCCsum=0x163b,CrRCsum=0x163b
[WML] Valid Stored Dynamic Data
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_WM_Lite
[WML] i=0,id=sv1,data=new.duckdns.org
[WML] i=1,id=tk1,data=token1
[WML] i=2,id=sv2,data=new.ddns.net
[WML] i=3,id=tk2,data=token2
[WML] i=4,id=prt,data=8080
[WML] i=5,id=mqt,data=mqtt.duckdns.org
[WML] Check if isForcedCP
[WML] LoadCPFile
[WML] OK
[WML] bg: isForcedConfigPortal = false
[WML] bg:Stay forever in CP:DRD/MRD
[WML] clearForcedCP
[WML] SaveCPFile
[WML] OK
[WML] SaveBkUpCPFile
[WML] OK
[WML]
stConf:SSID=ESP_9ABF498,PW=MyESP_9ABF498
[WML] IP=192.168.4.1,ch=10
[WML] s:millis() = 1014, configTimeout = 121014
F
Your stored Credentials :
Blynk Server1 = new.duckdns.org
Token1 = token1
Blynk Server2 = new.ddns.net
Token2 = token2
Port = 8080
MQTT Server = mqtt.duckdns.org
FFFFFFFFF
Starting ESP_WiFi 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] LoadCfgFile
[WML] OK
[WML] ======= Start Stored Config Data =======
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_WM_Lite
[WML] i=0,id=sv1,data=account.duckdns.org
[WML] i=1,id=tk1,data=token1
[WML] i=2,id=sv2,data=account.ddns.net
[WML] i=3,id=tk2,data=token2
[WML] i=4,id=prt,data=8080
[WML] i=5,id=mqt,data=mqtt.duckdns.org
[WML] LoadCredFile
[WML] OK
[WML] Valid Stored Dynamic Data
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_WM_Lite
[WML] i=0,id=sv1,data=new.duckdns.org
[WML] i=1,id=tk1,data=token1
[WML] i=2,id=sv2,data=new.ddns.net
[WML] i=3,id=tk2,data=token2
[WML] i=4,id=prt,data=8080
[WML] i=5,id=mqt,data=mqtt.duckdns.org
[WML] LoadCPFile
[WML] OK
H
Your stored Credentials :
Blynk Server1 = new.duckdns.org
Token1 = token1
Blynk Server2 = new.ddns.net
Token2 = token2
Port = 8080
MQTT Server = mqtt.duckdns.org
Stop multiResetDetecting
Saving config file...
Saving config file OK
HHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHH
[WML] run: WiFi lost. Reconnect WiFi
[WML] Connecting MultiWifi...
[WML] WiFi connected after time: 2
[WML] SSID=HueNet2,RSSI=-54
[WML] Channel=4,IP=192.168.2.82
[WML] run: WiFi reconnected
H
HHHHHHHHHH HHHHHHHHHH
2. ESP_WiFi_MQTT on ESP8266_NODEMCU
This is the terminal output when running ESP_WiFi_MQTT example on ESP8266_NODEMCU:
Starting ESP_WiFi_MQTT using LittleFS on ESP8266_NODEMCU
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] Hostname=ESP8266-Controller
[WML] LoadCfgFile
[WML] OK
[WML] ======= Start Stored Config Data =======
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP8266_WM_Lite
[WML] i=0,id=svr,data=io.adafruit.com
[WML] i=1,id=prt,data=1883
[WML] i=2,id=usr,data=private
[WML] i=3,id=key,data=private
[WML] i=4,id=pub,data=/feeds/Temperature
[WML] i=5,id=sub,data=/feeds/LED_Control
[WML] LoadCredFile
[WML] OK
[WML] Invalid Stored Dynamic Data. Ignored
[WML] InitCfgFile,sz=236
[WML] SaveCfgFile
[WML] WCSum=0xda0
[WML] OK
[WML] SaveBkUpCfgFile
[WML] OK
[WML] SaveCredFile
[WML] OK
[WML] CrWCSum=0xc30
[WML] SaveBkUpCredFile
[WML] OK
[WML] LoadCPFile
[WML] OK
[WML] bg:Stay forever in CP:No ConfigDat
[WML] SaveCPFile
[WML] OK
[WML] SaveBkUpCPFile
[WML] OK
N
Your stored Credentials :
AIO_SERVER = blank
AIO_SERVERPORT = blank
AIO_USERNAME = blank
AIO_KEY = blank
AIO_PUB_TOPIC = blank
AIO_SUB_TOPIC = blank
NStop multiResetDetecting
Saving config file...
Saving config file OK
NNN
[WML] h:UpdLittleFS
[WML] SaveCfgFile
[WML] WCSum=0x13a5
[WML] OK
[WML] SaveBkUpCfgFile
[WML] OK
[WML] SaveCredFile
[WML] OK
[WML] CrWCSum=0x2236
[WML] SaveBkUpCredFile
[WML] OK
[WML] h:Rst
Starting ESP_WiFi_MQTT using LittleFS on ESP8266_NODEMCU
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] Hostname=ESP8266-Controller
[WML] LoadCfgFile
[WML] OK
[WML] ======= Start Stored Config Data =======
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP8266_WM_MQTT
[WML] i=0,id=svr,data=io.adafruit.com
[WML] i=1,id=prt,data=1883
[WML] i=2,id=usr,data=private
[WML] i=3,id=key,data=private
[WML] i=4,id=pub,data=/feeds/Temperature
[WML] i=5,id=sub,data=/feeds/LED_Control
[WML] LoadCredFile
[WML] OK
[WML] Valid Stored Dynamic Data
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP8266_WM_MQTT
[WML] i=0,id=svr,data=io.adafruit.com
[WML] i=1,id=prt,data=1883
[WML] i=2,id=usr,data=user_name
[WML] i=3,id=key,data=aio_key
[WML] i=4,id=pub,data=/feeds/Temperature
[WML] i=5,id=sub,data=/feeds/LED_Control
[WML] LoadCPFile
[WML] OK
[WML] Connecting MultiWifi...
[WML] WiFi connected after time: 1
[WML] SSID=HueNet1,RSSI=-43
[WML] Channel=2,IP=192.168.2.98
[WML] bg: WiFi 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!
TW
Your stored Credentials :
AIO_SERVER = io.adafruit.com
AIO_SERVERPORT = 1883
AIO_USERNAME = user_name
AIO_KEY = aio_key
AIO_PUB_TOPIC = /feeds/Temperature
AIO_SUB_TOPIC = /feeds/LED_Control
Stop multiResetDetecting
Saving config file...
Saving config file OK
TWTWTWTW TW
[WML] run: WiFi lost. Reconnect WiFi
[WML] Connecting MultiWifi...
[WML] WiFi connected after time: 1
[WML] SSID=HueNet2,RSSI=-54
[WML] Channel=4,IP=192.168.2.98
[WML] run: WiFi reconnected
H
3. ESP_WiFi_MQTT on ESP32S2_DEV
This is the terminal output when running ESP_WiFi_MQTT example on ESP32S2_DEV:
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_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] Hostname=ESP32-Controller
[WML] Check if isForcedCP
[WML] LoadCPFile
[WML] OK
[WML] bg: isForcedConfigPortal = false
[WML] bg:Stay forever in CP:No ConfigDat
[WML] clearForcedCP
[WML] SaveCPFile
[WML] OK
[WML] SaveBkUpCPFile
[WML] OK
[WML]
stConf:SSID=ESP_8A1DF7C,PW=MyESP_8A1DF7C
[WML] IP=192.168.4.1,ch=1
[WML] s:configTimeout = 0
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
NStop multiResetDetecting
Saving config file...
Saving config file OK
NNN N
[WML] h: Init menuItemUpdated
[WML] h:repl id
[WML] h:items updated =1
[WML] h:key =id, value =HueNet1
[WML] h:repl pw
[WML] h:items updated =2
[WML] h:key =pw, value =12345678
[WML] h:repl id1
[WML] h:items updated =3
[WML] h:key =id1, value =HueNet2
[WML] h:repl pw1
[WML] h:items updated =4
[WML] h:key =pw1, value =12345678
[WML] h:repl nm
[WML] h:items updated =5
[WML] h:key =nm, value =ESP32_S2
[WML] h:svr=io.adafruit.com
[WML] h:items updated =6
[WML] h:key =svr, value =io.adafruit.com
[WML] h:prt=1883
[WML] h:items updated =7
[WML] h:key =prt, value =1883
[WML] h:usr=user_name
[WML] h:items updated =8
[WML] h:key =usr, value =user_name
[WML] h:key=aio_key
[WML] h:items updated =9
[WML] h:key =key, value =aio_key
[WML] h:pub=/feeds/Temperature
[WML] h:items updated =10
[WML] h:key =pub, value =/feeds/Temperature
[WML] h:sub=/feeds/LED_Control
[WML] h:items updated =11
[WML] h:key =sub, value =/feeds/LED_Control
[WML] h:UpdLittleFS
[WML] SaveCfgFile
[WML] WCSum=0x1170
[WML] OK
[WML] SaveBkUpCfgFile
[WML] OK
[WML] SaveCredFile
[WML] CW1:pdata=io.adafruit.com,len=20
[WML] CW1:pdata=1883,len=6
[WML] CW1:pdata=user_name,len=20
[WML] CW1:pdata=aio_key,len=40
[WML] CW1:pdata=/feeds/Temperature,len=40
[WML] CW1:pdata=/feeds/LED_Control,len=40
[WML] OK
[WML] CrWCSum=0x2236
[WML] SaveBkUpCredFile
[WML] CW2:pdata=io.adafruit.com,len=20
[WML] CW2:pdata=1883,len=6
[WML] CW2:pdata=user_name,len=20
[WML] CW2:pdata=aio_key,len=40
[WML] CW2:pdata=/feeds/Temperature,len=40
[WML] CW2:pdata=/feeds/LED_Control,len=40
[WML] OK
[WML] h:Rst
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40025f35
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x8
load:0x3ffe6108,len:0x608
load:0x4004c000,len:0xa38
load:0x40050000,len:0x2848
entry 0x4004c190
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_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] Hostname=ESP32-Controller
[WML] LoadCfgFile
[WML] OK
[WML] ======= Start Stored Config Data =======
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_S2
[WML] i=0,id=svr,data=io.adafruit.com
[WML] i=1,id=prt,data=1883
[WML] i=2,id=usr,data=private
[WML] i=3,id=key,data=private
[WML] i=4,id=pub,data=/feeds/Temperature
[WML] i=5,id=sub,data=/feeds/LED_Control
[WML] CCSum=0x1170,RCSum=0x1170
[WML] LoadCredFile
[WML] CrR:pdata=io.adafruit.com,len=20
[WML] CrR:pdata=1883,len=6
[WML] CrR:pdata=user_name,len=20
[WML] CrR:pdata=aio_key,len=40
[WML] CrR:pdata=/feeds/Temperature,len=40
[WML] CrR:pdata=/feeds/LED_Control,len=40
[WML] OK
[WML] CrCCsum=0x2236,CrRCsum=0x2236
[WML] Valid Stored Dynamic Data
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_S2
[WML] i=0,id=svr,data=io.adafruit.com
[WML] i=1,id=prt,data=1883
[WML] i=2,id=usr,data=user_name
[WML] i=3,id=key,data=aio_key
[WML] i=4,id=pub,data=/feeds/Temperature
[WML] i=5,id=sub,data=/feeds/LED_Control
[WML] Check if isForcedCP
[WML] LoadCPFile
[WML] OK
[WML] bg: noConfigPortal = true
[WML] Connecting MultiWifi...
[WML] WiFi connected after time: 1
[WML] SSID=HueNet1,RSSI=-19
[WML] Channel=2,IP=192.168.2.116
[WML] bg: WiFi OK.
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!
TW
Your stored Credentials :
AIO_SERVER = io.adafruit.com
AIO_SERVERPORT = 1883
AIO_USERNAME = user_name
AIO_KEY = aio_key
AIO_PUB_TOPIC = /feeds/Temperature
AIO_SUB_TOPIC = /feeds/LED_Control
TWTWTWTW TW
[WML] run: WiFi lost. Reconnect WiFi
[WML] Connecting MultiWifi...
[WML] WiFi connected after time: 1
[WML] SSID=HueNet2,RSSI=-54
[WML] Channel=4,IP=192.168.2.116
[WML] run: WiFi reconnected
H
4. ESP_WiFi_MQTT on ESP32S2_DEV to demo MultiResetDetector
This is the terminal output when running ESP_WiFi_MQTT example on ESP32S2_DEV
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_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]
stConf:SSID=ESP_8A1DF7C,PW=MyESP_8A1DF7C
[WML] IP=192.168.4.1,ch=3
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
NNNN NNNNN NNNNN NNNNN NN[WML] h:UpdLittleFS
[WML] h:Rst
Starting ESP_WiFi_MQTT using LittleFS on ESP32S2_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-S2
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32-S2
[WML] WiFi connected after time: 1
[WML] SSID=HueNet1,RSSI=-41
[WML] Channel=2,IP=192.168.2.157
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!
TW
Your stored Credentials :
AIO_SERVER = io.adafruit.com
AIO_SERVERPORT = 1883
AIO_USERNAME = user_name
AIO_KEY = aio_key
AIO_PUB_TOPIC = /feeds/Temperature
AIO_SUB_TOPIC = /feeds/LED_Control
TWTWTWTW TWTWTWTWTW TWTW
5. ESP_WiFi_MQTT on ESP32_DEV to demo WiFi Scan
This is the terminal output when running ESP_WiFi example on ESP32_DEV with WiFi Scan for selection in Configuration 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
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
Debug is enabled by default on Serial. To disable, add at the beginning of sketch
/* Comment this out to disable prints and save space */
#define ESP_WM_LITE_DEBUG_OUTPUT Serial
#define _ESP_WM_LITE_LOGLEVEL_ 3
#define USING_MRD true
#if USING_MRD
#define MULTIRESETDETECTOR_DEBUG true
#else
#define DOUBLERESETDETECTOR_DEBUG true
#endif
If you get compilation errors, more often than not, you may need to install a newer version of the board's core or this library version.
- Enable scan of WiFi networks for selection in Configuration Portal. Check PR for v1.3.0 - Enable scan of WiFi networks #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-15)
- Minor enhancement to not display garbage when data is invalid
- 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.
- Add EEPROM and SPIFFS support to new ESP32-C3 boards (Arduino ESP32C3_DEV). Check HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE.
- Fix invalid "blank" Config Data treated as Valid.
- Permit optionally inputting one set of WiFi SSID/PWD by using
REQUIRE_ONE_SET_SSID_PW == true
- Enforce WiFi PWD minimum length of 8 chars
- Fix bug where EEPROM_SIZE truncated by DRD/MRD to 512, resulting lost and corrupted data.
- Fix crashing bug in serverSendHeaders()
- Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header.
- Fix Config Portal Bug.
- Update examples
- Add support to ESP32-S2 (ESP32-S2 Saola and AI-Thinker ESP-12K)
- Add instruction to install ESP32-S2 core
- Initial release to support ESP32 and ESP8266.
Submit issues to: ESP_WiFiManager_Lite issues
- Support more boards, shields and libraries
- Bug Searching and Killing
- Permit EEPROM size and location configurable to avoid conflict with others.
- More flexible to configure reconnection timeout.
- For fresh config data, don't need to wait for connecting timeout before entering config portal.
- If the config data not entered completely (SSIDs, Passwords, etc.), entering config portal
- Add configurable Config Portal IP, SSID and Password
- Change Synch XMLHttpRequest to Async
- Add configurable Static IP, GW, Subnet Mask and 2 DNS Servers' IP Addresses.
- Add checksums
- Add support to ESP32 including ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.) and ESP8266
- Add MultiWiFi features with auto(re)connect
- Easy-to-use Dynamic Parameters without the necessity to write complicated ArduinoJSon functions
- Permit to input special chars such as % and # into data fields.
- Default Credentials and dynamic parameters
- Multi/DoubleDetectDetector to force Config Portal when multi/double reset is detected within predetermined time, default 10s.
- Configurable Config Portal Title
- Re-structure all examples to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device.
- Add Table of Contents and Version String
- Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header
- Permit optionally inputting one set of WiFi SSID/PWD by using
REQUIRE_ONE_SET_SSID_PW == true
- Enforce WiFi PWD minimum length of 8 chars
- Add support to ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.) using EEPROM, LittleFS and SPIFFS
- Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header
- Add support to ESP32-C3 using EEPROM and SPIFFS
- Enable scan of WiFi networks for selection in Configuration Portal
Please help contribute to this project and add your name here.
- Thanks to Michael H. "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 leading to v1.5.0
⭐️⭐️ Michael H. "bizprof" |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under MIT
Copyright 2021- Khoi Hoang