Why do we need the new Async Blynk_Async_ESP32_BT_WF 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
- Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer.
- Bump up to v1.0.6 to sync with BlynkESP32_BT_WF library v1.0.6.
By design, Blynk user can run ESP32 boards with either WiFi or BT/BLE by using different sketches, and have to upload / update firmware to change. This library enables user to include both Blynk BT / BLE and WiFi libraries in one sketch, run both WiFi and BT/BLE simultaneously, or select one to use at runtime after reboot.
This library also supports (auto)connection to MultiWiFi and MultiBlynk, dynamic custom as well as static parameters in Config Portal. Eliminate hardcoding your Wifi and Blynk credentials and configuration data saved in either SPIFFS or EEPROM.
Optional default Credentials to be autoloaded into Config Portal to use or change instead of manually input. Static STA IP and DHCP Hostname as well as Config Portal AP channel, IP, SSID, Password can be configured. DoubleDetectDetector feature permits entering Config Portal as requested.
You can eliminate hardcoding
your Wifi and Blynk credentials, thanks to the Smart Config Portal
, and have Credentials (WiFi SID/PW, Blynk WiFi/BT/BLE Tokens/ Hardware Port) saved in either SPIFFS or EEPROM.
Thanks to this Blynk_Async_ESP32_BT_WF library is based on and sync'ed with BlynkESP32_BT_WF library
, all the features currently supported by BlynkESP32_BT_WF library
will be available. Please have a look at DONE
or DONE in BlynkESP32_BT_WF library
for those too-many-to-list features.
Arduino IDE 1.8.12+
for ArduinoBlynk library 0.6.1+
ESP32 core 1.0.4+
for ESP32 boardsESP_DoubleResetDetector library 1.0.3+
to use DRD feature. To install, check .ESPAsyncWebServer v1.2.3+
AsyncTCP v1.1.1+
The best and easiest way is to use Arduino Library Manager
. Search for Blynk_Async_ESP32_BT_WF
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to Blynk_Async_ESP32_BT_WF page.
- Download the latest release
Blynk_Async_ESP32_BT_WF-master.zip
. - Extract the zip file to
Blynk_Async_ESP32_BT_WF-master
directory - Copy the whole
Blynk_Async_ESP32_BT_WF-master
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install Blynk_Async_ESP32_BT_WF library by using Library Manager. Search for Blynk_Async_ESP32_BT_WF in Platform.io Author's Libraries
- Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically.
How to migrate from BlynkESP32_BT_WF library
In your code, just replacing
BlynkSimpleEsp32_WF.h
withBlynkSimpleEsp32_Async_WF.h
BlynkSimpleEsp32_WFM.h
withBlynkSimpleEsp32_Async_WFM.h
BlynkSimpleEsp32_BT_WF.h
withBlynkSimpleEsp32_Async_BT_WF.h
BlynkSimpleEsp32_BLE_WF.h
withBlynkSimpleEsp32_Async_BLE_WF.h
In your code, replace
BlynkSimpleEsp32_BT.h
withBlynkSimpleEsp32_Async_BT_WF.h
BlynkSimpleEsp32_BLE.h
withBlynkSimpleEsp32_Async_BLE_WF.h
BlynkSimpleEsp32.h
withBlynkSimpleEsp32_Async_WFM.h
if using WiFiManager's Config Portal featuresBlynkSimpleEsp32.h
withBlynkSimpleEsp32_Async_WF.h
if not using WiFiManager's Config Portal features
- Then replace WiFi's
Blynk.begin(...)
with :
-
Blynk_WF.begin()
to use default DHCP hostnameESP8266-XXXXXX
orESP32-XXXXXX
-
or to have a personalized hostname
(RFC952-conformed,- 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char)
Blynk_WF.begin("Personalized-HostName")
Blynk.run();
withBlynk_WF.run()
for WiFi related function callsBlynk.run();
withBlynk_BT.run()
for BlueTooth related function calls orBlynk.run();
withBlynk_BLE.run()
for BLE related function calls
See this example and modify as necessary
1. To load Default Credentials
bool LOAD_DEFAULT_CONFIG_DATA = true;
bool LOAD_DEFAULT_CONFIG_DATA = false;
3. Example of Default Credentials
/// Start Default Config Data //////////////////
/*
// Defined in <BlynkSimpleESP32_Async_WFM.h>
#define SSID_MAX_LEN 32
#define PASS_MAX_LEN 64
typedef struct
{
char wifi_ssid[SSID_MAX_LEN];
char wifi_pw [PASS_MAX_LEN];
} WiFi_Credentials;
#define BLYNK_SERVER_MAX_LEN 32
#define BLYNK_TOKEN_MAX_LEN 36
typedef struct
{
char blynk_server[BLYNK_SERVER_MAX_LEN];
char blynk_token [BLYNK_TOKEN_MAX_LEN];
} Blynk_Credentials;
#define NUM_WIFI_CREDENTIALS 2
#define NUM_BLYNK_CREDENTIALS 2
typedef struct Configuration
{
char header [16];
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
int blynk_port;
char board_name [24];
int checkSum;
} Blynk_WM_Configuration;
*/
//bool LOAD_DEFAULT_CONFIG_DATA = true;
bool LOAD_DEFAULT_CONFIG_DATA = false;
Blynk_WM_Configuration defaultConfig =
{
//char header[16], dummy, not used
#if USE_SSL
"SSL",
#else
"NonSSL",
#endif
//WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]
//WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw
"SSID1", "password1",
"SSID2", "password2",
// Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
// Blynk_Creds.blynk_server and Blynk_Creds.blynk_token
"account.ddns.net", "token",
"account.duckdns.org", "token1",
//int blynk_port;
#if USE_SSL
9443,
#else
8080,
#endif
//char board_name [24];
"ESP32-BLE-WF",
//int checkSum, dummy, not used
0
};
/////////// End Default Config Data /////////////
- To add custom parameters, just modify the example below
#define USE_DYNAMIC_PARAMETERS true
/////////////// Start dynamic Credentials ///////////////
//Defined in <BlynkSimpleESP32_Async_WFM.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_MQTT_SERVER_LEN 34
char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server";
#define MAX_MQTT_PORT_LEN 6
char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883";
#define MAX_MQTT_USERNAME_LEN 34
char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username";
#define MAX_MQTT_PW_LEN 34
char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password";
#define MAX_MQTT_SUBS_TOPIC_LEN 34
char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic";
#define MAX_MQTT_PUB_TOPIC_LEN 34
char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic";
MenuItem myMenuItems [] =
{
{ "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },
{ "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN },
{ "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN },
{ "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN },
{ "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN },
{ "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN },
};
uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;
#else
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
#endif
/////// // End dynamic Credentials ///////////
Use the following code snippet in sketch
#define USE_DYNAMIC_PARAMETERS false
or
/////////////// Start dynamic Credentials ///////////////
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
/////// // End dynamic Credentials ///////////
Why using this Blynk_Async_ESP32_BT_WF with MultiWiFi-MultiBlynk features
You can see that the system automatically detects and connects to the best or avaiable WiFi APs and/or Blynk Servers, whenever interruption happens. This feature is very useful for systems requiring high degree of reliability.
Moreover, these Blynk_BLE.begin()
, Blynk_BT.begin()
and Blynk_WF.begin()
are not blocking calls, so you can use it for critical functions requiring in loop().
Anyway, this is better for projects using Blynk just for GUI (graphical user interface).
In operation, if WiFi or Blynk connection is lost, Blynk_BLE.begin()
, Blynk_BT.begin()
and Blynk_WF.begin()
will try reconnecting automatically.
Therefore, Blynk_BLE.begin()
, Blynk_BT.begin()
and Blynk_WF.begin()
must be called in the loop()
function.
For example, don't use:
void loop()
{
if (Blynk.connected())
Blynk_BLE.run();
...
}
just
void loop()
{
Blynk_BLE.run();
...
}
That's it.
Also see examples:
- Async_ESP32_BLE_WF
- Async_ESP32_BT_WF
- Async_Geiger_Counter_BLE
- Async_Geiger_Counter_BT
- Async_Geiger_Counter_OLED
- Async_Geiger_Counter_OLED_BT_WF
- Async_Geiger_Counter_OLED_BT_BLE_WF
- Async_PET_Check
and real-life project Hack GMC Geigercounter With Blynk of Crosswalkersam
If the necessary credentials are not valid or it cannot connect to the Blynk server in 30 seconds, it will switch to Configuration Mode
. You will see your built-in LED turned ON. In Configuration Mode
, it starts an access point called ESP_xxxxxx
or configurable TestPortal-ESP32
by using:
Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass");
Connect to it using password MyESP_xxxxxx
or configurable TestPortalPass
.
After you connected, please, go to http://192.168.4.1 or the configured AP IP. The Config Portal screen will appear:
Enter your WiFi and Blynk Credentials (Server, Port, WiFi/BT/BLE tokens)
Then click Save
. After you restarted, you will see your built-in LED turned OFF. That means, it connected to your Blynk server successfully.
Example Async_ESP32_BLE_WF
1. File Async_ESP32_BLE_WF.ino
#include "defines.h"
#include "Credentials.h"
#include "dynamicParams.h"
bool USE_BLE = true;
long timePreviousMeassure = 0;
#define WIFI_BLE_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32
BlynkTimer timer;
#include <Ticker.h>
Ticker led_ticker;
void set_led(byte status)
{
digitalWrite(LED_BUILTIN, status);
}
void noticeAlive(void)
{
if (USE_BLE)
Blynk_BLE.virtualWrite(V0, F("OK"));
else
Blynk_WF.virtualWrite(V0, F("OK"));
}
void heartBeatPrint(void)
{
static int num = 1;
if (Blynk.connected())
{
set_led(HIGH);
led_ticker.once_ms(111, set_led, (byte) LOW);
Serial.print(F("B"));
}
else
{
Serial.print(F("F"));
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void checkStatus()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 60000L
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
if (!USE_BLE)
{
// report Blynk connection
heartBeatPrint();
}
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
char BLE_Device_Name[] = "GeigerCounter-BLE";
void setup()
{
Serial.begin(115200);
while (!Serial);
#if ( USE_SPIFFS)
Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS"));
#else
Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM"));
#endif
#if USE_SSL
Serial.println(" with SSL on " + String(ARDUINO_BOARD));
#else
Serial.println(" without SSL on " + String(ARDUINO_BOARD));
#endif
pinMode(WIFI_BLE_SELECTION_PIN, INPUT_PULLUP);
#if BLYNK_USE_BLE_ONLY
Blynk_BLE.setDeviceName(BLE_Device_Name);
#if ESP32_BLE_WF_DEBUG
Serial.println(F("Blynk_BLE begin"));
#endif
Blynk_BLE.begin(auth);
#else
if (digitalRead(WIFI_BLE_SELECTION_PIN) == HIGH)
{
USE_BLE = false;
Serial.println(F("GPIO14 HIGH, Use WiFi"));
#if USE_BLYNK_WM
#if ESP32_BLE_WF_DEBUG
Serial.println(F("USE_BLYNK_WM: Blynk_WF begin"));
#endif
// Set config portal SSID and Password
Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass");
// Set config portal IP address
Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1));
// Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict
Blynk_WF.setConfigPortalChannel(0);
// From v1.0.6, select either one of these to set static IP + DNS
Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0));
//Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0),
// IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8));
//Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0),
// IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8));
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
//Blynk.begin();
// Use this to personalize DHCP hostname (RFC952 conformed)
// 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char
//Blynk.begin("ESP32-BLE-WM");
Blynk_WF.begin(BLE_Device_Name);
#else
//Blynk_WF.begin(auth, ssid, pass);
#if ESP32_BLE_WF_DEBUG
Serial.println(F("Not USE_BLYNK_WM: Blynk_WF begin"));
#endif
Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
#endif
}
else
{
USE_BLE = true;
Serial.println(F("GPIO14 LOW, Use BLE"));
Blynk_BLE.setDeviceName(BLE_Device_Name);
#if USE_BLYNK_WM
if (Blynk_WF.getBlynkBLEToken() == NO_CONFIG) //String("blank"))
{
Serial.println(F("No valid stored BLE auth. Have to run WiFi then enter config portal"));
USE_BLE = false;
#if ESP32_BLE_WF_DEBUG
Serial.println(F("USE_BLYNK_WM: No BLE Token. Blynk_WF begin"));
#endif
Blynk_WF.begin(BLE_Device_Name);
}
String BLE_auth = Blynk_WF.getBlynkBLEToken();
#else
String BLE_auth = auth;
#endif
if (USE_BLE)
{
Serial.print(F("Connecting Blynk via BLE, using auth = "));
Serial.println(BLE_auth);
#if ESP32_BLE_WF_DEBUG
Serial.println(F("USE_BLE: Blynk_BLE begin"));
#endif
Blynk_BLE.begin(BLE_auth.c_str());
}
}
#endif
// Important, need to keep constant communication to Blynk Server at least once per ~25s
// Or Blynk will lost and have to (auto)reconnect
timer.setInterval(10000L, noticeAlive);
}
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
void displayCredentials(void)
{
Serial.println(F("\nYour stored Credentials :"));
for (int i = 0; i < NUM_MENU_ITEMS; i++)
{
Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata);
}
}
#endif
void loop()
{
#if BLYNK_USE_BLE_ONLY
Blynk_BLE.run();
#else
if (USE_BLE)
Blynk_BLE.run();
else
Blynk_WF.run();
#endif
timer.run();
checkStatus();
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
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
}
2. File defines.h
#ifndef defines_h
#define defines_h
#ifndef ESP32
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif
#define BLYNK_PRINT Serial
#define ESP32_BLE_WF_DEBUG true
#define DOUBLERESETDETECTOR_DEBUG true
#define BLYNK_WM_DEBUG 3
// Not use #define USE_SPIFFS => using EEPROM for configuration data in WiFiManager
// #define USE_SPIFFS false => using EEPROM for configuration data in WiFiManager
// #define USE_SPIFFS true => using SPIFFS for configuration data in WiFiManager
// Those above #define's must be placed before #include <BlynkSimpleEsp32_Async_WFM.h>
#define USE_SPIFFS true
//#define USE_SPIFFS false
#if (!USE_SPIFFS)
// EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes)
#define EEPROM_SIZE (2 * 1024)
// EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE
#define EEPROM_START 0
#endif
// Force some params in Blynk, only valid for library version 1.0.1 and later
#define TIMEOUT_RECONNECT_WIFI 10000L
#define RESET_IF_CONFIG_TIMEOUT true
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
// Those above #define's must be placed before #include <BlynkSimpleEsp32_Async_WFM.h>
//#define BLYNK_USE_BLE_ONLY true
#define BLYNK_USE_BLE_ONLY false
#include <BlynkSimpleEsp32_Async_BLE_WF.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#define USE_BLYNK_WM true
//#define USE_BLYNK_WM false
#if !BLYNK_USE_BLE_ONLY
#if USE_BLYNK_WM
#warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP)
#include <BlynkSimpleEsp32_Async_WFM.h>
#else
#include <BlynkSimpleEsp32_Async_WF.h>
String cloudBlynkServer = "account.duckdns.org";
//String cloudBlynkServer = "192.168.2.110";
#define BLYNK_SERVER_HARDWARE_PORT 8080
char ssid[] = "SSID";
char pass[] = "PASS";
#endif
#endif
#if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM)
// Blynk token shared between BLE and WiFi
char auth[] = "****";
#endif
#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif
#define HOST_NAME "ASYNC-ESP32-BLE-WF"
#endif //defines_h
3. File Credentials.h
#ifndef Credentials_h
#define Credentials_h
#if USE_BLYNK_WM
/// Start Default Config Data //////////////////
/*
// Defined in <BlynkSimpleEsp32_Async_WFM.h>
#define SSID_MAX_LEN 32
#define PASS_MAX_LEN 64
typedef struct
{
char wifi_ssid[SSID_MAX_LEN];
char wifi_pw [PASS_MAX_LEN];
} WiFi_Credentials;
#define BLYNK_SERVER_MAX_LEN 32
#define BLYNK_TOKEN_MAX_LEN 36
typedef struct
{
char blynk_server[BLYNK_SERVER_MAX_LEN];
char blynk_token [BLYNK_TOKEN_MAX_LEN];
} Blynk_Credentials;
#define NUM_WIFI_CREDENTIALS 2
#define NUM_BLYNK_CREDENTIALS 2
typedef struct Configuration
{
char header [16];
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
int blynk_port;
char board_name [24];
int checkSum;
} Blynk_WM_Configuration;
*/
//bool LOAD_DEFAULT_CONFIG_DATA = true;
bool LOAD_DEFAULT_CONFIG_DATA = false;
Blynk_WM_Configuration defaultConfig =
{
//char header[16], dummy, not used
#if USE_SSL
"SSL",
#else
"NonSSL",
#endif
//WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]
//WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw
"SSID1", "password1",
"SSID2", "password2",
// Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
// Blynk_Creds.blynk_server and Blynk_Creds.blynk_token
"account.ddns.net", "token",
"account.duckdns.org", "token1",
//int blynk_port;
#if USE_SSL
9443,
#else
8080,
#endif
//char board_name [24];
"ESP32-BLE-WF",
//int checkSum, dummy, not used
0
};
/////////// End Default Config Data /////////////
#endif // #if USE_BLYNK_WM
#endif //Credentials_h
4. File dynamicParams.h
#ifndef dynamicParams_h
#define dynamicParams_h
#if USE_BLYNK_WM
#define USE_DYNAMIC_PARAMETERS true
/////////////// Start dynamic Credentials ///////////////
//Defined in <BlynkSimpleEsp32_Async_WFM.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_MQTT_SERVER_LEN 34
char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server";
#define MAX_MQTT_PORT_LEN 6
char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883";
#define MAX_MQTT_USERNAME_LEN 34
char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username";
#define MAX_MQTT_PW_LEN 34
char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password";
#define MAX_MQTT_SUBS_TOPIC_LEN 34
char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic";
#define MAX_MQTT_PUB_TOPIC_LEN 34
char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic";
MenuItem myMenuItems [] =
{
{ "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },
{ "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN },
{ "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN },
{ "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN },
{ "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN },
{ "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN },
};
uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;
#else
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
#endif
/////// // End dynamic Credentials ///////////
#endif // USE_BLYNK_WM
#endif //dynamicParams_h
- 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
"sv" for Blynk Server
"tk" for Blynk Token
"sv1" for Blynk Server1
"tk1" for Blynk Token1
"pt" for Blynk Port
"bttk" for BT Blynk Token
"bltk" for BLE Blynk Token
"nm" for Board Name
The following is the sample terminal output when running example Async_ESP32_BLE_WF
Starting Async_ESP32_BLE_WF using SPIFFS without SSL on ESP32_DEV
GPIO14 HIGH, Use WiFi
USE_BLYNK_WM: Blynk_WF begin
SPIFFS Flag read = 0xd0d04321
No doubleResetDetected
Saving config file...
Saving config file OK
[219] Hostname=GeigerCounter-BLE
[329] b:Nodat.Stay
[1174] stConf:SSID=TestPortal-ESP32,PW=TestPortalPass
[1174] IP=192.168.232.1,ch=1
F
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 doubleResetDetecting
Saving config file...
Saving config file OK
FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF
FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF FFFFFFFFFF
[9678328] h:repl
[9678335] h1:myMenuItems[0]=default-mqtt-server
[9678335] h1:myMenuItems[1]=1883
[9678336] h1:myMenuItems[2]=default-mqtt-username
[9678337] h1:myMenuItems[3]=default-mqtt-password
[9678341] h1:myMenuItems[4]=default-mqtt-SubTopic
[9678345] h1:myMenuItems[5]=default-mqtt-PubTopic
FF[9799112] id: = HueNet1
[9799134] pw: = 12345678
[9799184] id1: = HueNet2
[9799205] pw1: = 12345678
[9799226] sv: = your_account.duckdns.org
[9799248] tk: = ********
[9799275] sv1: = your_account.ddns.net
[9799302] tk1: = ********
[9799318] bttk: = ********
[9799339] bltk: = ********
[9799366] pt = 8080
[9799387] nm: = ESP32
[9799491] h:UpdSPIFFS /wfm_config.dat
[9799600] SaveCfgFile
[9799600] WCSum=0x47ec
[9799605] OK
[9799715] SaveBkUpCfgFile
[9799719] OK
[9799719] h:Rst
Starting Async_ESP32_BLE_WF using SPIFFS without SSL on ESP32_DEV
GPIO14 HIGH, Use WiFi
USE_BLYNK_WM: Blynk_WF begin
SPIFFS Flag read = 0xd0d01234
doubleResetDetected
Saving config file...
Saving config file OK
[119] Double Reset Detected
[215] Hostname=GeigerCounter-BLE
[244] LoadCfgFile
[245] OK
[245] ======= Start Stored Config Data =======
[245] Hdr=ESP32_WFM,BrdName=
[245] SSID=SSID1,PW=password1
[245] SSID1=SSID2,PW1=password2
[248] Server=account.ddns.net,Token=token
[252] Server1=account.duckdns.org,Token1=token1
[256] BT-Token=ESP32-BLE-WF,BLE-Token=
[260] Port=8080
[261] ======= End Config Data =======
[264] CCSum=0x2297,RCSum=0x2297
[268] LoadCredFile
[269] CrR:pdata=default-mqtt-server,len=34
[273] CrR:pdata=1883,len=6
[275] CrR:pdata=default-mqtt-username,len=34
[279] CrR:pdata=default-mqtt-password,len=34
[283] CrR:pdata=default-mqtt-SubTopic,len=34
[287] CrR:pdata=default-mqtt-PubTopic,len=34
[291] OK
[292] CrCCsum=0x29a6,CrRCsum=0x29a6
[295] Valid Stored Dynamic Data
[298] Hdr=ESP32_WFM,BrdName=
[301] SSID=SSID1,PW=password1
[304] SSID1=SSID2,PW1=password2
[306] Server=account.ddns.net,Token=token
[310] Server1=account.duckdns.org,Token1=token1
[314] BT-Token=ESP32-BLE-WF,BLE-Token=
[318] Port=8080
[319] ======= End Config Data =======
[323] b:Nodat.Stay
[1169] stConf:SSID=TestPortal-ESP32,PW=TestPortalPass
[1169] IP=192.168.232.1,ch=8
F
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
FFFFF
[194511] id: = HueNet1
[194526] pw: = 12345678
[194543] id1: = HueNet2
[194558] pw1: = 12345678
[194572] sv: = your_account.duckdns.org
[194597] tk: = ********
[194619] sv1: = your_account.ddns.net
[194635] tk1: = ********
[194655] bttk: = ********
[194669] bltk: = ********
[194690] pt = 8080
[194729] nm: = ESP32
[194866] h:UpdSPIFFS /wfm_config.dat
[194897] SaveCfgFile
[194897] WCSum=0x47ec
[194901] OK
[194904] SaveBkUpCfgFile
[194908] OK
[194908] h:Rst
Starting Async_ESP32_BLE_WF using SPIFFS without SSL on ESP32_DEV
GPIO14 HIGH, Use WiFi
USE_BLYNK_WM: Blynk_WF begin
SPIFFS Flag read = 0xd0d04321
No doubleResetDetected
Saving config file...
Saving config file OK
[214] Hostname=GeigerCounter-BLE
[243] LoadCfgFile
[243] OK
[243] ======= Start Stored Config Data =======
[243] Hdr=ESP32_WFM,BrdName=ESP32
[243] SSID=HueNet1,PW=12345678
[244] SSID1=HueNet2,PW1=12345678
[247] Server=your_account.duckdns.org,Token=********
[253] Server1=your_account.ddns.net,Token1=********
[259] BT-Token=********,BLE-Token=********
[267] Port=8080
[269] ======= End Config Data =======
[272] CCSum=0x4ace,RCSum=0x4ace
[302] LoadCredFile
[303] CrR:pdata=default-mqtt-server,len=34
[303] CrR:pdata=1883,len=6
[303] CrR:pdata=default-mqtt-username,len=34
[303] CrR:pdata=default-mqtt-password,len=34
[307] CrR:pdata=default-mqtt-SubTopic,len=34
[311] CrR:pdata=default-mqtt-PubTopic,len=34
[315] OK
[316] CrCCsum=0x29a6,CrRCsum=0x29a6
[319] Valid Stored Dynamic Data
[322] Hdr=ESP32_WFM,BrdName=ESP32
[325] SSID=HueNet1,PW=12345678
[328] SSID1=HueNet2,PW1=12345678
[331] Server=your_account.duckdns.org,Token=********
[337] Server1=your_account.ddns.net,Token1=********
[343] BT-Token=********,BLE-Token=********
[351] Port=8080
[353] ======= End Config Data =======
[356] bg: noConfigPortal = true
[359] Connecting MultiWifi...
[5190] WiFi connected after time: 1
[5190] SSID:HueNet1,RSSI=-42
[5190] Channel:2,IP address:192.168.2.98
[5190] bg: WiFi OK. Try Blynk
[5191]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.6.1 on ESP32
[5204] BlynkArduinoClient.connect: Connecting to your_account.duckdns.org:8080
[5354] Ready (ping: 8ms).
[5424] Connected to Blynk Server = your_account.duckdns.org, Token = ********
[5424] bg: WiFi+Blynk 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
Stop doubleResetDetecting
Saving config file...
Saving config file OK
BBBB
- Same features for other boards with WiFi / BT
- Optimize library so that smaller code size. Currently 2 instances of Blynk coexist and don't share code.
- 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 (SSID, password, Server and Blynk tokens), entering config portal
- Correct the operation of BUILTIN_LED
- Reduce EEPROM size to 2K from 4K to avoid ESP_ERR_NVS_NOT_ENOUGH_SPACE error.
- Add RFC952 hostname
- Add configurable Config Portal IP, SSID and Password
- Add configurable Static IP, GW, Subnet Mask and 2 DNS Servers' IP Addresses.
- Use dynamically alocated Config Portal WebServer
- Fix BT/BLE login timeout
- Add checksum for config data integrity
- Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary
- Add MultiWiFi feature to enable reconnect to the best / available WiFi AP.
- Add MultiBlynk feature to enable reconnect to the best / available Blynk Server.
- WiFi Password max length is 63, as in WPA2 standards
- Permit to input special chars such as % and # into data fields.
- Add Dynamic Custom Parameters with checksum
- Add function to configure AP Channel (fixed or random) to avoid channel conflict.
- Default Credentials and dynamic parameters
- DoubleDetectDetector to force Config Portal when 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.
- Using ESPAsyncWebServer instead of (ESP8266)WebServer.
- Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer.
- Bump up to v1.0.6 to sync with BlynkESP32_BT_WF library v1.0.6.
- Thanks to Crosswalkersam for the original code and request to inspire the work. See Select connection Type via Switch
- Thanks to Miguel Alexandre Wisintainer for working with, developing, debugging, testing and contributing example Async_PET_Check. See also nina-w102-ble-detector-presenca-de-pet
Crosswalkersam |
tcpipchip |
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 2020- Khoi Hoang