Blynk WiFiManager for ESP8266/ESP32 (including ESP32-S2, ESP32-C3) with Multi-WiFi and Multi-Blynk. Fix SSL issue for Blynk Cloud Server now

It’s nice to know the library can somehow help you.

The power failure issue can be hopefully solved by

  1. Using battery
  2. Using big electrolytic capacitor
  3. Using UPS (Uninterrupted Power Supply)
  4. You can also try to shorten the DRD time (default at 10s to something like 1s). But not sure can totally solve your power failure issue.
// Number of seconds after reset during which a
// subsequent reset will be considered a double reset.
#define DRD_TIMEOUT 10
  1. You can also use the SW, instead of DRD, to force the Config Portal.
    Compare the examples ConfigOnSwitch and ConfigOnDoubleReset and see how to change.

Good Luck,

It sounds like there should be a timeout added to the double reset config so that it will not hangup for too long.

The DRD is a different and independent library and you certainly can configure its features to whatever way you’d like.

For example, in the ConfigOnDoubleReset example, the time spent in Config Portal (CP) is forced to be indefinite by disable time-out, as this is considered as intentional to do some change to the Credentials. So the CP will stay until valid / new data are entered and saved.

Have a look at ConfigOnDoubleReset.ino Line 666-673 for a way to change the time-out

1. No timeout

  if (drd->detectDoubleReset())
  {
    // DRD, disable timeout.
    ESP_wifiManager.setConfigPortalTimeout(0);

    Serial.println("Open Config Portal without Timeout: Double Reset Detected");
    initialConfig = true;
  }

2. Timeout

If you don’t like to disable time-out, just specify the time-out different from 0.

  if (drd->detectDoubleReset())
  {
    // DRD, using timeout 180s
    ESP_wifiManager.setConfigPortalTimeout(180);

    Serial.println("Open Config Portal with 180s Timeout: Double Reset Detected");
    initialConfig = true;
  }

Looks like a reasonable way to handle the problem.

Updated Jan 1st 2021

Major Releases v1.1.0

  1. Add support to LittleFS for ESP32 using LittleFS_esp32 Library
  2. Add support to MultiDetectDetector. MultiDetectDetector feature to force Config Portal when configurable multi-reset is detected within predetermined time.
  3. Clean-up all compiler warnings possible.
  4. Add Table of Contents
  5. Add Version String
  6. Add MRD-related examples.
2 Likes

Bạn là người Việt Nam phải không?

Updated Feb 24th 2021

Major Releases v1.2.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

Releases v1.1.3

  1. To permit autoreset after configurable timeout if DRD/MRD or non-persistent forced-CP. Check Good new feature: Blynk.resetAndEnterConfigPortal() Thanks & question #27

Releases v1.1.2

  1. Fix rare Config Portal bug not updating Config and dynamic Params data successfully in very noisy or weak WiFi situation

Releases v1.1.1

  1. Add functions to control Config Portal from software or Virtual Switches. Check How to trigger a Config Portal from code #25
  2. Add examples to demo the new Virtual ConfigPortal SW feature
  3. Optimize code

Dear @khoih , congratulations on your work.
I realized that when the wi-fi + internet access are working normally and there is a failure in both due to a power outage or other similar problem that leaves them off for a time greater than or equal to 15 minutes and when they are turned on (wifi + access to internet working) esp8266 reconnects to wifi but cannot connect to the blynk-cloud server. Could you tell me why this is happening? thanks.

Sorry I have no idea what’s happening there as it doesn’t make sense at all.

What if you turn OFF power to the board more than 15 mins then turn back ON?

It’s possibly something wrong in your program and/or your network settings and only you can find out why. I’m afraid I can’t help you anything.

Good Luck,

15 minutes sounds like the amount of time that the router will hold a routing table entry for a device after it disappears off the network, but why that would prevent it re-connecting to the router later is a mystery to me.

I’d start by turning everything off then on again :grinning:

Pete.

2 posts were split to a new topic: Buttons not working when internet disconnected

I think the “auto start” that @Gyromike was asking for back in April '20 was a captive portal. It automatically presents the configuration page when in AP mode. Here’s an example I’ve successfully used with ESP32:

#include <WiFi.h>
#include <DNSServer.h>

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
WiFiServer server(80);
  
