Blynk Async_WM for ESP8266/ESP32 with Multi-WiFi and Multi-Blynk, using AsyncWebServer. Fix SSL issue for Blynk Cloud Server now

Blynk_Async_WM

arduino-library-badge GitHub release GitHub contributions welcome GitHub issues



Why do we need this Blynk_Async_WM 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 extensible 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

This is a Blynk and WiFiManager Library, using ESPAsyncWebServer instead of (ESP8266)WebServer, for configuring/auto(re)connecting ESP8266/ESP32 modules to the best or available MultiWiFi APs and MultiBlynk servers at runtime. Connection is with or without SSL. Configuration data to be saved in either LittleFS, SPIFFS or EEPROM. Default Credentials as well as Dynamic custom parameters can be added and modified easily without coding knowledge. DoubleResetDetector is used to force Config Portal opening even if the Credentials are still valid.

This library is designed to help you to eliminate hardcoding your Wifi and Blynk credentials for ESP8266 and ESP32 (with/without SSL), and updating/reflashing every time you need to change them.

Thanks to this Blynk_Async_WM library is based on and sync’ed with Blynk_WM library, all the features currently supported by Blynk_WM library will be available. Please have a look at Blynk_WM library for those too-many-to-list features.


Releases v1.0.16

  1. Initial coding to use ESPAsyncWebServer instead of (ESP8266)WebServer.
  2. Bump up to v1.0.16 to sync with Blynk_WiFiManager library v1.0.16.

So, how it works?

If it cannot connect to the Blynk server in 30 seconds, no valid stored Credentials or Double Reset is detected within default abd configurable 10s, it will switch to Configuration Mode. You will see your built-in LED turned ON. In Configuration Mode, it starts an AP with default name ESP_xxxxxx and password MyESP_xxxxxx or configurable name and password you specified. The AP IP address is default at 192.168.4.1 or configured IP (e.g. 192.168.200.1).

First, connect your (PC, Laptop, Tablet, phone, etc.) WiFi to Config Portal AP, then enter the WiFi password :

  1. If you choose not to load default Credentials and Dynamic Parameters

After you connected, please, go to http://192.168.4.1 or the configured AP IP. The following Config Portal screen will appear:

  1. If you choose to load default Credentials and Dynamic Parameters

After you connected, please, go to http://192.168.4.1 or the configured AP IP. The following Config Portal screen will appear:

Enter your WiFi and Blynk Credentials:

Then click Save. The system will auto-restart. You will see the board’s built-in LED turned OFF. That means, it’s already connected to your Blynk server successfully.


How to migrate from Blynk_WiFiManager library

In your code, just replacing

  1. BlynkSimpleEsp8266_WM.h with BlynkSimpleEsp8266_Async_WM.h for ESP8266 without SSL
  2. BlynkSimpleEsp8266_SSL_WM.h with BlynkSimpleEsp8266_SSL_Async_WM.h for ESP8266 with SSL
  3. BlynkSimpleEsp32_WM.h with BlynkSimpleEsp32_Async_WM.h for ESP32 without SSL
  4. BlynkSimpleEsp32_SSL_WM.h with BlynkSimpleEsp32_SSL_Async_WM.h for ESP32 with SSL

How to migrate from Blynk

In your code, replace

  1. BlynkSimpleEsp8266.h with BlynkSimpleEsp8266_Async_WM.h for ESP8266 without SSL
  2. BlynkSimpleEsp8266_SSL.h with BlynkSimpleEsp8266_SSL_Async_WM.h for ESP8266 with SSL
  3. BlynkSimpleEsp32.h with BlynkSimpleEsp32_Async_WM.h for ESP32 without SSL
  4. BlynkSimpleEsp32_SSL.h with BlynkSimpleEsp32_SSL_Async_WM.h for ESP32 with SSL
2 Likes

Updated Nov 27th 2020

Releases v1.1.0

  1. Add examples using RTOS MultiTask to avoid blocking in operation.
  2. Add Version String.

These are new examples

Using Free-RTOS MultiTasking for ESP32

  1. Async_ESP32_MultiTask
  2. AsyncMT_AM2315_ESP32_SSL
  3. AsyncMT_DHT11ESP32
  4. AsyncMT_DHT11ESP32_SSL
  5. AsyncMT_ESP32WM_Config

Updated April 19th 2021

Major Releases 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.
  2. 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.
  3. Fix SSL issue with Blynk Cloud Server
  4. Update examples

Major Releases v1.3.0

  1. Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header.
  2. Add support to ESP32-S2 (ESP32-S2 Saola and AI-Thinker ESP-12K). Currently using EEPROM only. To add support to LittleFS and SPIFFS in future releases.
  3. Fix Config Portal Bug.
  4. Tested with Latest ESP32 Core 1.0.5 for ESP32-based boards.
  5. Update examples

