diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0001ba8..545d00c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ Please ensure to specify the following: Arduino IDE version: 1.8.13 ESP32 Core Version 1.0.4 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.4.0-64-generic #72-Ubuntu SMP Fri Jan 15 10:27:54 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Context: The board couldn't autoreconnect to Local Blynk Server after router power recycling. diff --git a/README.md b/README.md index 56ab67e..cf04d4c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ * [Why Async is better](#why-async-is-better) * [Currently supported Boards](#currently-supported-boards) * [Changelog](#changelog) + * [Releases v1.1.1](#releases-v111) * [Major Releases v1.1.0](#major-releases-v110) * [Releases v1.0.6](#releases-v106) * [Prerequisites](#prerequisites) @@ -56,7 +57,9 @@ * [1. Async_ESP32_BLE_WF on ESP32_DEV](#1-async_esp32_ble_wf-on-esp32_dev) * [1.1. No Config Data => Config Portal. Input valid credentials => reboot](#11-no-config-data--config-portal-input-valid-credentials--reboot) * [1.2. DRD => Config Portal. Input valid credentials => reboot](#12-drd--config-portal-input-valid-credentials--reboot) - * [1.3. After inputting valid credentials and reboot](#13-after-inputting-valid-credentials-and-reboot) + * [1.3. After inputting valid credentials and reboot](#13-after-inputting-valid-credentials-and-reboot) + * [1.4. Enter non-persistent ConfigPortal](#14-enter-non-persistent-configportal) + * [1.5. Enter persistent ConfigPortal](#15-enter-persistent-configportal) * [Debug](#debug) * [Troubleshooting](#troubleshooting) * [Releases](#releases) @@ -111,6 +114,12 @@ This [**BlynkESP32_BT_WF** library](https://github.com/khoih-prog/BlynkESP32_BT_ ## Changelog +### 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](https://github.com/khoih-prog/Blynk_WM/issues/25) +2. Fix rare Config Portal bug not updating Config and dynamic Params data successfully in very noisy or weak WiFi situation +3. To permit autoreset after configurable timeout if DRD/MRD or non-persistent forced-CP. Check [**Good new feature: Blynk.resetAndEnterConfigPortal() Thanks & question #27**](https://github.com/khoih-prog/Blynk_WM/issues/27) + ### Major Releases v1.1.0 1. Add support to LittleFS for ESP32 using [LITTLEFS](https://github.com/lorol/LITTLEFS) Library @@ -557,6 +566,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void set_led(byte status) { digitalWrite(LED_BUILTIN, status); @@ -622,6 +661,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_ESP32_BLE_WF using LITTLEFS")); #elif (USE_SPIFFS) @@ -631,11 +672,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -734,13 +776,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -764,7 +808,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { @@ -835,6 +879,8 @@ void loop() #if !BLYNK_USE_BLE_ONLY #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else @@ -875,7 +921,7 @@ void loop() /// Start Default Config Data ////////////////// /* - // Defined in + // Defined in #define SSID_MAX_LEN 32 #define PASS_MAX_LEN 64 @@ -916,7 +962,7 @@ void loop() Blynk_WM_Configuration defaultConfig = { //char header[16], dummy, not used - #if USE_SSL + #if USE_SSL "SSL", #else "NonSSL", @@ -958,11 +1004,15 @@ void loop() #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// - //Defined in + //Defined in /************************************** #define MAX_ID_LEN 5 #define MAX_DISPLAY_NAME_LEN 16 @@ -1038,7 +1088,7 @@ The following is the sample terminal output when running example [Async_ESP32_BL ``` Starting Async_ESP32_BLE_WF using SPIFFS without SSL on ESP32_DEV -Blynk_Async_ESP32_BT_WF v1.1.0 +Blynk_Async_ESP32_BT_WF v1.1.1 ESP_DoubleResetDetector v1.1.1 GPIO14 HIGH, Use WiFi USE_BLYNK_WM: Blynk_WF begin @@ -1096,7 +1146,7 @@ FF[9799112] id: = HueNet1 ``` Starting Async_ESP32_BLE_WF using SPIFFS without SSL on ESP32_DEV -Blynk_Async_ESP32_BT_WF v1.1.0 +Blynk_Async_ESP32_BT_WF v1.1.1 ESP_DoubleResetDetector v1.1.1 GPIO14 HIGH, Use WiFi USE_BLYNK_WM: Blynk_WF begin @@ -1174,7 +1224,7 @@ FFFFF ``` Starting Async_ESP32_BLE_WF using SPIFFS without SSL on ESP32_DEV -Blynk_Async_ESP32_BT_WF v1.1.0 +Blynk_Async_ESP32_BT_WF v1.1.1 ESP_DoubleResetDetector v1.1.1 GPIO14 HIGH, Use WiFi USE_BLYNK_WM: Blynk_WF begin @@ -1242,8 +1292,167 @@ Stop doubleResetDetecting Saving config file... Saving config file OK BBBB +``` + +--- + +#### 1.4 Enter non-persistent ConfigPortal + +**Non-Persistent CP will be removed after first reset or time-out, even you didn't enter the CP**. You can optionally enter CP, input and `Save` config data. + +``` +CP Button Hit. Rebooting +[13025] setForcedCP non-Persistent +[13039] SaveCPFile +[13044] OK +[13058] SaveBkUpCPFile +[13063] OK +ets Jun 8 2016 00:22:57 + + +Starting Async_ESP32_BLE_WF using LITTLEFS without SSL on ESP32_DEV +Blynk_Async_ESP32_BT_WF v1.1.0 +ESP_DoubleResetDetector v1.1.1 +GPIO14 HIGH, Use WiFi +USE_BLYNK_WM: Blynk_WF begin +LittleFS Flag read = 0xD0D04321 +No doubleResetDetected +Saving config file... +Saving config file OK +[481] Hostname=GeigerCounter-BLE +[501] LoadCfgFile +[504] OK +[505] ======= Start Stored Config Data ======= +[505] Hdr=ESP32_WFM,BrdName=ESP32_BT_BLE +[505] SSID=HueNet1,PW=12345678 +[506] SSID1=HueNet2,PW1=12345678 +[509] Server=account.duckdns.org,Token=token +[515] Server1=account.duckdns.org,Token1=token1 +[521] BT-Token=bt_token,BLE-Token=ble_token +[529] Port=8080 +[531] ======= End Config Data ======= +[534] CCSum=0x4b86,RCSum=0x4b86 +[545] LoadCredFile +[548] CrR:pdata=new-mqtt-server,len=34 +[548] CrR:pdata=1883,len=6 +[548] CrR:pdata=default-mqtt-username,len=34 +[549] CrR:pdata=default-mqtt-password,len=34 +[553] CrR:pdata=default-mqtt-SubTopic,len=34 +[557] CrR:pdata=default-mqtt-PubTopic,len=34 +[561] OK +[562] CrCCsum=0x280b,CrRCsum=0x280b +[565] Valid Stored Dynamic Data +[568] Hdr=ESP32_WFM,BrdName=ESP32_BT_BLE +[571] SSID=HueNet1,PW=12345678 +[574] SSID1=HueNet2,PW1=12345678 +[577] Server=account.duckdns.org,Token=token +[583] Server1=account.duckdns.org,Token1=token1 +[589] BT-Token=bt_token,BLE-Token=ble_token +[597] Port=8080 +[599] ======= End Config Data ======= +[602] Check if isForcedCP +[612] LoadCPFile +[615] OK +[615] bg: isForcedConfigPortal = true +[615] bg:Stay forever in CP:Forced-non-Persistent +[615] clearForcedCP +[624] SaveCPFile +[628] OK +[636] SaveBkUpCPFile +[640] OK +[1485] stConf:SSID=TestPortal-ESP32,PW=TestPortalPass +[1485] IP=192.168.232.1,ch=7 +F +Your stored Credentials : +MQTT Server = new-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 +F +``` + +--- + +#### 1.5 Enter persistent ConfigPortal + +**Persistent CP will remain even after resets or time-out**. The only way to get rid of Config Portal is to enter CP, input (even fake data or none) and `Save` config data. So be careful to use this feature. ``` +Persistent CP Button Hit. Rebooting +[218377] setForcedCP Persistent +[218390] SaveCPFile +[218394] OK +[218408] SaveBkUpCPFile +[218413] OK +ets Jun 8 2016 00:22:57 + + +Starting Async_ESP32_BLE_WF using LITTLEFS without SSL on ESP32_DEV +Blynk_Async_ESP32_BT_WF v1.1.0 +ESP_DoubleResetDetector v1.1.1 +GPIO14 HIGH, Use WiFi +USE_BLYNK_WM: Blynk_WF begin +LittleFS Flag read = 0xD0D04321 +No doubleResetDetected +Saving config file... +Saving config file OK +[363] Hostname=GeigerCounter-BLE +[409] LoadCfgFile +[416] OK +[416] ======= Start Stored Config Data ======= +[416] Hdr=ESP32_WFM,BrdName=ESP32_BT_BLE +[416] SSID=HueNet1,PW=12345678 +[416] SSID1=HueNet2,PW1=12345678 +[419] Server=account.duckdns.org,Token=token +[425] Server1=account.duckdns.org,Token1=token1 +[432] BT-Token=bt_token,BLE-Token=ble_token +[440] Port=8080 +[441] ======= End Config Data ======= +[444] CCSum=0x4b86,RCSum=0x4b86 +[467] LoadCredFile +[473] CrR:pdata=new-mqtt-server,len=34 +[473] CrR:pdata=1883,len=6 +[473] CrR:pdata=default-mqtt-username,len=34 +[473] CrR:pdata=default-mqtt-password,len=34 +[476] CrR:pdata=default-mqtt-SubTopic,len=34 +[480] CrR:pdata=default-mqtt-PubTopic,len=34 +[484] OK +[485] CrCCsum=0x280b,CrRCsum=0x280b +[488] Valid Stored Dynamic Data +[491] Hdr=ESP32_WFM,BrdName=ESP32_BT_BLE +[494] SSID=HueNet1,PW=12345678 +[497] SSID1=HueNet2,PW1=12345678 +[500] Server=account.duckdns.org,Token=token +[506] Server1=account.duckdns.org,Token1=token1 +[513] BT-Token=bt_token,BLE-Token=ble_token +[521] Port=8080 +[522] ======= End Config Data ======= +[526] Check if isForcedCP +[541] LoadCPFile +[546] OK +[546] bg: isForcedConfigPortal = true +[546] bg:Stay forever in CP:Forced-Persistent +[1391] stConf:SSID=TestPortal-ESP32,PW=TestPortalPass +[1391] IP=192.168.232.1,ch=1 +F +Your stored Credentials : +MQTT Server = new-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 +FFFF +``` + --- --- @@ -1275,6 +1484,12 @@ Sometimes, the library will only work if you update the board core to the latest ## Releases +### 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](https://github.com/khoih-prog/Blynk_WM/issues/25) +2. Fix rare Config Portal bug not updating Config and dynamic Params data successfully in very noisy or weak WiFi situation +3. To permit autoreset after configurable timeout if DRD/MRD or non-persistent forced-CP. Check [**Good new feature: Blynk.resetAndEnterConfigPortal() Thanks & question #27**](https://github.com/khoih-prog/Blynk_WM/issues/27) + ### Major Releases v1.1.0 1. Add support to LittleFS for ESP32 using [LITTLEFS](https://github.com/lorol/LITTLEFS) Library diff --git a/examples/Async_ESP32_BLE_WF/Async_ESP32_BLE_WF.ino b/examples/Async_ESP32_BLE_WF/Async_ESP32_BLE_WF.ino index 8045e8a..cfc655d 100644 --- a/examples/Async_ESP32_BLE_WF/Async_ESP32_BLE_WF.ino +++ b/examples/Async_ESP32_BLE_WF/Async_ESP32_BLE_WF.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_ESP32_BLE_WF.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license + Async_ESP32_BLE_WF.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -43,6 +45,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void set_led(byte status) { digitalWrite(LED_BUILTIN, status); @@ -108,6 +140,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_ESP32_BLE_WF using LITTLEFS")); #elif (USE_SPIFFS) @@ -117,11 +151,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -220,13 +255,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -250,7 +287,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_ESP32_BLE_WF/Credentials.h b/examples/Async_ESP32_BLE_WF/Credentials.h index 348d225..bee1099 100644 --- a/examples/Async_ESP32_BLE_WF/Credentials.h +++ b/examples/Async_ESP32_BLE_WF/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 boards - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 boards + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_ESP32_BLE_WF/defines.h b/examples/Async_ESP32_BLE_WF/defines.h index 406a79b..b64983a 100644 --- a/examples/Async_ESP32_BLE_WF/defines.h +++ b/examples/Async_ESP32_BLE_WF/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 boards - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 boards + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -68,6 +60,8 @@ #if !BLYNK_USE_BLE_ONLY #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_ESP32_BLE_WF/dynamicParams.h b/examples/Async_ESP32_BLE_WF/dynamicParams.h index 2264061..d3aea7a 100644 --- a/examples/Async_ESP32_BLE_WF/dynamicParams.h +++ b/examples/Async_ESP32_BLE_WF/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 boards - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 boards + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_ESP32_BT_WF/Async_ESP32_BT_WF.ino b/examples/Async_ESP32_BT_WF/Async_ESP32_BT_WF.ino index f44ad9d..55c7947 100644 --- a/examples/Async_ESP32_BT_WF/Async_ESP32_BT_WF.ino +++ b/examples/Async_ESP32_BT_WF/Async_ESP32_BT_WF.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_ESP32_BT_WF.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Async_ESP32_BT_WF.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -43,6 +45,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void set_led(byte status) { digitalWrite(LED_BUILTIN, status); @@ -108,6 +140,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_ESP32_BT_WF using LITTLEFS")); #elif (USE_SPIFFS) @@ -117,11 +151,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -219,13 +254,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -249,7 +286,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_ESP32_BT_WF/Credentials.h b/examples/Async_ESP32_BT_WF/Credentials.h index 98214f4..7c629fa 100644 --- a/examples/Async_ESP32_BT_WF/Credentials.h +++ b/examples/Async_ESP32_BT_WF/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_ESP32_BT_WF/defines.h b/examples/Async_ESP32_BT_WF/defines.h index 1cb0a67..981b24c 100644 --- a/examples/Async_ESP32_BT_WF/defines.h +++ b/examples/Async_ESP32_BT_WF/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -66,6 +58,8 @@ #if !BLYNK_USE_BT_ONLY #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_ESP32_BT_WF/dynamicParams.h b/examples/Async_ESP32_BT_WF/dynamicParams.h index 0f63625..722769d 100644 --- a/examples/Async_ESP32_BT_WF/dynamicParams.h +++ b/examples/Async_ESP32_BT_WF/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_Geiger_Counter_BLE/Async_Geiger_Counter_BLE.ino b/examples/Async_Geiger_Counter_BLE/Async_Geiger_Counter_BLE.ino index a8c5d04..3ac8763 100644 --- a/examples/Async_Geiger_Counter_BLE/Async_Geiger_Counter_BLE.ino +++ b/examples/Async_Geiger_Counter_BLE/Async_Geiger_Counter_BLE.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_Geiger_Counter_BLE.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Async_Geiger_Counter_BLE.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -66,6 +68,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void IRAM_ATTR countPulse() { if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) @@ -199,6 +231,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_Geiger_Counter_BLE using LITTLEFS")); #elif (USE_SPIFFS) @@ -208,11 +242,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -288,13 +323,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -318,7 +355,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_Geiger_Counter_BLE/Credentials.h b/examples/Async_Geiger_Counter_BLE/Credentials.h index 98214f4..7c629fa 100644 --- a/examples/Async_Geiger_Counter_BLE/Credentials.h +++ b/examples/Async_Geiger_Counter_BLE/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_Geiger_Counter_BLE/defines.h b/examples/Async_Geiger_Counter_BLE/defines.h index f2e06dd..9d9b3eb 100644 --- a/examples/Async_Geiger_Counter_BLE/defines.h +++ b/examples/Async_Geiger_Counter_BLE/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -68,6 +60,8 @@ #if !BLYNK_USE_BLE_ONLY #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_Geiger_Counter_BLE/dynamicParams.h b/examples/Async_Geiger_Counter_BLE/dynamicParams.h index 0f63625..722769d 100644 --- a/examples/Async_Geiger_Counter_BLE/dynamicParams.h +++ b/examples/Async_Geiger_Counter_BLE/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_Geiger_Counter_BT/Async_Geiger_Counter_BT.ino b/examples/Async_Geiger_Counter_BT/Async_Geiger_Counter_BT.ino index 7381980..373aedd 100644 --- a/examples/Async_Geiger_Counter_BT/Async_Geiger_Counter_BT.ino +++ b/examples/Async_Geiger_Counter_BT/Async_Geiger_Counter_BT.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_Geiger_Counter_BT.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Async_Geiger_Counter_BT.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -66,6 +68,35 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif void IRAM_ATTR countPulse() { if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) @@ -199,6 +230,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_Geiger_Counter_BT using LITTLEFS")); #elif (USE_SPIFFS) @@ -208,11 +241,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -288,13 +322,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -318,7 +354,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_Geiger_Counter_BT/Credentials.h b/examples/Async_Geiger_Counter_BT/Credentials.h index 98214f4..7c629fa 100644 --- a/examples/Async_Geiger_Counter_BT/Credentials.h +++ b/examples/Async_Geiger_Counter_BT/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_Geiger_Counter_BT/defines.h b/examples/Async_Geiger_Counter_BT/defines.h index 16062db..320f5ec 100644 --- a/examples/Async_Geiger_Counter_BT/defines.h +++ b/examples/Async_Geiger_Counter_BT/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -66,6 +58,8 @@ #if !BLYNK_USE_BT_ONLY #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_Geiger_Counter_BT/dynamicParams.h b/examples/Async_Geiger_Counter_BT/dynamicParams.h index 694ffd6..97ab62f 100644 --- a/examples/Async_Geiger_Counter_BT/dynamicParams.h +++ b/examples/Async_Geiger_Counter_BT/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_Geiger_Counter_OLED/Async_Geiger_Counter_OLED.ino b/examples/Async_Geiger_Counter_OLED/Async_Geiger_Counter_OLED.ino index 495f4b9..7cfba94 100644 --- a/examples/Async_Geiger_Counter_OLED/Async_Geiger_Counter_OLED.ino +++ b/examples/Async_Geiger_Counter_OLED/Async_Geiger_Counter_OLED.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_Geiger_Counter_OLED.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Async_Geiger_Counter_OLED.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -75,6 +77,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void IRAM_ATTR countPulse() { if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) @@ -235,6 +267,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_Geiger_Counter_OLED using LITTLEFS")); #elif (USE_SPIFFS) @@ -244,11 +278,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -332,13 +367,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -362,7 +399,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_Geiger_Counter_OLED/Credentials.h b/examples/Async_Geiger_Counter_OLED/Credentials.h index 53ed52f..9ac09d6 100644 --- a/examples/Async_Geiger_Counter_OLED/Credentials.h +++ b/examples/Async_Geiger_Counter_OLED/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_Geiger_Counter_OLED/defines.h b/examples/Async_Geiger_Counter_OLED/defines.h index 9e83b5b..1f5fdb9 100644 --- a/examples/Async_Geiger_Counter_OLED/defines.h +++ b/examples/Async_Geiger_Counter_OLED/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -66,6 +58,8 @@ #if !BLYNK_USE_BT_ONLY #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_Geiger_Counter_OLED/dynamicParams.h b/examples/Async_Geiger_Counter_OLED/dynamicParams.h index 0f63625..722769d 100644 --- a/examples/Async_Geiger_Counter_OLED/dynamicParams.h +++ b/examples/Async_Geiger_Counter_OLED/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Async_Geiger_Counter_OLED_BT_BLE_WF.ino b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Async_Geiger_Counter_OLED_BT_BLE_WF.ino index 4100450..76b71e2 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Async_Geiger_Counter_OLED_BT_BLE_WF.ino +++ b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Async_Geiger_Counter_OLED_BT_BLE_WF.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_Geiger_Counter_OLED_BT_BLE_WF.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Async_Geiger_Counter_OLED_BT_BLE_WF.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -73,6 +75,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void IRAM_ATTR countPulse() { if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) @@ -235,6 +267,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_Geiger_Counter_OLED_BT_BLE_WF using LITTLEFS")); #elif (USE_SPIFFS) @@ -244,11 +278,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -350,13 +385,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -381,7 +418,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Credentials.h b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Credentials.h index 53ed52f..9ac09d6 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Credentials.h +++ b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/defines.h b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/defines.h index 8bae33c..cd59a1d 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/defines.h +++ b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -67,7 +59,11 @@ # include #endif +#define USE_BLYNK_WM true + #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/dynamicParams.h b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/dynamicParams.h index 0f63625..722769d 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/dynamicParams.h +++ b/examples/Async_Geiger_Counter_OLED_BT_BLE_WF/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_Geiger_Counter_OLED_BT_WF/Async_Geiger_Counter_OLED_BT_WF.ino b/examples/Async_Geiger_Counter_OLED_BT_WF/Async_Geiger_Counter_OLED_BT_WF.ino index eef9195..133cbe9 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_WF/Async_Geiger_Counter_OLED_BT_WF.ino +++ b/examples/Async_Geiger_Counter_OLED_BT_WF/Async_Geiger_Counter_OLED_BT_WF.ino @@ -1,21 +1,23 @@ -/**************************************************************************************************************************** - Async_Geiger_Counter_OLED_BT_WF.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + /**************************************************************************************************************************** + Async_Geiger_Counter_OLED_BT_WF.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Important Notes: @@ -73,6 +75,36 @@ BlynkTimer timer; #include Ticker led_ticker; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void IRAM_ATTR countPulse() { if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) @@ -226,6 +258,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_Geiger_Counter_OLED_BT_WF using LITTLEFS")); #elif (USE_SPIFFS) @@ -235,11 +269,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM @@ -314,13 +349,15 @@ void setup() } #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) -void displayCredentials(void) +void displayCredentials() { Serial.println(F("\nYour stored Credentials :")); - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + Serial.print(myMenuItems[i].displayName); + Serial.print(F(" = ")); + Serial.println(myMenuItems[i].pdata); } } #endif @@ -339,7 +376,7 @@ void loop() if (!displayedCredentials) { - for (int i = 0; i < NUM_MENU_ITEMS; i++) + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { if (!strlen(myMenuItems[i].pdata)) { diff --git a/examples/Async_Geiger_Counter_OLED_BT_WF/Credentials.h b/examples/Async_Geiger_Counter_OLED_BT_WF/Credentials.h index 53ed52f..9ac09d6 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_WF/Credentials.h +++ b/examples/Async_Geiger_Counter_OLED_BT_WF/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_Geiger_Counter_OLED_BT_WF/defines.h b/examples/Async_Geiger_Counter_OLED_BT_WF/defines.h index d438574..632559c 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_WF/defines.h +++ b/examples/Async_Geiger_Counter_OLED_BT_WF/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -65,6 +57,8 @@ //#define USE_BLYNK_WM false #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_Geiger_Counter_OLED_BT_WF/dynamicParams.h b/examples/Async_Geiger_Counter_OLED_BT_WF/dynamicParams.h index 694ffd6..97ab62f 100644 --- a/examples/Async_Geiger_Counter_OLED_BT_WF/dynamicParams.h +++ b/examples/Async_Geiger_Counter_OLED_BT_WF/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/examples/Async_PET_Check/Async_PET_Check.ino b/examples/Async_PET_Check/Async_PET_Check.ino index ce31d38..6f784c3 100644 --- a/examples/Async_PET_Check/Async_PET_Check.ino +++ b/examples/Async_PET_Check/Async_PET_Check.ino @@ -1,21 +1,23 @@ /**************************************************************************************************************************** - Async_PET_Check.ino - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Async_PET_Check.ino + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ /**************************************************************************************************************************** Example Created by Miguel Alexandre Wisintainer @@ -49,6 +51,36 @@ Ticker led_ticker; int NEAR_PET = 0; +#if USE_BLYNK_WM + +#define BLYNK_PIN_FORCED_CONFIG V10 +#define BLYNK_PIN_FORCED_PERS_CONFIG V20 + +// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nCP Button Hit. Rebooting") ); + + // This will keep CP once, clear after reset, even you didn't enter CP at all. + Blynk.resetAndEnterConfigPortal(); + } +} + +// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal +BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) +{ + if (param.asInt()) + { + Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + Blynk.resetAndEnterConfigPortalPersistent(); + } +} +#endif + void set_led(byte status) { digitalWrite(LED_BUILTIN , status); @@ -179,6 +211,8 @@ void setup() Serial.begin(115200); while (!Serial); + delay(200); + #if (USE_LITTLEFS) Serial.print(F("\nStarting Async_PET_Check_BLE using LITTLEFS")); #elif (USE_SPIFFS) @@ -188,11 +222,12 @@ void setup() #endif #if USE_SSL - Serial.println(" with SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" with SSL on ")); #else - Serial.println(" without SSL on " + String(ARDUINO_BOARD)); + Serial.print(F(" without SSL on ")); #endif + Serial.println(ARDUINO_BOARD); Serial.println(BLYNK_ASYNC_ESP32_BT_WF_VERSION); #if USE_BLYNK_WM diff --git a/examples/Async_PET_Check/Credentials.h b/examples/Async_PET_Check/Credentials.h index 53ed52f..9ac09d6 100644 --- a/examples/Async_PET_Check/Credentials.h +++ b/examples/Async_PET_Check/Credentials.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - Credentials.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + Credentials.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef Credentials_h diff --git a/examples/Async_PET_Check/defines.h b/examples/Async_PET_Check/defines.h index 247382f..41937bb 100644 --- a/examples/Async_PET_Check/defines.h +++ b/examples/Async_PET_Check/defines.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - defines.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + defines.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef defines_h @@ -65,6 +57,8 @@ //#define USE_BLYNK_WM false #if USE_BLYNK_WM + #define USE_DYNAMIC_PARAMETERS true + #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) #include #else diff --git a/examples/Async_PET_Check/dynamicParams.h b/examples/Async_PET_Check/dynamicParams.h index 694ffd6..97ab62f 100644 --- a/examples/Async_PET_Check/dynamicParams.h +++ b/examples/Async_PET_Check/dynamicParams.h @@ -1,21 +1,13 @@ /**************************************************************************************************************************** - dynamicParams.h - For ESP32 using WiFi along with BlueTooth BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + dynamicParams.h + For ESP32 using WiFi along with BlueTooth BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license *****************************************************************************************************************************/ #ifndef dynamicParams_h @@ -23,7 +15,11 @@ #if USE_BLYNK_WM - #define USE_DYNAMIC_PARAMETERS true +#if (USE_DYNAMIC_PARAMETERS) + #warning USE_DYNAMIC_PARAMETERS +#endif + +// USE_DYNAMIC_PARAMETERS defined in defined.h /////////////// Start dynamic Credentials /////////////// diff --git a/keywords.txt b/keywords.txt index de367b4..2033a10 100644 --- a/keywords.txt +++ b/keywords.txt @@ -57,8 +57,14 @@ getBoardName KEYWORD2 getHWPort KEYWORD2 getFullConfigData KEYWORD2 clearConfigData KEYWORD2 +resetAndEnterConfigPortal KEYWORD2 +resetAndEnterConfigPortalPersistent KEYWORD2 + +################# # Handler helpers +################# + BLYNK_READ KEYWORD2 BLYNK_WRITE KEYWORD2 BLYNK_READ_DEFAULT KEYWORD2 @@ -74,13 +80,19 @@ BLYNK_INPUT KEYWORD2 BLYNK_OUTPUT_DEFAULT KEYWORD2 BLYNK_INPUT_DEFAULT KEYWORD2 +#################### # Variables binding +#################### + BLYNK_VAR_INT KEYWORD2 BLYNK_VAR_LONG KEYWORD2 BLYNK_VAR_DOUBLE KEYWORD2 BLYNK_VAR_STRING KEYWORD2 +################# # Special defines +################# + BLYNK_DEBUG KEYWORD2 BLYNK_DEBUG_ALL KEYWORD2 BLYNK_PRINT KEYWORD2 @@ -95,7 +107,10 @@ BLYNK_USE_DIRECT_CONNECT KEYWORD2 BLYNK_MAX_SENDBYTES KEYWORD2 BLYNK_MAX_READBYTES KEYWORD2 +################### # Periodic actions +################### + #BLYNK_EVERY_N_MILLIS KEYWORD2 #BLYNK_EVERY_N_SECONDS KEYWORD2 #BLYNK_EVERY_N_MINUTES KEYWORD2 diff --git a/library.json b/library.json index aa8236e..60deb24 100644 --- a/library.json +++ b/library.json @@ -1,8 +1,8 @@ { "name": "Blynk_Async_ESP32_BT_WF", - "version": "1.1.0", + "version": "1.1.1", "description": "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 LittleFS, 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. Using AsyncWebServer instead of WebServer.", - "keywords": "sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, m2m, wifi, ble, bt-ble, bluetooth, ethernet, usb, serial, gsm, gprs, 3g, data, esp8266, http, multi-wifi, multi-blynk, littlefs, spiffs, eeprom, async, webserver", + "keywords": "sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, m2m, wifi, ble, bt-ble, bluetooth, ethernet, usb, serial, gsm, gprs, 3g, data, esp8266, http, drd, mrd, double-reset, multi-reset, multi-wifi, multi-blynk, littlefs, spiffs, eeprom, async, webserver, configportal, portal, credentials", "authors": { "name": "Khoi Hoang", diff --git a/library.properties b/library.properties index bc02c9b..7c3dc01 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Blynk_Async_ESP32_BT_WF -version=1.1.0 +version=1.1.1 author=Khoi Hoang license=MIT maintainer=Khoi Hoang diff --git a/src/BlynkSimpleEsp32_Async_BLE_WF.h b/src/BlynkSimpleEsp32_Async_BLE_WF.h index 6c5a565..7492de4 100644 --- a/src/BlynkSimpleEsp32_Async_BLE_WF.h +++ b/src/BlynkSimpleEsp32_Async_BLE_WF.h @@ -1,31 +1,35 @@ /**************************************************************************************************************************** - BlynkSimpleEsp32_Async_BLE_WF.h - For ESP32 using BLE along with WiFi - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Original Blynk Library author: - @file BlynkSimpleESP32.h - @author Volodymyr Shymanskyy - @license This project is released under the MIT License (MIT) - @copyright Copyright (c) 2015 Volodymyr Shymanskyy - @date Oct 2016 - @brief - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + BlynkSimpleEsp32_Async_BLE_WF.h + For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Original Blynk Library author: + @file BlynkSimpleESP32.h + @author Volodymyr Shymanskyy + @license This project is released under the MIT License (MIT) + @copyright Copyright (c) 2015 Volodymyr Shymanskyy + @date Oct 2016 + @brief + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ +#pragma once + #ifndef BlynkSimpleEsp32_BLE_WF_h #define BlynkSimpleEsp32_BLE_WF_h @@ -33,7 +37,7 @@ #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #endif -#define BLYNK_ASYNC_ESP32_BT_WF_VERSION "Blynk_Async_ESP32_BT_WF v1.1.0" +#define BLYNK_ASYNC_ESP32_BT_WF_VERSION "Blynk_Async_ESP32_BT_WF v1.1.1" #ifndef BLYNK_INFO_CONNECTION #define BLYNK_INFO_CONNECTION "Esp32_BLE" diff --git a/src/BlynkSimpleEsp32_Async_BT_WF.h b/src/BlynkSimpleEsp32_Async_BT_WF.h index 45c7077..931b55d 100644 --- a/src/BlynkSimpleEsp32_Async_BT_WF.h +++ b/src/BlynkSimpleEsp32_Async_BT_WF.h @@ -1,31 +1,35 @@ /**************************************************************************************************************************** - BlynkSimpleEsp32_Async_BT_WF.h - For ESP32 using BlueTooth along with WiFi - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Original Blynk Library author: - @file BlynkSimpleESP32.h - @author Volodymyr Shymanskyy - @license This project is released under the MIT License (MIT) - @copyright Copyright (c) 2015 Volodymyr Shymanskyy - @date Oct 2016 - @brief - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + BlynkSimpleEsp32_Async_BT_WF.h + For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Original Blynk Library author: + @file BlynkSimpleESP32.h + @author Volodymyr Shymanskyy + @license This project is released under the MIT License (MIT) + @copyright Copyright (c) 2015 Volodymyr Shymanskyy + @date Oct 2016 + @brief + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ +#pragma once + #ifndef BlynkSimpleEsp32_BT_WF_h #define BlynkSimpleEsp32_BT_WF_h @@ -33,7 +37,7 @@ #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #endif -#define BLYNK_ASYNC_ESP32_BT_WF_VERSION "Blynk_Async_ESP32_BT_WF v1.1.0" +#define BLYNK_ASYNC_ESP32_BT_WF_VERSION "Blynk_Async_ESP32_BT_WF v1.1.1" #ifndef BLYNK_INFO_CONNECTION #define BLYNK_INFO_CONNECTION "ESP32_BT" diff --git a/src/BlynkSimpleEsp32_Async_WF.h b/src/BlynkSimpleEsp32_Async_WF.h index 121ccea..78673e2 100644 --- a/src/BlynkSimpleEsp32_Async_WF.h +++ b/src/BlynkSimpleEsp32_Async_WF.h @@ -1,31 +1,35 @@ /**************************************************************************************************************************** - BlynkSimpleESP32_Async_WF.h - For ESP32 using WiFi along with BlueTooth / BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Original Blynk Library author: - @file BlynkSimpleESP32.h - @author Volodymyr Shymanskyy - @license This project is released under the MIT License (MIT) - @copyright Copyright (c) 2015 Volodymyr Shymanskyy - @date Oct 2016 - @brief - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + BlynkSimpleESP32_Async_WF.h + For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Original Blynk Library author: + @file BlynkSimpleESP32.h + @author Volodymyr Shymanskyy + @license This project is released under the MIT License (MIT) + @copyright Copyright (c) 2015 Volodymyr Shymanskyy + @date Oct 2016 + @brief + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ +#pragma once + #ifndef BlynkSimpleEsp32_WF_h #define BlynkSimpleEsp32_WF_h @@ -33,7 +37,7 @@ #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #endif -#define BLYNK_ASYNC_ESP32_BT_WF_VERSION "Blynk_Async_ESP32_BT_WF v1.1.0" +#define BLYNK_ASYNC_ESP32_BT_WF_VERSION "Blynk_Async_ESP32_BT_WF v1.1.1" #define BLYNK_SEND_ATOMIC diff --git a/src/BlynkSimpleEsp32_Async_WFM.h b/src/BlynkSimpleEsp32_Async_WFM.h index 2160667..8f96bc5 100644 --- a/src/BlynkSimpleEsp32_Async_WFM.h +++ b/src/BlynkSimpleEsp32_Async_WFM.h @@ -1,31 +1,35 @@ /**************************************************************************************************************************** - BlynkSimpleESP32_Async_WFM.h - For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE - - Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 - Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. - - Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF - Licensed under MIT license - - Original Blynk Library author: - @file BlynkSimpleESP32.h - @author Volodymyr Shymanskyy - @license This project is released under the MIT License (MIT) - @copyright Copyright (c) 2015 Volodymyr Shymanskyy - @date Oct 2016 - @brief - - Version: 1.1.0 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. - Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. - 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + BlynkSimpleESP32_Async_WFM.h + For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE + + Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32 + Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime. + + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF + Licensed under MIT license + + Original Blynk Library author: + @file BlynkSimpleESP32.h + @author Volodymyr Shymanskyy + @license This project is released under the MIT License (MIT) + @copyright Copyright (c) 2015 Volodymyr Shymanskyy + @date Oct 2016 + @brief + + Version: 1.1.1 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. + Bump up to v1.0.6 to sync with BlynkESP32_BT_WF v1.0.6. + 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples + 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches + Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP *****************************************************************************************************************************/ +#pragma once + #ifndef BlynkSimpleEsp32_WFM_h #define BlynkSimpleEsp32_WFM_h @@ -135,11 +139,14 @@ typedef struct } MenuItem; // -extern uint16_t NUM_MENU_ITEMS; -extern MenuItem myMenuItems []; +#if USE_DYNAMIC_PARAMETERS + extern uint16_t NUM_MENU_ITEMS; + extern MenuItem myMenuItems []; + bool *menuItemUpdated = NULL; +#endif #define SSID_MAX_LEN 32 -// WPA2 passwords can be up to 63 characters long. +//From v1.0.5, WPA2 passwords can be up to 63 characters long. #define PASS_MAX_LEN 64 typedef struct @@ -148,9 +155,13 @@ typedef struct char wifi_pw [PASS_MAX_LEN]; } WiFi_Credentials; +#define HEADER_MAX_LEN 16 + #define BLYNK_SERVER_MAX_LEN 32 #define BLYNK_TOKEN_MAX_LEN 36 +#define BOARD_NAME_MAX_LEN 24 + typedef struct { char blynk_server[BLYNK_SERVER_MAX_LEN]; @@ -164,13 +175,13 @@ typedef struct #define NUM_CONFIGURABLE_ITEMS ( 4 + (2 * NUM_WIFI_CREDENTIALS) + (2 * NUM_BLYNK_CREDENTIALS) ) typedef struct Configuration { - char header [16]; + char header [HEADER_MAX_LEN]; WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; int blynk_port; - char blynk_bt_tk [36]; - char blynk_ble_tk [36]; - char board_name [24]; + char blynk_bt_tk [BLYNK_TOKEN_MAX_LEN]; + char blynk_ble_tk [BLYNK_TOKEN_MAX_LEN]; + char board_name [BOARD_NAME_MAX_LEN]; int checkSum; } Blynk_WM_Configuration; // Currently CONFIG_DATA_SIZE = ( 120 + (96 * NUM_WIFI_CREDENTIALS) + (68 * NUM_BLYNK_CREDENTIALS) ) = 448 @@ -355,11 +366,15 @@ class BlynkWifi } BLYNK_LOG2(BLYNK_F("Hostname="), RFC952_hostname); - - //// New DRD //// - // noConfigPortal when getConfigData() OK and no DRD'ed - if (getConfigData() && noConfigPortal) - //// New DRD //// + + hadConfigData = getConfigData(); + + isForcedConfigPortal = isForcedCP(); + + //// New DRD/MRD //// + // noConfigPortal when getConfigData() OK and no MRD/DRD'ed + //if (getConfigData() && noConfigPortal) + if (hadConfigData && noConfigPortal && (!isForcedConfigPortal) ) { hadConfigData = true; @@ -404,11 +419,25 @@ class BlynkWifi } else { - BLYNK_LOG2(BLYNK_F("bg: Stay forever in config portal."), - noConfigPortal ? BLYNK_F("No configDat") : BLYNK_F("DRD detected")); +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(isForcedConfigPortal? BLYNK_F("bg: isForcedConfigPortal = true") : BLYNK_F("bg: isForcedConfigPortal = false")); +#endif + + // If not persistent => clear the flag so that after reset. no more CP, even CP not entered and saved + if (persForcedConfigPortal) + { + BLYNK_LOG2(BLYNK_F("bg:Stay forever in CP:"), isForcedConfigPortal ? BLYNK_F("Forced-Persistent") : (noConfigPortal ? BLYNK_F("No ConfigDat") : BLYNK_F("DRD/MRD"))); + } + else + { + BLYNK_LOG2(BLYNK_F("bg:Stay forever in CP:"), isForcedConfigPortal ? BLYNK_F("Forced-non-Persistent") : (noConfigPortal ? BLYNK_F("No ConfigDat") : BLYNK_F("DRD/MRD"))); + clearForcedCP(); + } + + hadConfigData = isForcedConfigPortal ? true : (noConfigPortal ? false : true); + // failed to connect to Blynk server, will start configuration mode - hadConfigData = false; startConfigurationMode(); } } @@ -556,7 +585,7 @@ class BlynkWifi } #define MIN_WIFI_CHANNEL 1 -#define MAX_WIFI_CHANNEL 12 +#define MAX_WIFI_CHANNEL 11 int setConfigPortalChannel(int channel = 1) { @@ -686,6 +715,42 @@ class BlynkWifi memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); saveConfigData(); } + + // Forced CP => Flag = 0xBEEFBEEF. Else => No forced CP + // Flag to be stored at (EEPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // to avoid corruption to current data + //#define FORCED_CONFIG_PORTAL_FLAG_DATA ( (uint32_t) 0xDEADBEEF) + //#define FORCED_PERS_CONFIG_PORTAL_FLAG_DATA ( (uint32_t) 0xBEEFDEAD) + + const uint32_t FORCED_CONFIG_PORTAL_FLAG_DATA = 0xDEADBEEF; + const uint32_t FORCED_PERS_CONFIG_PORTAL_FLAG_DATA = 0xBEEFDEAD; + + #define FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE 4 + + void resetAndEnterConfigPortal() + { + persForcedConfigPortal = false; + + setForcedCP(false); + + // Delay then reset the ESP32 after save data + delay(1000); + ESP.restart(); + } + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + void resetAndEnterConfigPortalPersistent() + { + persForcedConfigPortal = true; + + setForcedCP(true); + + // Delay then reset the ESP32 after save data + delay(1000); + ESP.restart(); + } + + ////////////////////////////////////////////// private: AsyncWebServer *server; @@ -696,6 +761,9 @@ class BlynkWifi unsigned long configTimeout; bool hadConfigData = false; + bool isForcedConfigPortal = false; + bool persForcedConfigPortal = false; + // default to channel 1 int WiFiAPChannel = 1; @@ -786,6 +854,126 @@ class BlynkWifi #define CREDENTIALS_FILENAME BLYNK_F("/wm_cred.dat") #define CREDENTIALS_FILENAME_BACKUP BLYNK_F("/wm_cred.bak") + #define CONFIG_PORTAL_FILENAME BLYNK_F("/wm_cp.dat") + #define CONFIG_PORTAL_FILENAME_BACKUP BLYNK_F("/wm_cp.bak") + + ////////////////////////////////////////////// + + void saveForcedCP(uint32_t value) + { + File file = FileFS.open(CONFIG_PORTAL_FILENAME, "w"); + + BLYNK_LOG1(BLYNK_F("SaveCPFile ")); + + if (file) + { + file.write((uint8_t*) &value, sizeof(value)); + file.close(); + BLYNK_LOG1(BLYNK_F("OK")); + } + else + { + BLYNK_LOG1(BLYNK_F("failed")); + } + + // Trying open redundant CP file + file = FileFS.open(CONFIG_PORTAL_FILENAME_BACKUP, "w"); + + BLYNK_LOG1(BLYNK_F("SaveBkUpCPFile ")); + + if (file) + { + file.write((uint8_t *) &value, sizeof(value)); + file.close(); + BLYNK_LOG1(BLYNK_F("OK")); + } + else + { + BLYNK_LOG1(BLYNK_F("failed")); + } + } + + ////////////////////////////////////////////// + + void setForcedCP(bool isPersistent) + { + uint32_t readForcedConfigPortalFlag = isPersistent? FORCED_PERS_CONFIG_PORTAL_FLAG_DATA : FORCED_CONFIG_PORTAL_FLAG_DATA; + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(isPersistent ? BLYNK_F("setForcedCP Persistent") : BLYNK_F("setForcedCP non-Persistent")); +#endif + + saveForcedCP(readForcedConfigPortalFlag); + } + + ////////////////////////////////////////////// + + void clearForcedCP() + { + uint32_t readForcedConfigPortalFlag = 0; + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("clearForcedCP")); +#endif + + saveForcedCP(readForcedConfigPortalFlag); + } + + ////////////////////////////////////////////// + + bool isForcedCP() + { + uint32_t readForcedConfigPortalFlag; + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("Check if isForcedCP")); +#endif + + File file = FileFS.open(CONFIG_PORTAL_FILENAME, "r"); + BLYNK_LOG1(BLYNK_F("LoadCPFile ")); + + if (!file) + { + BLYNK_LOG1(BLYNK_F("failed")); + + // Trying open redundant config file + file = FileFS.open(CONFIG_PORTAL_FILENAME_BACKUP, "r"); + BLYNK_LOG1(BLYNK_F("LoadBkUpCPFile ")); + + if (!file) + { + BLYNK_LOG1(BLYNK_F("failed")); + return false; + } + } + + file.readBytes((char *) &readForcedConfigPortalFlag, sizeof(readForcedConfigPortalFlag)); + + BLYNK_LOG1(BLYNK_F("OK")); + file.close(); + + // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // => set flag noForcedConfigPortal = false + if (readForcedConfigPortalFlag == FORCED_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = false; + return true; + } + else if (readForcedConfigPortalFlag == FORCED_PERS_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = true; + return true; + } + else + { + return false; + } + } + + ////////////////////////////////////////////// + +#if USE_DYNAMIC_PARAMETERS + bool checkDynamicData(void) { int checkSum = 0; @@ -879,6 +1067,8 @@ class BlynkWifi return true; } + + ////////////////////////////////////////////// bool loadDynamicData(void) { @@ -938,6 +1128,8 @@ class BlynkWifi return true; } + + ////////////////////////////////////////////// void saveDynamicData(void) { @@ -1020,6 +1212,9 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("failed")); } } +#endif + + ////////////////////////////////////////////// void loadConfigData(void) { @@ -1046,6 +1241,8 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("OK")); file.close(); } + + ////////////////////////////////////////////// void saveConfigData(void) { @@ -1083,16 +1280,23 @@ class BlynkWifi } } + ////////////////////////////////////////////// + void saveAllConfigData(void) { - saveConfigData(); + saveConfigData(); + +#if USE_DYNAMIC_PARAMETERS saveDynamicData(); +#endif } + + ////////////////////////////////////////////// // Return false if init new EEPROM or SPIFFS/LittleFS. No more need trying to connect. Go directly to config mode bool getConfigData() { - bool dynamicDataValid; + bool dynamicDataValid = true; int calChecksum; hadConfigData = false; @@ -1126,8 +1330,12 @@ class BlynkWifi // Don't need Config Portal anymore return true; } +#if USE_DYNAMIC_PARAMETERS else if ( ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) && ( FileFS.exists(CREDENTIALS_FILENAME) || FileFS.exists(CREDENTIALS_FILENAME_BACKUP) ) ) +#else + else if ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) +#endif { // if config file exists, load loadConfigData(); @@ -1141,31 +1349,34 @@ class BlynkWifi BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), BLYNK_F(",RCSum=0x"), String(BlynkESP32_WM_config.checkSum, HEX)); - + +#if USE_DYNAMIC_PARAMETERS // Load dynamic data dynamicDataValid = loadDynamicData(); if (dynamicDataValid) { -#if ( BLYNK_WM_DEBUG > 2) + #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Valid Stored Dynamic Data")); -#endif + #endif } -#if ( BLYNK_WM_DEBUG > 2) + #if ( BLYNK_WM_DEBUG > 2) else { BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data. Ignored")); } + #endif #endif } else { // Not loading Default config data, but having no config file => Config Portal return false; - } + } if ( (strncmp(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || (calChecksum != BlynkESP32_WM_config.checkSum) || !dynamicDataValid ) + { // Including Credentials CSum BLYNK_LOG2(BLYNK_F("InitCfgFile,sz="), sizeof(BlynkESP32_WM_config)); @@ -1177,32 +1388,34 @@ class BlynkWifi } else { - memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); + memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); strcpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_ssid, NO_CONFIG); - strcpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_pw, NO_CONFIG); - strcpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_ssid, NO_CONFIG); - strcpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_pw, NO_CONFIG); - strcpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_server, NO_CONFIG); - strcpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_token, NO_CONFIG); - strcpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_server, NO_CONFIG); - strcpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_token, NO_CONFIG); - BlynkESP32_WM_config.blynk_port = BLYNK_SERVER_HARDWARE_PORT; - strcpy(BlynkESP32_WM_config.blynk_bt_tk, NO_CONFIG); - strcpy(BlynkESP32_WM_config.blynk_ble_tk, NO_CONFIG); - strcpy(BlynkESP32_WM_config.board_name, NO_CONFIG); + strcpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_pw, NO_CONFIG); + strcpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_ssid, NO_CONFIG); + strcpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_pw, NO_CONFIG); + strcpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_server, NO_CONFIG); + strcpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_token, NO_CONFIG); + strcpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_server, NO_CONFIG); + strcpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_token, NO_CONFIG); + BlynkESP32_WM_config.blynk_port = BLYNK_SERVER_HARDWARE_PORT; + strcpy(BlynkESP32_WM_config.blynk_bt_tk, NO_CONFIG); + strcpy(BlynkESP32_WM_config.blynk_ble_tk, NO_CONFIG); + strcpy(BlynkESP32_WM_config.board_name, NO_CONFIG); +#if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { // Actual size of pdata is [maxlen + 1] memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); strncpy(myMenuItems[i].pdata, NO_CONFIG, myMenuItems[i].maxlen); } +#endif } strcpy(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE); - #if ( BLYNK_WM_DEBUG > 2) + #if (USE_DYNAMIC_PARAMETERS && ( BLYNK_WM_DEBUG > 2) ) for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { BLYNK_LOG4(BLYNK_F("g:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); @@ -1259,17 +1472,78 @@ class BlynkWifi #endif #ifndef EEPROM_START - #define EEPROM_START 0 //define 256 in DRD + #define EEPROM_START 0 //define 256 in DRD/MRD #else - #if (EEPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE) - #error EPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE. Please adjust. + #if (EEPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE > EEPROM_SIZE) + #error EPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE > EEPROM_SIZE. Please adjust. #endif -#endif + #endif // Stating positon to store Blynk8266_WM_config #define BLYNK_EEPROM_START (EEPROM_START + FLAG_DATA_SIZE) - bool checkDynamicData(void) + ////////////////////////////////////////////// + + void setForcedCP(bool isPersistent) + { + uint32_t readForcedConfigPortalFlag = isPersistent? FORCED_PERS_CONFIG_PORTAL_FLAG_DATA : FORCED_CONFIG_PORTAL_FLAG_DATA; + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("setForcedCP")); +#endif + + EEPROM.put(BLYNK_EEPROM_START + CONFIG_DATA_SIZE, readForcedConfigPortalFlag); + EEPROM.commit(); + } + ////////////////////////////////////////////// + + void clearForcedCP() + { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("clearForcedCP")); +#endif + + EEPROM.put(BLYNK_EEPROM_START + CONFIG_DATA_SIZE, 0); + EEPROM.commit(); + } + + ////////////////////////////////////////////// + + bool isForcedCP() + { + uint32_t readForcedConfigPortalFlag; + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("Check if isForcedCP")); +#endif + + // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // => set flag noForcedConfigPortal = false + EEPROM.get(BLYNK_EEPROM_START + CONFIG_DATA_SIZE, readForcedConfigPortalFlag); + + // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // => set flag noForcedConfigPortal = false + if (readForcedConfigPortalFlag == FORCED_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = false; + return true; + } + else if (readForcedConfigPortalFlag == FORCED_PERS_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = true; + return true; + } + else + { + return false; + } + } + + ////////////////////////////////////////////// + +#if USE_DYNAMIC_PARAMETERS + + bool checkDynamicData() { int checkSum = 0; int readCheckSum; @@ -1277,7 +1551,7 @@ class BlynkWifi #define BUFFER_LEN 128 char readBuffer[BUFFER_LEN + 1]; - uint16_t offset = BLYNK_EEPROM_START + sizeof(BlynkESP32_WM_config); + uint16_t offset = BLYNK_EEPROM_START + sizeof(BlynkESP32_WM_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; // Find the longest pdata, then dynamically allocate buffer. Remember to free when done // This is used to store tempo data to calculate checksum to see of data is valid @@ -1329,12 +1603,13 @@ class BlynkWifi return true; } - - bool EEPROM_getDynamicData(void) + ////////////////////////////////////////////// + + bool EEPROM_getDynamicData() { int readCheckSum; int checkSum = 0; - uint16_t offset = BLYNK_EEPROM_START + sizeof(BlynkESP32_WM_config); + uint16_t offset = BLYNK_EEPROM_START + sizeof(BlynkESP32_WM_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; totalDataSize = sizeof(BlynkESP32_WM_config) + sizeof(readCheckSum); @@ -1368,11 +1643,13 @@ class BlynkWifi return true; } + + ////////////////////////////////////////////// - void EEPROM_putDynamicData(void) + void EEPROM_putDynamicData() { int checkSum = 0; - uint16_t offset = BLYNK_EEPROM_START + sizeof(BlynkESP32_WM_config); + uint16_t offset = BLYNK_EEPROM_START + sizeof(BlynkESP32_WM_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { @@ -1395,11 +1672,14 @@ class BlynkWifi BLYNK_LOG2(F("CrWCSum=0x"), String(checkSum, HEX)); } +#endif + + ////////////////////////////////////////////// // Return false if init new EEPROM or SPIFFS/LittleFS. No more need trying to connect. Go directly to config mode bool getConfigData() { - bool dynamicDataValid; + bool dynamicDataValid = true; int calChecksum; hadConfigData = false; @@ -1438,21 +1718,24 @@ class BlynkWifi BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), BLYNK_F(",RCSum=0x"), String(BlynkESP32_WM_config.checkSum, HEX)); + +#if USE_DYNAMIC_PARAMETERS // Load dynamic data from EEPROM dynamicDataValid = EEPROM_getDynamicData(); if (dynamicDataValid) { -#if ( BLYNK_WM_DEBUG > 2) + #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Valid Stored Dynamic Data")); -#endif + #endif } -#if ( BLYNK_WM_DEBUG > 2) + #if ( BLYNK_WM_DEBUG > 2) else { BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data. Ignored")); } + #endif #endif } @@ -1484,17 +1767,19 @@ class BlynkWifi strcpy(BlynkESP32_WM_config.blynk_ble_tk, NO_CONFIG); strcpy(BlynkESP32_WM_config.board_name, NO_CONFIG); +#if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { // Actual size of pdata is [maxlen + 1] memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); strncpy(myMenuItems[i].pdata, NO_CONFIG, myMenuItems[i].maxlen); } +#endif } strcpy(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE); - #if ( BLYNK_WM_DEBUG > 2) + #if ( USE_DYNAMIC_PARAMETERS && ( BLYNK_WM_DEBUG > 2) ) for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { BLYNK_LOG4(BLYNK_F("g:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); @@ -1527,6 +1812,8 @@ class BlynkWifi return true; } + + ////////////////////////////////////////////// void saveConfigData() { @@ -1539,6 +1826,8 @@ class BlynkWifi EEPROM.commit(); } + ////////////////////////////////////////////// + void saveAllConfigData(void) { int calChecksum = calcChecksum(); @@ -1553,6 +1842,8 @@ class BlynkWifi #endif + ////////////////////////////////////////////// + bool connectMultiBlynk(void) { #define BLYNK_CONNECT_TIMEOUT_MS 10000L @@ -1614,12 +1905,15 @@ class BlynkWifi return status; } + ////////////////////////////////////////////// + void createHTML(String &root_html_template) { String pitem; root_html_template = String(BLYNK_WM_HTML_HEAD) + BLYNK_WM_FLDSET_START; - + +#if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { pitem = String(BLYNK_WM_HTML_PARAM); @@ -1630,9 +1924,11 @@ class BlynkWifi root_html_template += pitem; } +#endif root_html_template += String(BLYNK_WM_FLDSET_END) + BLYNK_WM_HTML_BUTTON + BLYNK_WM_HTML_SCRIPT; - + +#if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { pitem = String(BLYNK_WM_HTML_SCRIPT_ITEM); @@ -1641,12 +1937,14 @@ class BlynkWifi root_html_template += pitem; } +#endif root_html_template += String(BLYNK_WM_HTML_SCRIPT_END) + BLYNK_WM_HTML_END; return; } - //// + + ////////////////////////////////////////////// void handleRequest(AsyncWebServerRequest *request) { @@ -1693,15 +1991,17 @@ class BlynkWifi result.replace("[[bltk]]", BlynkESP32_WM_config.blynk_ble_tk); result.replace("[[nm]]", BlynkESP32_WM_config.board_name); +#if USE_DYNAMIC_PARAMETERS + // Load default configuration for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { String toChange = String("[[") + myMenuItems[i].id + "]]"; result.replace(toChange, myMenuItems[i].pdata); - -#if ( BLYNK_WM_DEBUG > 2) + #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG4(BLYNK_F("h1:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ) -#endif + #endif } +#endif request->send(200, "text/html", result); @@ -1714,153 +2014,176 @@ class BlynkWifi strcpy(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE); } - if (key == "id") +#if USE_DYNAMIC_PARAMETERS + if (!menuItemUpdated) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("id: = "), value.c_str()); -#endif - + // Don't need to free + menuItemUpdated = new bool[NUM_MENU_ITEMS]; + + if (menuItemUpdated) + { + for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) + { + // To flag item is not yet updated + menuItemUpdated[i] = false; + } + #if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("h: Init menuItemUpdated" )); + #endif + } + else + { + BLYNK_LOG1(BLYNK_F("h: Error can't alloc memory for menuItemUpdated" )); + } + } +#endif + + static bool id_Updated = false; + static bool pw_Updated = false; + static bool id1_Updated = false; + static bool pw1_Updated = false; + static bool sv_Updated = false; + static bool tk_Updated = false; + static bool sv1_Updated = false; + static bool tk1_Updated = false; + static bool pt_Updated = false; + static bool bttk_Updated = false; + static bool bltk_Updated = false; + static bool nm_Updated = false; + + if (!id_Updated && (key == String("id"))) + { + id_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.WiFi_Creds[0].wifi_ssid) - 1) strcpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_ssid, value.c_str()); else strncpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_ssid, value.c_str(), sizeof(BlynkESP32_WM_config.WiFi_Creds[0].wifi_ssid) - 1); } - else if (key == "pw") + else if (!pw_Updated && (key == String("pw"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("pw: = "), value.c_str()); -#endif - + pw_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.WiFi_Creds[0].wifi_pw) - 1) strcpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_pw, value.c_str()); else strncpy(BlynkESP32_WM_config.WiFi_Creds[0].wifi_pw, value.c_str(), sizeof(BlynkESP32_WM_config.WiFi_Creds[0].wifi_pw) - 1); } - else if (key == "id1") + else if (!id1_Updated && (key == String("id1"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("id1: = "), value.c_str()); -#endif - + id1_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.WiFi_Creds[1].wifi_ssid) - 1) strcpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_ssid, value.c_str()); else strncpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_ssid, value.c_str(), sizeof(BlynkESP32_WM_config.WiFi_Creds[1].wifi_ssid) - 1); } - else if (key == "pw1") + else if (!pw1_Updated && (key == String("pw1"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("pw1: = "), value.c_str()); -#endif - + pw1_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.WiFi_Creds[1].wifi_pw) - 1) strcpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_pw, value.c_str()); else strncpy(BlynkESP32_WM_config.WiFi_Creds[1].wifi_pw, value.c_str(), sizeof(BlynkESP32_WM_config.WiFi_Creds[1].wifi_pw) - 1); } - else if (key == "sv") + else if (!sv_Updated && (key == String("sv"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("sv: = "), value.c_str()); -#endif - + sv_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.Blynk_Creds[0].blynk_server) - 1) strcpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_server, value.c_str()); else strncpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_server, value.c_str(), sizeof(BlynkESP32_WM_config.Blynk_Creds[0].blynk_server) - 1); } - else if (key == "tk") + else if (!tk_Updated && (key == String("tk"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("tk: = "), value.c_str()); -#endif - + tk_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.Blynk_Creds[0].blynk_token) - 1) strcpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_token, value.c_str()); else strncpy(BlynkESP32_WM_config.Blynk_Creds[0].blynk_token, value.c_str(), sizeof(BlynkESP32_WM_config.Blynk_Creds[0].blynk_token) - 1); } - else if (key == "sv1") + else if (!sv1_Updated && (key == String("sv1"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("sv1: = "), value.c_str()); -#endif - + sv1_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.Blynk_Creds[1].blynk_server) - 1) strcpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_server, value.c_str()); else strncpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_server, value.c_str(), sizeof(BlynkESP32_WM_config.Blynk_Creds[1].blynk_server) - 1); } - else if (key == "tk1") + else if (!tk1_Updated && (key == String("tk1"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("tk1: = "), value.c_str()); -#endif - + tk1_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.Blynk_Creds[1].blynk_token) - 1) strcpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_token, value.c_str()); else strncpy(BlynkESP32_WM_config.Blynk_Creds[1].blynk_token, value.c_str(), sizeof(BlynkESP32_WM_config.Blynk_Creds[1].blynk_token) - 1); } - else if (key == "pt") + else if (!pt_Updated && (key == String("pt"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("pt = "), value.toInt()); -#endif - + pt_Updated = true; number_items_Updated++; + BlynkESP32_WM_config.blynk_port = value.toInt(); } - else if (key == "bttk") + else if (!bttk_Updated && (key == String("bttk"))) { #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG2(BLYNK_F("bttk: = "), value.c_str()); #endif - + bttk_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.blynk_bt_tk) - 1) strcpy(BlynkESP32_WM_config.blynk_bt_tk, value.c_str()); else strncpy(BlynkESP32_WM_config.blynk_bt_tk, value.c_str(), sizeof(BlynkESP32_WM_config.blynk_bt_tk) - 1); } - else if (key == "bltk") + else if (!bltk_Updated && (key == String("bltk"))) { #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG2(BLYNK_F("bltk: = "), value.c_str()); #endif - + bltk_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.blynk_ble_tk) - 1) strcpy(BlynkESP32_WM_config.blynk_ble_tk, value.c_str()); else strncpy(BlynkESP32_WM_config.blynk_ble_tk, value.c_str(), sizeof(BlynkESP32_WM_config.blynk_ble_tk) - 1); } - else if (key == "nm") + else if (!nm_Updated && (key == String("nm"))) { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("nm: = "), value.c_str()); -#endif - + nm_Updated = true; number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkESP32_WM_config.board_name) - 1) strcpy(BlynkESP32_WM_config.board_name, value.c_str()); else strncpy(BlynkESP32_WM_config.board_name, value.c_str(), sizeof(BlynkESP32_WM_config.board_name) - 1); } +#if USE_DYNAMIC_PARAMETERS for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) { - if (key == myMenuItems[i].id) + if ( !menuItemUpdated[i] && (key == myMenuItems[i].id) ) { - //BLYNK_LOG4(F("h:"), myMenuItems[i].id, F("="), value.c_str() ); + BLYNK_LOG4(BLYNK_F("h:"), myMenuItems[i].id, BLYNK_F("="), value.c_str() ); + + menuItemUpdated[i] = true; + number_items_Updated++; // Actual size of pdata is [maxlen + 1] @@ -1870,12 +2193,20 @@ class BlynkWifi strcpy(myMenuItems[i].pdata, value.c_str()); else strncpy(myMenuItems[i].pdata, value.c_str(), myMenuItems[i].maxlen); +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG4(BLYNK_F("h2:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); +#endif } } +#endif request->send(200, "text/html", "OK"); +#if USE_DYNAMIC_PARAMETERS if (number_items_Updated == NUM_CONFIGURABLE_ITEMS + NUM_MENU_ITEMS) +#else + if (number_items_Updated == NUM_CONFIGURABLE_ITEMS) +#endif { #if USE_LITTLEFS BLYNK_LOG2(BLYNK_F("h:Updating LittleFS:"), CONFIG_FILENAME); @@ -1886,10 +2217,16 @@ class BlynkWifi #endif saveAllConfigData(); + + // Done with CP, Clear CP Flag here if forced + if (isForcedConfigPortal) + { + clearForcedCP(); + } BLYNK_LOG1(BLYNK_F("h:Rst")); - // Delay then reset the ESP32 after save data + // Delay then reset the ESP8266 after save data delay(1000); ESP.restart(); }