String responseHTML = ""
  "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>"
  "<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;} .l{background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==\") no-repeat left center;background-size: 1em;}</style>"
  "<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
  "be redirected here.</p></body></html>";

void setup() {
  Serial.begin(9600);
  
  if(!WiFi.isConnected()){
    Serial.println("No saved credentials.");
    GetCredentials();
  }
  else{
    Serial.println("Using saved credentials.");
  }
}

void loop() { 
}

void GetCredentials(){
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  WiFi.softAP("Captive Portal Test");

  // if DNSServer is started with "*" for domain name, it will reply with
  // provided IP to all DNS request
  dnsServer.start(DNS_PORT, "*", apIP);

  server.begin();

  while(1){
    dnsServer.processNextRequest();
    WiFiClient client = server.available();   // listen for incoming clients
  
    if (client) {
      String currentLine = "";
      while (client.connected()) {
        if (client.available()) {
          char c = client.read();
          if (c == '\n') {
            if (currentLine.length() == 0) {
              client.println("HTTP/1.1 200 OK");
              client.println("Content-type:text/html");
              client.println();
              client.print(responseHTML);
              break;
            } else {
              currentLine = "";
            }
          } else if (c != '\r') {
            currentLine += c;
          }
        }
      }
      client.stop();
    }
  }
}

Updated April 19th 2021