Debug Terminal Output

Async_ESP32WM_ForcedConfig using LittleFS with SSL on ESP32S2_DEV

The following is the sample terminal output when running example Async_ESP32WM_ForcedConfig on ESP32S2_DEV to demonstrate the usage of SSL, Blynk and LittleFS.

Starting Async_ESP32WM_ForcedConfig using LittleFS with SSL on ESP32S2_DEV
Blynk_Async_WM SSL for ESP32 v1.4.0
ESP_DoubleResetDetector v1.1.1
[958] Set CustomsStyle to : <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>
[980] Set CustomsHeadElement to : <style>html{filter: invert(10%);}</style>
[987] Set CORS Header to : Your Access-Control-Allow-Origin
[1202] Hostname=ESP32-Async-Controller
[1247] LoadCfgFile 
[1253] OK
[1253] ======= Start Stored Config Data =======
[1253] Hdr=SSL_ESP32,BrdName=ESP32-S2
[1253] SSID=HueNet1,PW=12345678
[1253] SSID1=HueNet2,PW1=12345678
[1256] Server=blynk-cloud.com,Token=token
[1262] Server1=blynk-cloud.com,Token1=token
[1269] Port=9443
[1270] ======= End Config Data =======
[1274] CCSum=0x2f32,RCSum=0x2f32
[1291] LoadCredFile 
[1297] CrR:pdata=default-mqtt-server,len=34
[1297] CrR:pdata=1883,len=6
[1297] CrR:pdata=default-mqtt-username,len=34
[1297] CrR:pdata=default-mqtt-password,len=34
[1301] CrR:pdata=default-mqtt-SubTopic,len=34
[1305] CrR:pdata=default-mqtt-PubTopic,len=34
[1309] OK
[1310] CrCCsum=0x29a6,CrRCsum=0x29a6
[1313] Valid Stored Dynamic Data
[1316] Hdr=SSL_ESP32,BrdName=ESP32-S2
[1319] SSID=HueNet1,PW=12345678
[1322] SSID1=HueNet2,PW1=12345678
[1325] Server=blynk-cloud.com,Token=token
[1331] Server1=blynk-cloud.com,Token1=token
[1337] Port=9443
[1339] ======= End Config Data =======
[1342] Check if isForcedCP
[1358] LoadCPFile 
[1363] OK
[1364] bg: noConfigPortal = true
[1364] Connecting MultiWifi...
[11065] WiFi connected after time: 1
[11065] SSID: HueNet1, RSSI = -45
[11066] Channel: 2, IP address: 192.168.2.157
[11066] bg: WiFi OK. Try Blynk
[11067] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP32

[16081] NTP time: Mon Apr 19 23:16:54 2021
[16081] BlynkArduinoClient.connect: Connecting to blynk-cloud.com:9443
[16702] Certificate OK
[16725] Ready (ping: 21ms).
[16793] Connected to Blynk Server = blynk-cloud.com, Token = token
[16794] bg: WiFi+Blynk OK

Blynk ESP32 using LittleFS connected.
Board Name : ESP32-S2
B
Your stored Credentials :
MQTT Server = default-mqtt-server
Port = 1883
MQTT UserName = default-mqtt-username
MQTT PWD = default-mqtt-password
Subs Topics = default-mqtt-SubTopic
Pubs Topics = default-mqtt-PubTopic

Updated April 25th 2021

Now you can enable scan of WiFi networks for selection in Configuration Portal and don’t have to input SSIDs manually

Major Releases 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. 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)
  2. Fix invalid “blank” Config Data treated as Valid.
  3. Permit optionally inputting one set of WiFi SSID/PWD by using REQUIRE_ONE_SET_SSID_PW == true
  4. Enforce WiFi PWD minimum length of 8 chars
  5. Minor enhancement to not display garbage when data is invalid

Releases v1.4.1

  1. Fix issue of custom Blynk port (different from 8080 or 9443) not working on ESP32. Check Custom Blynk port not working for BlynkSimpleEsp32_Async_WM.h #4
2 Likes

Updated May 20th 2021

Major Releases v1.6.0

  1. Fix AP connect issue caused by breaking ESP8266 core v3.0.0. Caused by multiple core changes, but the new solution results a better and faster connection to AP.
  2. Fix SSL issue caused by breaking ESP8266 core v3.0.0. Now the better BearSSL is used in both ESP32 and ESP8266 to replace the ESP8266 deprecated axTLS. Check Remove axTLS from code and documentation #7437
  3. Fix the BLYNK_INFO_DEVICEdisplaying the generic ESP8266 board with Blynk logo. Caused by new ESP8266 core changes of build.board. For example from ESP8266_NODEMCU in core v2.7.4 to ESP8266_NODEMCU_ESP12E in core v3.0.0
  4. Fix many warnings only displayed in new core ESP8266 v3.0.0
  5. Make code compatible for either new ESP8266 core v3.0.0+ or ealier cores v2.7.4-

