ESPAsync_WiFiManager
How To Install Using Arduino Library Manager
Why do we need this ESPAsync_WiFiManager Library
- Using asynchronous network means that you can handle more than one connection at the same time
- You are called once the request is ready and parsed
- When you send the response, you are immediately ready to handle other connections while the server is taking care of sending the response in the background
- Speed is OMG
- Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse
- Easily extendible to handle **any type of content**
- Supports Continue 100%
- Async WebSocket plugin offering different locations without extra servers or ports
- Async EventSource (Server-Sent Events) plugin to send events to the browser
- URL Rewrite plugin for conditional and permanent url rewrites
- ServeStatic plugin that supports cache, Last-Modified, default index and more
- Simple template processing engine to handle templates
New in v1.0.11
1. Initial coding to use ESPAsyncWebServer instead of (ESP8266)WebServer.
2. Bump up to v1.0.11 to sync with ESP_WiFiManager v1.0.11.
So, how it works?
In ConfigPortal Mode, it starts an access point called ESP_XXXXXX. Connect to it using the configurable password you can define in the code. For example, your_password (see examples):
Code: Select all
// SSID and PW for Config Portal
String ssid = "ESP_" + String(ESP_getChipId(), HEX);
const char* password = "your_password";
Select `Information` to enter the Info page where the board info will be shown (long page)
or short page (default)
Select Configuration to enter this page where you can select an AP and specify its WiFi Credentials
Enter your credentials, then click Save. The WiFi Credentials will be saved and the board reboots to 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 Portal from the Main page to reboot the board and connect to the previously-stored AP. The WiFi Credentials are still intact.
Debug Termimal Output Samples
1. This is terminal debug output when running Async_ConfigOnSwitchFS_MQTT_Ptr on ESP8266 NodeMCU 1.0.. Config Portal was requested to input and save MQTT Credentials. The boards then connected to Adafruit MQTT Server successfully.
Code: Select all
Starting Async_ConfigOnSwichFS_MQTT_Ptr on ESP8266_NODEMCU
LittleFS opened: OK
Configuration file not found
Failed to read configuration file, using default values
[WM] RFC925 Hostname = ConfigOnSwichFS-MQTT
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
Stored: SSID = HueNet1, Pass = 12345678
Connecting to HueNet1
After waiting 5 secs more in setup(), connection result is connected. Local IP: 192.168.2.148
[WM] freeing allocated params!
Creating new WiFi client object OK
Creating new MQTT object OK
AIO_SERVER = , AIO_SERVERPORT = 0
AIO_USERNAME = , AIO_KEY =
Creating new MQTT_Pub_Topic, Temperature = /feeds/Temperature
Creating new Temperature object OK
Temperature MQTT_Pub_Topic = /feeds/Temperature
Connecting to WiFi MQTT (3 attempts)...
Connection failed
Another attemtpt to connect to MQTT in 2 seconds...
Connection failed
Another attemtpt to connect to MQTT in 2 seconds...
Connection failed
Another attemtpt to connect to MQTT in 2 seconds...
WiFi MQTT connection failed. Continuing with program...
FW
Button double clicked!
Connecting to WiFi MQTT (3 attempts)...
Connection failed
Another attemtpt to connect to MQTT in 2 seconds...
Connection failed
Another attemtpt to connect to MQTT in 2 seconds...
Connection failed
Another attemtpt to connect to MQTT in 2 seconds...
WiFi MQTT connection failed. Continuing with program...
FW
Button clicked!
Configuration Portal requested.
[WM] RFC925 Hostname = ConfigOnDoubleReset
Opening Configuration Portal. Got stored Credentials. Timeout 120s
[WM] Adding parameter AIO_SERVER_Label
[WM] Adding parameter AIO_SERVERPORT_Label
[WM] Adding parameter AIO_USERNAME_Label
[WM] Adding parameter AIO_KEY_Label
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
[WM] WiFi.waitForConnectResult Done
[WM] SET AP_STA
[WM]
Configuring AP SSID = ESP_1190DD
[WM] AP PWD = your_password
[WM] AP Channel = 10
[WM] AP IP address = 192.168.4.1
[WM] HTTP server started
[WM] ESPAsync_WiFiManager::startConfigPortal : Enter loop
[WM] Custom STA IP/GW/Subnet
[WM] DNS1 and DNS2 set
[WM] setWifiStaticIP IP = 192.168.2.188
[WM] Connected after waiting (s) : 2.23
[WM] Local ip = 192.168.2.188
[WM] Timed out connection result: WL_CONNECTED
Connected...yeey :)
Local IP: 192.168.2.188
Saving config file
{
"AIO_SERVER_Label": "io.adafruit.com",
"AIO_SERVERPORT_Label": 1883,
"AIO_USERNAME_Label": "your_account",
"AIO_KEY_Label": "aio_********"
}
Config file was successfully saved
Deleting old MQTT object
Deleting old Temperature object
Creating new MQTT object OK
AIO_SERVER = io.adafruit.com, AIO_SERVERPORT = 1883
AIO_USERNAME = your_account, AIO_KEY = aio_********
Creating new MQTT_Pub_Topic, Temperature = your_account/feeds/Temperature
Creating new Temperature object OK
Temperature MQTT_Pub_Topic = your_account/feeds/Temperature
[WM] freeing allocated params!
Connecting to WiFi MQTT (3 attempts)...
WiFi MQTT connection successful!
TWTWTWTWTW TWTWTWTWTW TWTWTWTWTW TWTWTWTWTW TWTWTWTW
2. This is terminal debug output when running Async_ConfigOnDoubleReset on ESP32 ESP32_DEV.. Config Portal was requested by DRD to input and save Credentials. The boards then connected to WiFi using new Static IP successfully.
Code: Select all
Starting ConfigOnDoubleReset on ESP32_DEV
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
Stored: SSID = HueNet1, Pass = password
Got stored Credentials. Timeout 120s
SPIFFS Flag read = 0xd0d01234
doubleResetDetected
Saving config file...
Saving config file OK
Open Config Portal without Timeout: Double Reset Detected
Starting configuration portal.
[WM] WiFi.waitForConnectResult Done
[WM] SET AP
[WM]
Configuring AP SSID = ESP_9ABF498
[WM] AP PWD = your_password
[WM] AP Channel = 11
[WM] AP IP address = 192.168.4.1
[WM] HTTP server started
[WM] ESPAsync_WiFiManager::startConfigPortal : Enter loop
[WM] Connecting to new AP
[WM] Previous settings invalidated
[WM] Custom STA IP/GW/Subnet
[WM] DNS1 and DNS2 set
[WM] setWifiStaticIP IP = 192.168.2.222
[WM] Connect to new WiFi using new IP parameters
[WM] Connected after waiting (s) : 0.60
[WM] Local ip = 192.168.2.222
[WM] Connection result: WL_CONNECTED
WiFi connected...yeey :)
After waiting 0 secs more in setup(), connection result is connected. Local IP: 192.168.2.222
[WM] freeing allocated params!
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
3. This is terminal debug output when running Async_ConfigOnDoubleReset on ESP8266_NODEMCU.. Config Portal was requested by DRD to input and save Credentials. The boards then connected to WiFi using new Static IP successfully.
Code: Select all
Starting Async_ConfigOnDoubleReset on ESP8266_NODEMCU
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
Stored: SSID = HueNet1, Pass = 12345678
Got stored Credentials. Timeout 120s
LittleFS Flag read = 0xd0d01234
doubleResetDetected
Saving config file...
Saving config file OK
Open Config Portal without Timeout: Double Reset Detected
Starting configuration portal.
[WM] WiFi.waitForConnectResult Done
[WM] SET AP_STA
[WM]
Configuring AP SSID = ESP_1190DD
[WM] AP PWD = your_password
[WM] AP Channel = 8
[WM] AP IP address = 192.168.4.1
[WM] HTTP server started
[WM] ESPAsync_WiFiManager::startConfigPortal : Enter loop
[WM] Request redirected to captive portal
[WM] Handle root
[WM] Info
[WM] Info page sent
[WM] Handle root
[WM] Handle WiFi
[WM] handleWifi: Scan done
[WM] Static IP = 192.168.2.186
[WM] Sent config page
[WM] WiFi save
[WM] New Static IP = 192.168.2.186
[WM] New Static Gateway = 192.168.2.1
[WM] New Static Netmask = 255.255.255.0
[WM] New Static DNS1 = 192.168.2.1
[WM] New Static DNS2 = 8.8.8.8
[WM] Sent wifi save page
[WM] Custom STA IP/GW/Subnet
[WM] DNS1 and DNS2 set
[WM] setWifiStaticIP IP = 192.168.2.186
[WM] Connected after waiting (s) : 2.22
[WM] Local ip = 192.168.2.186
[WM] Timed out connection result: WL_CONNECTED
WiFi connected...yeey :)
After waiting 0 secs more in setup(), connection result is connected. Local IP: 192.168.2.186
[WM] freeing allocated params!
HHHHHHHHHH HHHHHHHHHH HHH