Major Releases v1.3.0

  1. Add LittleFS and SPIFFS support to new ESP32-S2 boards (Arduino ESP32S2_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
1 Like

Debug Terminal Output

ESP8266WM_MRD_ForcedConfig using LITTLEFS with SSL on ESP8266_NODEMCU

The following is the sample terminal output when running example ESP8266WM_MRD_ForcedConfig on ESP8266_NODEMCU. Please note that this fix the SSL issue with Blynk Cloud Server.

Starting ESP8266WM_MRD_ForcedConfig using LittleFS with SSL on ESP8266_NODEMCU
Blynk_WM SSL for ESP8266 v1.3.0
ESP_MultiResetDetector v1.1.1
[267] 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>
[289] Set CustomsHeadElement to : <style>html{filter: invert(10%);}</style>
[296] 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
[339] Hostname=8266-Master-Controller
[361] LoadCfgFile 
[361] OK
[361] ======= Start Stored Config Data =======
[361] Hdr=SSL_ESP8266,BrdName=ESP8266
[361] SSID=HueNet1,PW=12345678
[363] SSID1=HueNet2,PW1=12345678
[366] Server=blynk-cloud.com,Token=token1
[372] Server1=blynk-cloud.com,Token1=token2
[378] Port=9443
[379] ======= End Config Data =======
[383] CCSum=0x2fa3,RCSum=0x2fa3
[390] LoadCredFile 
[391] CrR:pdata=default-mqtt-server,len=34
[391] CrR:pdata=1883,len=6
[393] CrR:pdata=default-mqtt-username,len=34
[397] CrR:pdata=default-mqtt-password,len=34
[401] CrR:pdata=default-mqtt-SubTopic,len=34
[405] CrR:pdata=default-mqtt-PubTopic,len=34
[409] OK
[410] CrCCsum=0x29a6,CrRCsum=0x29a6
[413] Valid Stored Dynamic Data
[416] Hdr=SSL_ESP8266,BrdName=ESP8266
[420] SSID=HueNet1,PW=12345678
[423] SSID1=HueNet2,PW1=12345678
[425] Server=blynk-cloud.com,Token=token1
[431] Server1=blynk-cloud.com,Token1=token2
[438] Port=9443
[439] ======= End Config Data =======
[442] Check if isForcedCP
[450] LoadCPFile 
[450] OK
[450] bg: noConfigPortal = true
[450] Connecting MultiWifi...
[6667] WiFi connected after time: 1
[6667] SSID: HueNet1, RSSI = -46
[6667] Channel: 2, IP address: 192.168.2.92
[6668] bg: WiFi OK. Try Blynk
[6669] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[22695] NTP time: Mon Apr 19 06:36:31 2021
[22695] BlynkArduinoClient.connect: Connecting to blynk-cloud.com:9443
[23153] Ready (ping: 1ms).
[23245] Connected to Blynk Server = blynk-cloud.com, Token = token1
[23245] bg: WiFi+Blynk OK

Blynk ESP8266 using LittleFS connected.
Board Name : ESP8266
Stop multiResetDetecting
Saving config file...
Saving config file OK
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
BBBB

ESP32WM_MRD_Config using LITTLEFS with SSL on ESP32S2_DEV

The following is the sample terminal output when running example ESP32WM_MRD_Config on ESP8266_NODEMCU. Please note that this fix the SSL issue with Blynk Cloud Server and runs on new ESP32-S2 using LittleFS using esp32 core v1.0.6+ (not official release v1.0.6, but master release as of 2021/04/19).

Starting ESP32WM_MRD_Config using LITTLEFS with SSL on ESP32S2_DEV
Blynk_WM SSL for ESP32 v1.3.0
ESP_MultiResetDetector v1.1.1
[134394] 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>
[134417] Set CustomsHeadElement to : <style>html{filter: invert(10%);}</style>
[134424] 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
[134657] Hostname=ESP32-Master-Controller
[134695] LoadCfgFile 
[134700] OK
[134700] ======= Start Stored Config Data =======
[134700] Hdr=SSL_ESP32,BrdName=ESP8266
[134700] SSID=HueNet1,PW=12345678
[134701] SSID1=HueNet2,PW1=12345678
[134704] Server=account.duckdns.org,Token=token1
[134710] Server1=account.duckdns.org,Token1=token2
[134717] Port=9443
[134719] ======= End Config Data =======
[134722] CCSum=0x33eb,RCSum=0x33eb
[134738] LoadCredFile 
[134742] CrR:pdata=default-mqtt-server,len=34
[134743] CrR:pdata=1883,len=6
[134743] CrR:pdata=default-mqtt-username,len=34
[134743] CrR:pdata=default-mqtt-password,len=34
[134747] CrR:pdata=default-mqtt-SubTopic,len=34
[134751] CrR:pdata=default-mqtt-PubTopic,len=34
[134755] OK
[134756] CrCCsum=0x29a6,CrRCsum=0x29a6
[134760] Valid Stored Dynamic Data
[134763] Hdr=SSL_ESP32,BrdName=ESP8266
[134766] SSID=HueNet1,PW=12345678
[134769] SSID1=HueNet2,PW1=12345678
[134773] Server=account.duckdns.org,Token=token1
[134779] Server1=account.duckdns.org,Token1=token2
[134786] Port=9443
[134787] ======= End Config Data =======
[134791] Check if isForcedCP
[134806] LoadCPFile 
[134811] OK
[134811] bg: noConfigPortal = true
[134811] Connecting MultiWifi...
[144534] WiFi connected after time: 1
[144534] SSID: HueNet1, RSSI = -38
[144534] Channel: 2, IP address: 192.168.2.157
[144535] bg: WiFi OK. Try Blynk
[144536] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP32

[145549] NTP time: Mon Apr 19 07:23:17 2021
[145549] BlynkArduinoClient.connect: Connecting to blynk-cloud.com:9443
[146810] Certificate OK
[146826] Ready (ping: 20ms).
[146895] Connected to Blynk Server = blynk-cloud.com, Token = token1
[146895] bg: WiFi+Blynk OK

Blynk ESP32 using LittleFS connected
Board Name : ESP8266
Stop multiResetDetecting
Saving config file...
Saving config file OK
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
1 Like

Notes from ESP8266 SSL connections down using Blynk_WiFiManager


This so-called "insecured mode"

  1. permits you to actually connect to a TLS server (port 443,9443, etc., especially with expired CA Certs such as Blynk Cloud). It won’t let you connect to plain non-SSL server because full encryption is still required.
  2. You never have to worry about CA Certs’ update and to include every trusted CA root certificate of every TLS server
  3. Still requires encryption. It just does not validate the certificate or fingerprint. Insecure because we could be subject to a MITM (Man-In-The-Middle) attack.
  4. It’s still much better than plain non-SSL mode which just communicates using no encryption at all.

So this is the much better choice.

1 Like

Thank you again @khoih .

The updated Blynk_WiFiManager works well for me with ‘standard’ ESP8266, SONOFF, and ESP32s (I like Adafruit’s). I did not like running all these devices unencrypted. I look forward to Blynk’s SSL implementation as they progress their beta into an official release.

With great appreciation.

1 Like

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.4.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.3.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
1 Like

Updated May 19th 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-

Releases v1.5.0

  1. Fix bug.
  2. Optimize and sync with Blynk_Async_WM library v1.5.0

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 ESP8266WM_MRD_Config on ESP8266_NODEMCU_ESP12E using new ESP8266 core v3.0.0

Starting ESP8266WM_MRD_Config using LittleFS with SSL on ESP8266_NODEMCU_ESP12E
ESP8266 core v3.0.0
Blynk_WM SSL for ESP8266 v1.6.0
ESP_MultiResetDetector v1.1.1
[274] 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>
[296] Set CustomsHeadElement to : <style>html{filter: invert(10%);}</style>
[303] 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
[337] Hostname=8266-Master-Controller
[349] LoadCfgFile 
[349] OK
[349] ======= Start Stored Config Data =======
[349] Hdr=SSL_ESP8266,BrdName=ESP32
[350] SSID=HueNet1,PW=password
[351] SSID1=HueNet2,PW1=password
[354] Server=account.duckdns.org,Token=token
[360] Server1=account.duckdns.org,Token1=token1
[366] Port=9443
[368] ======= End Config Data =======
[371] CCSum=0x3473,RCSum=0x3473
[376] LoadCredFile 
[376] CrR:pdata=default-mqtt-server,len=34
[380] CrR:pdata=1883,len=6
[382] CrR:pdata=default-mqtt-username,len=34
[386] CrR:pdata=default-mqtt-password,len=34
[390] CrR:pdata=default-mqtt-SubTopic,len=34
[394] CrR:pdata=default-mqtt-PubTopic,len=34
[398] OK
[399] CrCCsum=0x29a6,CrRCsum=0x29a6
[402] Valid Stored Dynamic Data
[405] Hdr=SSL_ESP8266,BrdName=ESP32
[408] SSID=HueNet1,PW=password
[411] SSID1=HueNet2,PW1=password
[414] Server=account.duckdns.org,Token=token
[420] Server1=account.duckdns.org,Token1=token1
[426] Port=9443
[428] ======= End Config Data =======
[431] Check if isForcedCP
[436] LoadCPFile 
[436] OK
[436] bg: noConfigPortal = true
[439] Connecting MultiWifi...
[5576] WiFi connected after time: 1
[5577] SSID: HueNet1, RSSI = -43
[5577] Channel: 2, IP address: 192.168.2.135
[5577] bg: WiFi OK. Try Blynk
[5578] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP8266_NODEMCU_ESP12E

[6592] NTP time: Thu May 20 02:13:51 2021
[6624] BlynkArduinoClient.connect: Connecting to account.duckdns.org:9443
[7360] Certificate OK
[7387] Ready (ping: 20ms).
[7457] Connected to Blynk Server = account.duckdns.org, Token = token
[7458] bg: WiFi+Blynk OK

Blynk ESP8288 using LittleFS connected.
Board Name : ESP8266
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
BBBBBRBBBB BBRBBBBBBRBB BBBBRBBBBBB
2 Likes

Good day.

I am using BlynkSimpleEsp32_WM.h v1.6.1 and is not very strong in all C ++ syntax yet, can anyone tell me. How can I track the enable status of ConfigPortal after executing Blynk.begin() ? I tried to make the noConfigPortal variable global, but it is overridden in the BlynkSimpleEsp32_WM.h code as local … Even if we remove the bool :frowning:

Add BlynkSimpleEsp32_WM.h:

...
class BlynkWifi
  : public BlynkProtocol<BlynkArduinoClient>
{
    typedef BlynkProtocol<BlynkArduinoClient> Base;
  public:
     BlynkWifi(BlynkArduinoClient& transp)
      : Base(transp)
    {}

  public:
     bool noConfigPortal;
... 

Error:

...error: 'noConfigPortal' was not declared in this scope Serial.printf("\n\n flag CP = %d\n", noConfigPortal);

Working with the example ESP32WM_Config.ino

P.S. I need it to display the status on the LCD display.

Hi! I have been used your lib Blynk_wm. But i got a debug. After few minutes my Serial in Arduino display: lost connect blynk. Connecting to blynk sever:8080 … and then blynk not connected. Solve that for me! Thanks.