diff --git a/README.md b/README.md index 20dbca3..612d073 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Also see examples: 6. [Geiger_Counter_OLED_BT_WF](examples/Geiger_Counter_OLED_BT_WF) 7. [Geiger_Counter_OLED_BT_BLE_WF](examples/Geiger_Counter_OLED_BT_BLE_WF) -and real-life project [Hack GMC Geigercounter With Blynk](https://www.instructables.com/id/Hack-GMC-Geigercounter-With-Blynk/) of [Crosswalkersam](https://www.instructables.com/member/Crosswalkersam/) +and real-life project [Hack GMC Geigercounter With Blynk](https://www.instructables.com/id/Hack-GMC-Geigercounter-With-Blynk/) of [Crosswalkersam](https://www.instructables.com/member/Crosswalkersam/)

@@ -92,8 +92,8 @@ Enter your credentials, then click `Save`. After you restarted, you will see you ## Prerequisite -* Release `1.0.4` or newer of the [ESP32 core for Arduino](https://github.com/espressif/arduino-esp32) -* [`Blynk library 0.6.1 or later`](https://github.com/blynkkk/blynk-library/releases) +* `ESP32 core 1.0.4 or later` +* `Blynk library 0.6.1 or later` (https://www.arduino.cc/en/guide/libraries#toc3) ## Sample code ``` @@ -208,28 +208,68 @@ void loop() } ``` -and this is the terminal debug output when running both WiFi and BT at the same time using example [ESP32_BLE_WF](examples/ESP32_BLE_WF) +and this is the terminal debug output when running both WiFi and BT at the same time using example [Geiger_Counter_OLED_BT_BLE_WF](examples/Geiger_Counter_OLED_BT_BLE_WF) ``` -Starting ESP32_BLE_WF -GPIO14 LOW, Use BLE -[51] Load configfile -[52] OK -[52] Header = ESP32_WFM, SSID = ***, PW = *** -[52] Server = account.duckdns.org, Port = 8080, Token = **** -[56] BT Token = ****, BLE Token = **** -[64] Board Name = Geiger-OLED-BLE-BT -Connecting Blynk via BLE, using auth = **** -[149] + +Starting Geiger-Counter-OLED-BT-BLE-WF +Use WiFi to connect Blynk +[332] RFC925 Hostname = GeigerCounter-WiFi +[338] Calc Cksum = 0x3446, Read Cksum = 0x3446 +[338] Header = ESP32_WFM, SSID = ****, PW = **** +[338] Server = ****.duckdns.org, Port = 8080, Token = **** +[344] BT Token = ****, BLE Token = **** +[352] Board Name = ESP32-BLE-WF +[355] + ___ __ __ + / _ )/ /_ _____ / /__ + / _ / / // / _ \/ '_/ + /____/_/\_, /_//_/_/\_\ + /___/ v0.6.1 on ESP32 + +[371] con2WF: start +[1872] con2WF: con OK +[1872] IP = 192.168.2.92, GW = 192.168.2.1, SN = 255.255.0.0 +[1872] DNS1 = 192.168.2.1, DNS2 = 0.0.0.0 +[1872] bg: WiFi connected. Try Blynk +[1875] BlynkArduinoClient.connect: Connecting to ****.duckdns.org:8080 +[1956] Ready (ping: 42ms). +[2026] bg: WiFi+Blynk connected +Use BLE to connect Blynk +BLE_auth = **** +[2027] ___ __ __ / _ )/ /_ _____ / /__ / _ / / // / _ \/ '_/ /____/_/\_, /_//_/_/\_\ /___/ v0.6.1 on ESP32 -[75491] BLE connect -[77327] Ready +[14199] BLE connect +[15191] Ready +cpm = 0 - RadiationValue = 0.000 uSv/h - Equivalent RadiationDose = 0.0000 uSv +cpm = 30 - RadiationValue = 0.197 uSv/h - Equivalent RadiationDose = 0.0008 uSv +cpm = 60 - RadiationValue = 0.395 uSv/h - Equivalent RadiationDose = 0.0025 uSv +cpm = 90 - RadiationValue = 0.592 uSv/h - Equivalent RadiationDose = 0.0049 uSv +cpm = 120 - RadiationValue = 0.790 uSv/h - Equivalent RadiationDose = 0.0082 uSv +cpm = 150 - RadiationValue = 0.987 uSv/h - Equivalent RadiationDose = 0.0123 uSv +cpm = 180 - RadiationValue = 1.184 uSv/h - Equivalent RadiationDose = 0.0173 uSv +cpm = 210 - RadiationValue = 1.382 uSv/h - Equivalent RadiationDose = 0.0230 uSv +cpm = 240 - RadiationValue = 1.579 uSv/h - Equivalent RadiationDose = 0.0296 uSv +cpm = 270 - RadiationValue = 1.777 uSv/h - Equivalent RadiationDose = 0.0370 uSv +cpm = 300 - RadiationValue = 1.974 uSv/h - Equivalent RadiationDose = 0.0452 uSv +cpm = 330 - RadiationValue = 2.171 uSv/h - Equivalent RadiationDose = 0.0543 uSv +cpm = 360 - RadiationValue = 2.369 uSv/h - Equivalent RadiationDose = 0.0642 uSv +cpm = 390 - RadiationValue = 2.566 uSv/h - Equivalent RadiationDose = 0.0748 uSv +cpm = 420 - RadiationValue = 2.764 uSv/h - Equivalent RadiationDose = 0.0864 uSv +cpm = 450 - RadiationValue = 2.961 uSv/h - Equivalent RadiationDose = 0.0987 uSv +cpm = 480 - RadiationValue = 3.158 uSv/h - Equivalent RadiationDose = 0.1119 uSv +cpm = 510 - RadiationValue = 3.356 uSv/h - Equivalent RadiationDose = 0.1258 uSv +cpm = 540 - RadiationValue = 3.553 uSv/h - Equivalent RadiationDose = 0.1406 uSv +cpm = 570 - RadiationValue = 3.751 uSv/h - Equivalent RadiationDose = 0.1563 uSv +cpm = 600 - RadiationValue = 3.948 uSv/h - Equivalent RadiationDose = 0.1727 uSv +cpm = 630 - RadiationValue = 4.145 uSv/h - Equivalent RadiationDose = 0.1900 uSv + ``` @@ -246,6 +286,15 @@ Connecting Blynk via BLE, using auth = **** 9. Add configurable Static IP, GW, Subnet Mask and 2 DNS Servers' IP Addresses. 10. Use dynamically alocated Config Portal WebServer 11. Fix BT/BLE login timeout + 12. Add checksum for config data integrity + 13. Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary + +### Releases v1.0.3 + +***Why this version*** + +1. Add checksum for config data integrity. +2. Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary ### Releases v1.0.2 diff --git a/keywords.txt b/keywords.txt index 979685c..4b94cfc 100644 --- a/keywords.txt +++ b/keywords.txt @@ -48,6 +48,7 @@ getBlynkBLEToken KEYWORD2 getBoardName KEYWORD2 getHWPort KEYWORD2 getFullConfigData KEYWORD2 +clearConfigData KEYWORD2 # Handler helpers BLYNK_READ KEYWORD2 diff --git a/library.json b/library.json index 3b0a9a2..01d568c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "BlynkESP32_BT_WF", - "version": "1.0.2", + "version": "1.0.3", "description": "Build a smartphone app for your project in minutes. Blynk allows creating IoT solutions easily. It supports WiFi, BLE, Bluetooth, Ethernet, GSM, USB, Serial. Works with many boards like ESP8266, ESP32, Arduino UNO, Nano, Due, Mega, Zero, MKR100, Yun, Raspberry Pi, Particle, Energia, ARM mbed, Intel Edison/Galileo/Joule, BBC micro:bit, DFRobot, RedBearLab, Microduino, LinkIt ONE ...", "keywords": "sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, m2m, wifi, ble, bluetooth, ethernet, usb, serial, gsm, gprs, 3g, data, esp8266, http", "authors": diff --git a/library.properties b/library.properties index c826c11..ab85be3 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=BlynkESP32_BT_WF -version=1.0.2 +version=1.0.3 author=Khoi Hoang license=MIT maintainer=Khoi Hoang -sentence=Enable inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. Then run both WiFi and BT/BLE simultaneously, or select one to use at runtime after reboot. -paragraph=Eliminate hardcoding your Wifi and Blynk credentials and configuration data saved in either SPIFFS or EEPROM. +sentence=Enable inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. Then select one at reboot or run both. Eliminate hardcoding your Wifi and Blynk credentials and configuration data saved in either SPIFFS or EEPROM. +paragraph=Library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. Then select one at reboot or run both. Eliminate hardcoding your Wifi and Blynk credentials and configuration data saved in either SPIFFS or EEPROM. category=Communication url=https://github.com/khoih-prog/BlynkESP32_BT_WF architectures=esp32 diff --git a/src/BlynkSimpleEsp32_BLE_WF.h b/src/BlynkSimpleEsp32_BLE_WF.h index a1c5dbc..277483d 100644 --- a/src/BlynkSimpleEsp32_BLE_WF.h +++ b/src/BlynkSimpleEsp32_BLE_WF.h @@ -6,14 +6,14 @@ * Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases * Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager * Licensed under MIT license - * Version: 1.0.2 + * Version: 1.0.3 * * 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 Nov 2017 + * @date Oct 2016 * @brief * * Version Modified By Date Comments @@ -21,6 +21,7 @@ * 1.0.0 K Hoang 25/01/2020 Initial coding * 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi * 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library + * 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_BLE_WF_h diff --git a/src/BlynkSimpleEsp32_BT_WF.h b/src/BlynkSimpleEsp32_BT_WF.h index a954b9a..8512bc1 100644 --- a/src/BlynkSimpleEsp32_BT_WF.h +++ b/src/BlynkSimpleEsp32_BT_WF.h @@ -6,14 +6,14 @@ * Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases * Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager * Licensed under MIT license - * Version: 1.0.2 + * Version: 1.0.3 * * 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 Nov 2017 + * @date Oct 2016 * @brief * * Version Modified By Date Comments @@ -21,6 +21,7 @@ * 1.0.0 K Hoang 25/01/2020 Initial coding * 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi * 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library + * 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_BT_WF_h diff --git a/src/BlynkSimpleEsp32_WF.h b/src/BlynkSimpleEsp32_WF.h index 4ec4db8..828f8f7 100644 --- a/src/BlynkSimpleEsp32_WF.h +++ b/src/BlynkSimpleEsp32_WF.h @@ -6,7 +6,7 @@ * Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases * Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager * Licensed under MIT license - * Version: 1.0.2 + * Version: 1.0.3 * * Original Blynk Library author: * @file BlynkSimpleESP32.h @@ -21,6 +21,7 @@ * 1.0.0 K Hoang 25/01/2020 Initial coding * 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi * 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library + * 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_WF_h diff --git a/src/BlynkSimpleEsp32_WFM.h b/src/BlynkSimpleEsp32_WFM.h index 4b4c48a..32ab75d 100644 --- a/src/BlynkSimpleEsp32_WFM.h +++ b/src/BlynkSimpleEsp32_WFM.h @@ -6,7 +6,7 @@ * Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases * Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager * Licensed under MIT license - * Version: 1.0.2 + * Version: 1.0.3 * * Original Blynk Library author: * @file BlynkSimpleESP32.h @@ -21,6 +21,7 @@ * 1.0.0 K Hoang 25/01/2020 Initial coding * 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi * 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library + * 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_WFM_h @@ -66,9 +67,10 @@ typedef struct Configuration char blynk_bt_tk [36]; char blynk_ble_tk [36]; char board_name [24]; + int checkSum; } Blynk_WF_Configuration; -// Currently CONFIG_DATA_SIZE = 248 +// Currently CONFIG_DATA_SIZE = 252 uint16_t CONFIG_DATA_SIZE = sizeof(Blynk_WF_Configuration); #define root_html_template " \ @@ -158,8 +160,8 @@ alert('Updated. Reset'); \ #define BLYNK_SERVER_HARDWARE_PORT 8080 -#define BOARD_TYPE "ESP32_WFM" -#define NO_CONFIG "nothing" +#define BLYNK_BOARD_TYPE "ESP32_WFM" +#define NO_CONFIG "nothing" class BlynkWifi : public BlynkProtocol @@ -248,6 +250,8 @@ class BlynkWifi pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); + WiFi.mode(WIFI_STA); + if (iHostname[0] == 0) { #ifdef ESP8266 @@ -530,6 +534,12 @@ class BlynkWifi return (configData); } + + void clearConfigData() + { + memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); + saveConfigData(); + } private: WebServer *server; @@ -587,7 +597,18 @@ class BlynkWifi BLYNK_F(", Token = "), BlynkESP32_WM_config.blynk_token); BLYNK_LOG4(BLYNK_F("BT Token = "), BlynkESP32_WM_config.blynk_bt_tk, BLYNK_F(", BLE Token = "), BlynkESP32_WM_config.blynk_ble_tk); BLYNK_LOG2(BLYNK_F("Board Name = "), BlynkESP32_WM_config.board_name); - } + } + + int calcChecksum() + { + int checkSum = 0; + for (uint16_t index = 0; index < (sizeof(BlynkESP32_WM_config) - sizeof(BlynkESP32_WM_config.checkSum)); index++) + { + checkSum += * ( ( (byte*) &BlynkESP32_WM_config ) + index); + } + + return checkSum; + } #if USE_SPIFFS @@ -625,6 +646,10 @@ class BlynkWifi File file = SPIFFS.open(CONFIG_FILENAME, "w"); BLYNK_LOG1(BLYNK_F("Save configfile ")); + int calChecksum = calcChecksum(); + BlynkESP32_WM_config.checkSum = calChecksum; + BLYNK_LOG2(BLYNK_F("chkSum = 0x"), String(calChecksum, HEX)); + if (file) { file.write((uint8_t*) &BlynkESP32_WM_config, sizeof(BlynkESP32_WM_config)); @@ -667,15 +692,21 @@ class BlynkWifi loadConfigData(); } - displayConfigData(); + int calChecksum = calcChecksum(); - if (strncmp(BlynkESP32_WM_config.header, BOARD_TYPE, strlen(BOARD_TYPE)) != 0) + BLYNK_LOG4(BLYNK_F("Calc Cksum = 0x"), String(calChecksum, HEX), + BLYNK_F(", Read Cksum = 0x"), String(BlynkESP32_WM_config.checkSum, HEX)); + + //displayConfigData(); + + if ( (strncmp(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || + (calChecksum != BlynkESP32_WM_config.checkSum) ) { memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); BLYNK_LOG2(BLYNK_F("Init new configfile, size = "), sizeof(BlynkESP32_WM_config)); // doesn't have any configuration - strcpy(BlynkESP32_WM_config.header, BOARD_TYPE); + strcpy(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE); strcpy(BlynkESP32_WM_config.wifi_ssid, NO_CONFIG); strcpy(BlynkESP32_WM_config.wifi_pw, NO_CONFIG); strcpy(BlynkESP32_WM_config.blynk_server, NO_CONFIG); @@ -683,7 +714,9 @@ class BlynkWifi strcpy(BlynkESP32_WM_config.blynk_token, NO_CONFIG); 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.board_name, NO_CONFIG); + // Don't need + BlynkESP32_WM_config.checkSum = 0; saveConfigData(); @@ -739,15 +772,19 @@ class BlynkWifi EEPROM.begin(EEPROM_SIZE); EEPROM.get(EEPROM_START, BlynkESP32_WM_config); - displayConfigData(); + int calChecksum = calcChecksum(); + + BLYNK_LOG4(BLYNK_F("Calc Cksum = 0x"), String(calChecksum, HEX), + BLYNK_F(", Read Cksum = 0x"), String(BlynkESP32_WM_config.checkSum, HEX)); - if (strncmp(BlynkESP32_WM_config.header, BOARD_TYPE, strlen(BOARD_TYPE)) != 0) + if ( (strncmp(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || + (calChecksum != BlynkESP32_WM_config.checkSum) ) { memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); BLYNK_LOG2(BLYNK_F("Init new EEPROM, size = "), EEPROM_SIZE /*EEPROM.length()*/); // doesn't have any configuration - strcpy(BlynkESP32_WM_config.header, BOARD_TYPE); + strcpy(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE); strcpy(BlynkESP32_WM_config.wifi_ssid, NO_CONFIG); strcpy(BlynkESP32_WM_config.wifi_pw, NO_CONFIG); strcpy(BlynkESP32_WM_config.blynk_server, NO_CONFIG); @@ -756,6 +793,8 @@ class BlynkWifi 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); + // Don't need + BlynkESP32_WM_config.checkSum = 0; EEPROM.put(EEPROM_START, BlynkESP32_WM_config); EEPROM.commit(); @@ -774,14 +813,18 @@ class BlynkWifi } else { - displayConfigData(); + displayConfigData(); } return true; } void saveConfigData() { - BLYNK_LOG2(BLYNK_F("Save EEPROM, size = "), EEPROM_SIZE /*EEPROM.length()*/); + int calChecksum = calcChecksum(); + BlynkESP32_WM_config.checkSum = calChecksum; + BLYNK_LOG4(BLYNK_F("Save EEPROM, size = "), EEPROM_SIZE /*EEPROM.length()*/, + BLYNK_F(", chkSum = 0x"), String(calChecksum, HEX)); + EEPROM.put(EEPROM_START, BlynkESP32_WM_config); EEPROM.commit(); } @@ -870,7 +913,7 @@ class BlynkWifi if (number_items_Updated == 0) { memset(&BlynkESP32_WM_config, 0, sizeof(BlynkESP32_WM_config)); - strcpy(BlynkESP32_WM_config.header, BOARD_TYPE); + strcpy(BlynkESP32_WM_config.header, BLYNK_BOARD_TYPE); } if (key == "wf_id")