Async_ESP8266WM_MRD_Config using LITTLEFS with SSL on ESP8266_NODEMCU_ESP12E using new ESP8266 core v3.0.0

The following is the sample terminal output when running example Async_ESP8266WM_MRD_Config on ESP8266_NODEMCU_ESP12E using new ESP8266 core v3.0.0

Starting Async_ESP8266WM_MRD_Config using LittleFS with SSL on ESP8266_NODEMCU_ESP12E
ESP8266 core v3.0.0
Blynk_Async_WM SSL for ESP8266 v1.6.0
ESP_MultiResetDetector v1.1.1
[268] Set CustomsStyle to : <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>
[290] Set CustomsHeadElement to : <style>html{filter: invert(10%);}</style>
[297] Set CORS Header to : Your Access-Control-Allow-Origin
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
[348] Hostname=ESP8266-Async-Config
[370] LoadCfgFile 
[370] OK
[371] ======= Start Stored Config Data =======
[371] Hdr=SSL_ESP8266,BrdName= ESP8266_NODEMCU_ESP12E
[371] SSID=HueNet1,PW=password
[373] SSID1=HueNet2,PW1=password
[376] Server=account.duckdns.org,Token=token
[383] Server1=account.duckdns.org,Token1=token1
[389] Port=9443
[390] ======= End Config Data =======
[394] CCSum=0x395d,RCSum=0x395d
[400] LoadCredFile 
[400] CrR:pdata=default-mqtt-server,len=34
[402] CrR:pdata=1883,len=6
[405] CrR:pdata=default-mqtt-username,len=34
[409] CrR:pdata=default-mqtt-password,len=34
[413] CrR:pdata=default-mqtt-SubTopic,len=34
[417] CrR:pdata=default-mqtt-PubTopic,len=34
[421] OK
[422] CrCCsum=0x29a6,CrRCsum=0x29a6
[425] Valid Stored Dynamic Data
[428] Hdr=SSL_ESP8266,BrdName= ESP8266_NODEMCU_ESP12E
[432] SSID=HueNet1,PW=password
[435] SSID1=HueNet2,PW1=password
[438] Server=account.duckdns.org,Token=token
[444] Server1=account.duckdns.org,Token1=token1
[451] Port=9443
[452] ======= End Config Data =======
[455] Check if isForcedCP
[462] LoadCPFile 
[462] OK
[462] bg: noConfigPortal = true
[463] Connecting MultiWifi...
[5563] WiFi connected after time: 1
[5563] SSID: HueNet1, RSSI = -43
[5564] Channel: 2, IP address: 192.168.2.135
[5564] bg: WiFi OK. Try Blynk
[5565] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP8266_NODEMCU_ESP12E

[6580] NTP time: Thu May 20 04:54:30 2021
[6612] BlynkArduinoClient.connect: Connecting to account.duckdns.org:9443
[7369] Certificate OK
[7375] Ready (ping: 1ms).
[7451] Connected to Blynk Server = account.duckdns.org, Token = token
[7451] bg: WiFi+Blynk OK

Blynk ESP8266 using LittleFS connected.
Board Name :  ESP8266_NODEMCU_ESP12E
B
Your stored Credentials :
MQTT Server = default-mqtt-server
Port = 1883
MQTT UserName = default-mqtt-username
MQTT PWD = default-mqtt-password
Subs Topics = default-mqtt-SubTopic
Pubs Topics = default-mqtt-PubTopic
Stop multiResetDetecting
Saving config file...
Saving config file OK
BBB

Hello
I use this wonderful library
I have a problem
If I use begin() function and wifi is connected but Internet is down the code loop in Connecting to Cloud
Is possible to set a timeout like in connect() function?
Thank you

If you’re referring to Blynk.begin() then the answer is no, it’s a blocking function.

Pete.

thanks a lot for answer
Is there any suggestion to bypass this situation?
Is it mandatory to use Blynk.begin() ?

Max

The alternative is Blynk.config() and Blynk.connect
Blynk.connect() is optional, and every time Blynk.run() is encountered and Blynk.connected() == false then a connection attempt will be made.

Blynk.connect() allows an optional timeout to be specified (otherwise the default of around 18 seconds will apply.
Care needs to be taken to not continuously call Blynk.run() if Blynk.connected == false if you want to maintain some offline functionality, otherwise the timeout period will be continually be in effect.

Pete.