├── pics ├── Main.png ├── Saved.png ├── WiFi_AP.jpg ├── ConfigPortal.png └── Input_With_Scan.png ├── examples ├── Geiger_Counter_OLED │ ├── pics │ │ ├── Box1.jpg │ │ ├── Box2.jpg │ │ ├── Blynk.jpg │ │ └── Schematics.jpg │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── Geiger_Counter_OLED.ino ├── PET_Check │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── PET_Check.ino ├── ESP32_BLE_WF │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── ESP32_BLE_WF.ino ├── ESP32_BT_WF │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── ESP32_BT_WF.ino ├── Geiger_Counter_BLE │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── Geiger_Counter_BLE.ino ├── Geiger_Counter_BT │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── Geiger_Counter_BT.ino ├── Geiger_Counter_OLED_BT_WF │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── Geiger_Counter_OLED_BT_WF.ino └── Geiger_Counter_OLED_BT_BLE_WF │ ├── Credentials.h │ ├── dynamicParams.h │ ├── defines.h │ └── Geiger_Counter_OLED_BT_BLE_WF.ino ├── .github ├── workflows │ └── auto-github-actions.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── .gitignore ├── LICENSE ├── library.properties ├── CONTRIBUTING.md ├── library.json ├── platformio └── platformio.ini ├── keywords.txt ├── src ├── BlynkSimpleEsp32_WF.h ├── BlynkSimpleEsp32_BLE_WF.h └── BlynkSimpleEsp32_BT_WF.h └── changelog.md /pics/Main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/pics/Main.png -------------------------------------------------------------------------------- /pics/Saved.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/pics/Saved.png -------------------------------------------------------------------------------- /pics/WiFi_AP.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/pics/WiFi_AP.jpg -------------------------------------------------------------------------------- /pics/ConfigPortal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/pics/ConfigPortal.png -------------------------------------------------------------------------------- /pics/Input_With_Scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/pics/Input_With_Scan.png -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/pics/Box1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/examples/Geiger_Counter_OLED/pics/Box1.jpg -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/pics/Box2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/examples/Geiger_Counter_OLED/pics/Box2.jpg -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/pics/Blynk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/examples/Geiger_Counter_OLED/pics/Blynk.jpg -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/pics/Schematics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/BlynkESP32_BT_WF/HEAD/examples/Geiger_Counter_OLED/pics/Schematics.jpg -------------------------------------------------------------------------------- /.github/workflows/auto-github-actions.yml: -------------------------------------------------------------------------------- 1 | name: auto-github-actions 2 | on: [push] 3 | jobs: 4 | check-bats-version: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - uses: actions/setup-node@v2 9 | with: 10 | node-version: '14' 11 | - run: npm install -g bats 12 | - run: bats -v 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Is your feature request related to a problem? Please describe. 11 | 12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 13 | 14 | ### Describe the solution you'd like 15 | 16 | A clear and concise description of what you want to happen. 17 | 18 | ### Describe alternatives you've considered 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | ### Additional context 22 | 23 | Add any other context or screenshots about the feature request here. 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Khoi Hoang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=BlynkESP32_BT_WF 2 | version=1.2.2 3 | author=Khoi Hoang 4 | license=MIT 5 | maintainer=Khoi Hoang 6 | 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 LittleFS, SPIFFS or EEPROM. 7 | paragraph=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. 8 | category=Communication 9 | url=https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | architectures=esp32 11 | depends=Blynk,ESP_DoubleResetDetector 12 | includes=BlynkSimpleESP32_WFM.h,BlynkSimpleESP32_WF.h,BlynkSimpleEsp32_BLE_WF.h,BlynkSimpleEsp32_BT_WF.h 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to BlynkESP32_BT_WF 2 | 3 | ### Reporting Bugs 4 | 5 | Please report bugs in BlynkESP32_BT_WF if you find them. 6 | 7 | However, before reporting a bug please check through the following: 8 | 9 | * [Existing Open Issues](https://github.com/khoih-prog/BlynkESP32_BT_WF/issues) - someone might have already encountered this. 10 | 11 | If you don't find anything, please [open a new issue](https://github.com/khoih-prog/BlynkESP32_BT_WF/issues/new). 12 | 13 | ### How to submit a bug report 14 | 15 | Please ensure to specify the following: 16 | 17 | * Arduino IDE version (e.g. 1.8.15) or Platform.io version 18 | * `ESP32` Core Version (e.g. ESP32 core v2.0.0) 19 | * Contextual information (e.g. what you were trying to achieve) 20 | * Simplest possible steps to reproduce 21 | * Anything that might be relevant in your opinion, such as: 22 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 23 | * Network configuration 24 | 25 | 26 | ### Example 27 | 28 | ``` 29 | Arduino IDE version: 1.8.16 30 | ESP32 Core Version 2.0.0 31 | OS: Ubuntu 20.04 LTS 32 | Linux xy-Inspiron-3593 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux 33 | 34 | Context: 35 | The board couldn't autoreconnect to Local Blynk Server after router power recycling. 36 | 37 | Steps to reproduce: 38 | 1. ... 39 | 2. ... 40 | 3. ... 41 | 4. ... 42 | ``` 43 | 44 | ### Sending Feature Requests 45 | 46 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 47 | 48 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/BlynkESP32_BT_WF/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 49 | 50 | ### Sending Pull Requests 51 | 52 | Pull Requests with changes and fixes are also welcome! 53 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the bug 11 | 12 | A clear and concise description of what the bug is. 13 | 14 | ### Steps to Reproduce 15 | 16 | Steps to reproduce the behavior. Including the [MRE](https://stackoverflow.com/help/minimal-reproducible-example) sketches 17 | 18 | ### Expected behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ### Actual behavior 23 | 24 | A clear and concise description of what you expected to happen. 25 | 26 | ### Debug and AT-command log (if applicable) 27 | 28 | A clear and concise description of what you expected to happen. 29 | 30 | ### Screenshots 31 | 32 | If applicable, add screenshots to help explain your problem. 33 | 34 | ### Information 35 | 36 | Please ensure to specify the following: 37 | 38 | * Arduino IDE version (e.g. 1.8.13) or Platform.io version 39 | * `ESP8266`,`ESP32` or `STM32` Core Version (e.g. ESP8266 core v2.7.4, ESP32 v1.0.5 or STM32 v1.9.0) 40 | * Contextual information (e.g. what you were trying to achieve) 41 | * Simplest possible steps to reproduce 42 | * Anything that might be relevant in your opinion, such as: 43 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 44 | * Network configuration 45 | 46 | ### Example 47 | 48 | ``` 49 | Arduino IDE version: 1.8.13 50 | ESP32 Core Version 1.0.5 51 | OS: Ubuntu 20.04 LTS 52 | Linux xy-Inspiron-3593 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux 53 | 54 | Context: 55 | I encountered an endless loop while trying to connect to Local WiFi. 56 | 57 | Steps to reproduce: 58 | 1. ... 59 | 2. ... 60 | 3. ... 61 | 4. ... 62 | ``` 63 | 64 | ### Additional context 65 | 66 | Add any other context about the problem here. 67 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BlynkESP32_BT_WF", 3 | "version": "1.2.2", 4 | "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 LittlFS, 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. Now with scanning of WiFi networks for selection in Configuration Portal.", 5 | "keywords": "sensors, control, device, communication, wifi, ble, bt-ble, bluetooth, drd, mrd, double-reset, multi-reset, multi-wifi, multi-blynk, littlefs, spiffs, eeprom, webserver, config-portal, credentials, protocol, iot, m2m, smartphone, mobile, app, web, cloud, ethernet, usb, serial, gsm, gprs, 3g, data, esp8266, http, portal", 6 | "authors": 7 | { 8 | "name": "Khoi Hoang", 9 | "url": "https://github.com/khoih-prog", 10 | "maintainer": true 11 | }, 12 | "repository": 13 | { 14 | "type": "git", 15 | "url": "https://github.com/khoih-prog/BlynkESP32_BT_WF" 16 | }, 17 | "homepage": "https://github.com/khoih-prog/BlynkESP32_BT_WF", 18 | "export": { 19 | "exclude": [ 20 | "linux", 21 | "extras", 22 | "tests" 23 | ] 24 | }, 25 | "dependencies": 26 | [ 27 | { 28 | "owner": "blynkkk", 29 | "name": "Blynk", 30 | "version": "^1.0.1", 31 | "platforms": ["espressif8266", "espressif32"] 32 | }, 33 | { 34 | "owner": "khoih-prog", 35 | "name": "ESP_DoubleResetDetector", 36 | "version": "^1.2.1", 37 | "platforms": ["espressif8266", "espressif32"] 38 | } 39 | ], 40 | "frameworks": "*", 41 | "platforms": "*", 42 | "examples": "examples/*/*/*.ino" 43 | } 44 | -------------------------------------------------------------------------------- /platformio/platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; ============================================================ 13 | ; chose environment: 14 | ; ESP32 15 | ; ============================================================ 16 | default_envs = ESP32 17 | 18 | [env] 19 | ; ============================================================ 20 | ; Serial configuration 21 | ; choose upload speed, serial-monitor speed 22 | ; ============================================================ 23 | upload_speed = 921600 24 | ;upload_port = COM11 25 | ;monitor_speed = 9600 26 | ;monitor_port = COM11 27 | 28 | ; Checks for the compatibility with frameworks and dev/platforms 29 | lib_compat_mode = strict 30 | 31 | lib_deps = 32 | ; PlatformIO 4.x 33 | Blynk@>=0.6.1 34 | ESP_DoubleResetDetector@>=1.1.1 35 | ; PlatformIO 5.x 36 | ; blynkkk/Blynk@>=0.6.1 37 | ; khoih-prog/ESP_DoubleResetDetector@>=1.1.1 38 | 39 | build_flags = 40 | ; set your debug output (default=Serial) 41 | -D DEBUG_ESP_PORT=Serial 42 | ; comment the folowing line to enable WiFi debugging 43 | -D NDEBUG 44 | 45 | [env:ESP32] 46 | platform = espressif32 47 | framework = arduino 48 | ; ============================================================ 49 | ; Board configuration 50 | ; choose your board by uncommenting one of the following lines 51 | ; ============================================================ 52 | ;board = esp32cam 53 | ;board = alksesp32 54 | ;board = featheresp32 55 | ;board = espea32 56 | ;board = bpi-bit 57 | ;board = d-duino-32 58 | board = esp32doit-devkit-v1 59 | ;board = pocket_32 60 | ;board = fm-devkit 61 | ;board = pico32 62 | ;board = esp32-evb 63 | ;board = esp32-gateway 64 | ;board = esp32-pro 65 | ;board = esp32-poe 66 | ;board = oroca_edubot 67 | ;board = onehorse32dev 68 | ;board = lopy 69 | ;board = lopy4 70 | ;board = wesp32 71 | ;board = esp32thing 72 | ;board = sparkfun_lora_gateway_1-channel 73 | ;board = ttgo-lora32-v1 74 | ;board = ttgo-t-beam 75 | ;board = turta_iot_node 76 | ;board = lolin_d32 77 | ;board = lolin_d32_pro 78 | ;board = lolin32 79 | ;board = wemosbat 80 | ;board = widora-air 81 | ;board = xinabox_cw02 82 | ;board = iotbusio 83 | ;board = iotbusproteus 84 | ;board = nina_w10 85 | -------------------------------------------------------------------------------- /examples/PET_Check/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/ESP32_BLE_WF/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/ESP32_BT_WF/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BLE/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BT/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_WF/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_BLE_WF/Credentials.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Credentials.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef Credentials_h 14 | #define Credentials_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | /// Start Default Config Data ////////////////// 19 | 20 | /* 21 | // Defined in 22 | 23 | #define SSID_MAX_LEN 32 24 | #define PASS_MAX_LEN 64 25 | 26 | typedef struct 27 | { 28 | char wifi_ssid[SSID_MAX_LEN]; 29 | char wifi_pw [PASS_MAX_LEN]; 30 | } WiFi_Credentials; 31 | 32 | #define BLYNK_SERVER_MAX_LEN 32 33 | #define BLYNK_TOKEN_MAX_LEN 36 34 | 35 | typedef struct 36 | { 37 | char blynk_server[BLYNK_SERVER_MAX_LEN]; 38 | char blynk_token [BLYNK_TOKEN_MAX_LEN]; 39 | } Blynk_Credentials; 40 | 41 | #define NUM_WIFI_CREDENTIALS 2 42 | #define NUM_BLYNK_CREDENTIALS 2 43 | 44 | typedef struct Configuration 45 | { 46 | char header [16]; 47 | WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; 48 | Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 49 | int blynk_port; 50 | char board_name [24]; 51 | int checkSum; 52 | } Blynk_WM_Configuration; 53 | 54 | */ 55 | 56 | //bool LOAD_DEFAULT_CONFIG_DATA = true; 57 | bool LOAD_DEFAULT_CONFIG_DATA = false; 58 | 59 | Blynk_WM_Configuration defaultConfig = 60 | { 61 | //char header[16], dummy, not used 62 | #if USE_SSL 63 | "SSL", 64 | #else 65 | "NonSSL", 66 | #endif 67 | //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] 68 | //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw 69 | "SSID1", "password1", 70 | "SSID2", "password2", 71 | // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; 72 | // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token 73 | "account.ddns.net", "token", 74 | "account.duckdns.org", "token1", 75 | //int blynk_port; 76 | #if USE_SSL 77 | 9443, 78 | #else 79 | 8080, 80 | #endif 81 | //char board_name [24]; 82 | "ESP32-BLE-WF", 83 | //int checkSum, dummy, not used 84 | 0 85 | }; 86 | 87 | /////////// End Default Config Data ///////////// 88 | 89 | #endif // #if USE_BLYNK_WM 90 | 91 | #endif //Credentials_h 92 | -------------------------------------------------------------------------------- /examples/PET_Check/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/ESP32_BLE_WF/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/ESP32_BT_WF/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BLE/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BT/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_WF/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_BLE_WF/dynamicParams.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | dynamicParams.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef dynamicParams_h 14 | #define dynamicParams_h 15 | 16 | #if USE_BLYNK_WM 17 | 18 | #if (USE_DYNAMIC_PARAMETERS) 19 | #warning USE_DYNAMIC_PARAMETERS 20 | #endif 21 | 22 | // USE_DYNAMIC_PARAMETERS defined in defined.h 23 | 24 | /////////////// Start dynamic Credentials /////////////// 25 | 26 | //Defined in 27 | /************************************** 28 | #define MAX_ID_LEN 5 29 | #define MAX_DISPLAY_NAME_LEN 16 30 | 31 | typedef struct 32 | { 33 | char id [MAX_ID_LEN + 1]; 34 | char displayName [MAX_DISPLAY_NAME_LEN + 1]; 35 | char *pdata; 36 | uint8_t maxlen; 37 | } MenuItem; 38 | **************************************/ 39 | 40 | #if USE_DYNAMIC_PARAMETERS 41 | 42 | #define MAX_MQTT_SERVER_LEN 34 43 | char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; 44 | 45 | #define MAX_MQTT_PORT_LEN 6 46 | char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; 47 | 48 | #define MAX_MQTT_USERNAME_LEN 34 49 | char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; 50 | 51 | #define MAX_MQTT_PW_LEN 34 52 | char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; 53 | 54 | #define MAX_MQTT_SUBS_TOPIC_LEN 34 55 | char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; 56 | 57 | #define MAX_MQTT_PUB_TOPIC_LEN 34 58 | char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; 59 | 60 | MenuItem myMenuItems [] = 61 | { 62 | { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, 63 | { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, 64 | { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, 65 | { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, 66 | { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, 67 | { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, 68 | }; 69 | 70 | uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; 71 | 72 | #else 73 | 74 | MenuItem myMenuItems [] = {}; 75 | 76 | uint16_t NUM_MENU_ITEMS = 0; 77 | #endif 78 | 79 | 80 | /////// // End dynamic Credentials /////////// 81 | 82 | #endif // USE_BLYNK_WM 83 | 84 | #endif //dynamicParams_h 85 | -------------------------------------------------------------------------------- /examples/ESP32_BT_WF/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BLE_ONLY true 53 | #define BLYNK_USE_BLE_ONLY false 54 | 55 | #include 56 | 57 | #define USE_BLYNK_WM true 58 | //#define USE_BLYNK_WM false 59 | 60 | #if !BLYNK_USE_BT_ONLY 61 | #if USE_BLYNK_WM 62 | #define USE_DYNAMIC_PARAMETERS true 63 | 64 | ///////////////////////////////////////////// 65 | 66 | #define REQUIRE_ONE_SET_SSID_PW false 67 | 68 | #define SCAN_WIFI_NETWORKS true 69 | 70 | // To be able to manually input SSID, not from a scanned SSID lists 71 | #define MANUAL_SSID_INPUT_ALLOWED true 72 | 73 | // From 2-15 74 | #define MAX_SSID_IN_LIST 8 75 | 76 | ///////////////////////////////////////////// 77 | 78 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 79 | #include 80 | #else 81 | #include 82 | 83 | String cloudBlynkServer = "account.duckdns.org"; 84 | //String cloudBlynkServer = "192.168.2.110"; 85 | #define BLYNK_SERVER_HARDWARE_PORT 8080 86 | char ssid[] = "SSID"; 87 | char pass[] = "PASS"; 88 | #endif 89 | #endif 90 | 91 | #if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM) 92 | // Blynk token shared between BLE and WiFi 93 | char auth[] = "****"; 94 | #endif 95 | 96 | #ifndef LED_BUILTIN 97 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 98 | #endif 99 | 100 | #define HOST_NAME "ESP32-BLE-WF" 101 | 102 | #endif //defines_h 103 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BT/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BT_ONLY true 53 | #define BLYNK_USE_BT_ONLY false 54 | 55 | #include 56 | 57 | #define USE_BLYNK_WM true 58 | //#define USE_BLYNK_WM false 59 | 60 | #if !BLYNK_USE_BT_ONLY 61 | #if USE_BLYNK_WM 62 | #define USE_DYNAMIC_PARAMETERS true 63 | 64 | ///////////////////////////////////////////// 65 | 66 | #define REQUIRE_ONE_SET_SSID_PW false 67 | 68 | #define SCAN_WIFI_NETWORKS true 69 | 70 | // To be able to manually input SSID, not from a scanned SSID lists 71 | #define MANUAL_SSID_INPUT_ALLOWED true 72 | 73 | // From 2-15 74 | #define MAX_SSID_IN_LIST 8 75 | 76 | ///////////////////////////////////////////// 77 | 78 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 79 | #include 80 | #else 81 | #include 82 | 83 | String cloudBlynkServer = "account.duckdns.org"; 84 | //String cloudBlynkServer = "192.168.2.110"; 85 | #define BLYNK_SERVER_HARDWARE_PORT 8080 86 | char ssid[] = "SSID"; 87 | char pass[] = "PASS"; 88 | #endif 89 | #endif 90 | 91 | #if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM) 92 | // Blynk token shared between BLE and WiFi 93 | char auth[] = "****"; 94 | #endif 95 | 96 | #ifndef LED_BUILTIN 97 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 98 | #endif 99 | 100 | #define HOST_NAME "ESP32-BLE-WF" 101 | 102 | #endif //defines_h 103 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BLE_ONLY true 53 | #define BLYNK_USE_BLE_ONLY false 54 | 55 | #include 56 | 57 | #define USE_BLYNK_WM true 58 | //#define USE_BLYNK_WM false 59 | 60 | #if !BLYNK_USE_BT_ONLY 61 | #if USE_BLYNK_WM 62 | #define USE_DYNAMIC_PARAMETERS true 63 | 64 | ///////////////////////////////////////////// 65 | 66 | #define REQUIRE_ONE_SET_SSID_PW false 67 | 68 | #define SCAN_WIFI_NETWORKS true 69 | 70 | // To be able to manually input SSID, not from a scanned SSID lists 71 | #define MANUAL_SSID_INPUT_ALLOWED true 72 | 73 | // From 2-15 74 | #define MAX_SSID_IN_LIST 8 75 | 76 | ///////////////////////////////////////////// 77 | 78 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 79 | #include 80 | #else 81 | #include 82 | 83 | String cloudBlynkServer = "account.duckdns.org"; 84 | //String cloudBlynkServer = "192.168.2.110"; 85 | #define BLYNK_SERVER_HARDWARE_PORT 8080 86 | char ssid[] = "SSID"; 87 | char pass[] = "PASS"; 88 | #endif 89 | #endif 90 | 91 | #if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM) 92 | // Blynk token shared between BLE and WiFi 93 | char auth[] = "****"; 94 | #endif 95 | 96 | #ifndef LED_BUILTIN 97 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 98 | #endif 99 | 100 | #define HOST_NAME "ESP32-BLE-WF" 101 | 102 | #endif //defines_h 103 | -------------------------------------------------------------------------------- /examples/PET_Check/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BLE_ONLY true 53 | #define BLYNK_USE_BLE_ONLY false 54 | 55 | #include 56 | #include 57 | #include 58 | #include "BLEScan.h" 59 | 60 | #define USE_BLYNK_WM true 61 | //#define USE_BLYNK_WM false 62 | 63 | #if USE_BLYNK_WM 64 | #define USE_DYNAMIC_PARAMETERS true 65 | 66 | ///////////////////////////////////////////// 67 | 68 | #define REQUIRE_ONE_SET_SSID_PW false 69 | 70 | #define SCAN_WIFI_NETWORKS true 71 | 72 | // To be able to manually input SSID, not from a scanned SSID lists 73 | #define MANUAL_SSID_INPUT_ALLOWED true 74 | 75 | // From 2-15 76 | #define MAX_SSID_IN_LIST 8 77 | 78 | ///////////////////////////////////////////// 79 | 80 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 81 | #include 82 | #else 83 | #include 84 | 85 | String cloudBlynkServer = "account.duckdns.org"; 86 | //String cloudBlynkServer = "192.168.2.110"; 87 | #define BLYNK_SERVER_HARDWARE_PORT 8080 88 | char ssid[] = "SSID"; 89 | char pass[] = "PASSPASS"; 90 | 91 | // Blynk token shared between BLE and WiFi 92 | char auth[] = "your-token"; 93 | 94 | #endif 95 | 96 | #ifndef LED_BUILTIN 97 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 98 | #endif 99 | 100 | // For ESP32 101 | #define LED_OFF LOW 102 | #define LED_ON HIGH 103 | 104 | #define HOST_NAME "ESP32-BLE-WF" 105 | 106 | #endif //defines_h 107 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BLE/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BLE_ONLY true 53 | #define BLYNK_USE_BLE_ONLY false 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | #define USE_BLYNK_WM true 60 | //#define USE_BLYNK_WM false 61 | 62 | #if !BLYNK_USE_BLE_ONLY 63 | #if USE_BLYNK_WM 64 | #define USE_DYNAMIC_PARAMETERS true 65 | 66 | ///////////////////////////////////////////// 67 | 68 | #define REQUIRE_ONE_SET_SSID_PW false 69 | 70 | #define SCAN_WIFI_NETWORKS true 71 | 72 | // To be able to manually input SSID, not from a scanned SSID lists 73 | #define MANUAL_SSID_INPUT_ALLOWED true 74 | 75 | // From 2-15 76 | #define MAX_SSID_IN_LIST 8 77 | 78 | ///////////////////////////////////////////// 79 | 80 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 81 | #include 82 | #else 83 | #include 84 | 85 | String cloudBlynkServer = "account.duckdns.org"; 86 | //String cloudBlynkServer = "192.168.2.110"; 87 | #define BLYNK_SERVER_HARDWARE_PORT 8080 88 | char ssid[] = "SSID"; 89 | char pass[] = "PASS"; 90 | #endif 91 | #endif 92 | 93 | #if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM) 94 | // Blynk token shared between BLE and WiFi 95 | char auth[] = "****"; 96 | #endif 97 | 98 | #ifndef LED_BUILTIN 99 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 100 | #endif 101 | 102 | #define HOST_NAME "ESP32-BLE-WF" 103 | 104 | #endif //defines_h 105 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_WF/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BLE_ONLY true 53 | #define BLYNK_USE_BLE_ONLY false 54 | 55 | #include 56 | 57 | #define USE_BLYNK_WM true 58 | //#define USE_BLYNK_WM false 59 | 60 | #if USE_BLYNK_WM 61 | #define USE_DYNAMIC_PARAMETERS true 62 | 63 | ///////////////////////////////////////////// 64 | 65 | #define REQUIRE_ONE_SET_SSID_PW false 66 | 67 | #define SCAN_WIFI_NETWORKS true 68 | 69 | // To be able to manually input SSID, not from a scanned SSID lists 70 | #define MANUAL_SSID_INPUT_ALLOWED true 71 | 72 | // From 2-15 73 | #define MAX_SSID_IN_LIST 8 74 | 75 | ///////////////////////////////////////////// 76 | 77 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 78 | #include 79 | #else 80 | #include 81 | 82 | String cloudBlynkServer = "account.duckdns.org"; 83 | //String cloudBlynkServer = "192.168.2.110"; 84 | #define BLYNK_SERVER_HARDWARE_PORT 8080 85 | char ssid[] = "SSID"; 86 | char pass[] = "PASS"; 87 | 88 | // WiFi Blynk token 89 | char WiFi_auth[] = "WF_token"; 90 | 91 | // BT Blynk token, not shared between BT and WiFi 92 | char BT_auth[] = "BT_token"; 93 | 94 | // BLE Blynk token, not shared between BT and WiFi 95 | char BLE_auth[] = "BLE_token"; 96 | #endif 97 | 98 | #ifndef LED_BUILTIN 99 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 100 | #endif 101 | 102 | #define HOST_NAME "ESP32-BLE-WF" 103 | 104 | #endif //defines_h 105 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_BLE_WF/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 3 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | // Force some params in Blynk, only valid for library version 1.0.1 and later 46 | #define TIMEOUT_RECONNECT_WIFI 10000L 47 | #define RESET_IF_CONFIG_TIMEOUT true 48 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 49 | 50 | // Those above #define's must be placed before #include 51 | 52 | //#define BLYNK_USE_BLE_ONLY true 53 | #define BLYNK_USE_BLE_ONLY false 54 | 55 | #include 56 | 57 | #define USE_BLYNK_WM true 58 | //#define USE_BLYNK_WM false 59 | 60 | #if USE_BLYNK_WM 61 | #define USE_DYNAMIC_PARAMETERS true 62 | 63 | ///////////////////////////////////////////// 64 | 65 | #define REQUIRE_ONE_SET_SSID_PW false 66 | 67 | #define SCAN_WIFI_NETWORKS true 68 | 69 | // To be able to manually input SSID, not from a scanned SSID lists 70 | #define MANUAL_SSID_INPUT_ALLOWED true 71 | 72 | // From 2-15 73 | #define MAX_SSID_IN_LIST 8 74 | 75 | ///////////////////////////////////////////// 76 | 77 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 78 | #include 79 | #else 80 | #include 81 | 82 | String cloudBlynkServer = "account.duckdns.org"; 83 | //String cloudBlynkServer = "192.168.2.110"; 84 | #define BLYNK_SERVER_HARDWARE_PORT 8080 85 | char ssid[] = "SSID"; 86 | char pass[] = "PASS"; 87 | 88 | // WiFi Blynk token 89 | char WiFi_auth[] = "WF_token"; 90 | 91 | // BT Blynk token, not shared between BT and WiFi 92 | char BT_auth[] = "BT_token"; 93 | 94 | // BLE Blynk token, not shared between BT and WiFi 95 | char BLE_auth[] = "BLE_token"; 96 | #endif 97 | 98 | #ifndef LED_BUILTIN 99 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 100 | #endif 101 | 102 | #define HOST_NAME "ESP32-BLE-WF" 103 | 104 | #endif //defines_h 105 | -------------------------------------------------------------------------------- /examples/ESP32_BLE_WF/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef defines_h 14 | #define defines_h 15 | 16 | #ifndef ESP32 17 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 18 | #endif 19 | 20 | #define BLYNK_PRINT Serial 21 | 22 | #define ESP32_BLE_WF_DEBUG true 23 | 24 | #define DOUBLERESETDETECTOR_DEBUG true 25 | #define BLYNK_WM_DEBUG 1 26 | 27 | // Not use #define USE_LITTLEFS and #define USE_SPIFFS => using SPIFFS for configuration data in WiFiManager 28 | // (USE_LITTLEFS == false) and (USE_SPIFFS == false) => using EEPROM for configuration data in WiFiManager 29 | // (USE_LITTLEFS == true) and (USE_SPIFFS == false) => using LITTLEFS for configuration data in WiFiManager 30 | // (USE_LITTLEFS == true) and (USE_SPIFFS == true) => using LITTLEFS for configuration data in WiFiManager 31 | // (USE_LITTLEFS == false) and (USE_SPIFFS == true) => using SPIFFS for configuration data in WiFiManager 32 | // Those above #define's must be placed before #include 33 | 34 | #define USE_LITTLEFS true 35 | #define USE_SPIFFS false 36 | 37 | 38 | #if !( USE_SPIFFS || USE_LITTLEFS) 39 | // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes) 40 | #define EEPROM_SIZE (2 * 1024) 41 | // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE 42 | #define EEPROM_START 0 43 | #endif 44 | 45 | ///////////////////////////////////////////// 46 | 47 | // Add customs headers from v1.2.0 48 | #define USING_CUSTOMS_STYLE true 49 | #define USING_CUSTOMS_HEAD_ELEMENT true 50 | #define USING_CORS_FEATURE true 51 | 52 | ///////////////////////////////////////////// 53 | 54 | // Force some params in Blynk, only valid for library version 1.0.1 and later 55 | #define TIMEOUT_RECONNECT_WIFI 10000L 56 | #define RESET_IF_CONFIG_TIMEOUT true 57 | #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 58 | 59 | // Those above #define's must be placed before #include 60 | 61 | //#define BLYNK_USE_BLE_ONLY true 62 | #define BLYNK_USE_BLE_ONLY false 63 | 64 | #include 65 | #include 66 | #include 67 | 68 | #define USE_BLYNK_WM true 69 | //#define USE_BLYNK_WM false 70 | 71 | #if !BLYNK_USE_BLE_ONLY 72 | #if USE_BLYNK_WM 73 | #define USE_DYNAMIC_PARAMETERS true 74 | 75 | ///////////////////////////////////////////// 76 | 77 | #define REQUIRE_ONE_SET_SSID_PW false 78 | 79 | #define SCAN_WIFI_NETWORKS true 80 | 81 | // To be able to manually input SSID, not from a scanned SSID lists 82 | #define MANUAL_SSID_INPUT_ALLOWED true 83 | 84 | // From 2-15 85 | #define MAX_SSID_IN_LIST 8 86 | 87 | ///////////////////////////////////////////// 88 | 89 | #warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP) 90 | #include 91 | #else 92 | #include 93 | 94 | String cloudBlynkServer = "account.duckdns.org"; 95 | //String cloudBlynkServer = "192.168.2.110"; 96 | #define BLYNK_SERVER_HARDWARE_PORT 8080 97 | char ssid[] = "SSID"; 98 | char pass[] = "PASS"; 99 | #endif 100 | #endif 101 | 102 | #if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM) 103 | // Blynk token shared between BLE and WiFi 104 | char auth[] = "****"; 105 | #endif 106 | 107 | #ifndef LED_BUILTIN 108 | #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED 109 | #endif 110 | 111 | #define HOST_NAME "ESP32-BLE-WF" 112 | 113 | #endif //defines_h 114 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Data types (KEYWORD1) 3 | ####################################### 4 | Blynk KEYWORD1 5 | BlynkTimer KEYWORD1 6 | WidgetBridge KEYWORD1 7 | WidgetLCD KEYWORD1 8 | WidgetLED KEYWORD1 9 | WidgetRTC KEYWORD1 10 | WidgetSD KEYWORD1 11 | WidgetTerminal KEYWORD1 12 | WidgetMap KEYWORD1 13 | WidgetTable KEYWORD1 14 | BlynkParam KEYWORD1 15 | BlynkParamAllocated KEYWORD1 16 | 17 | MenuItem KEYWORD1 18 | WiFi_Credentials KEYWORD1 19 | Blynk_Credentials KEYWORD1 20 | Blynk_WM_Configuration KEYWORD1 21 | 22 | ####################################### 23 | # Methods and Functions (KEYWORD2) 24 | ####################################### 25 | begin KEYWORD2 26 | config KEYWORD2 27 | run KEYWORD2 28 | connect KEYWORD2 29 | connected KEYWORD2 30 | tweet KEYWORD2 31 | notify KEYWORD2 32 | email KEYWORD2 33 | virtualWrite KEYWORD2 34 | virtualWriteBinary KEYWORD2 35 | syncAll KEYWORD2 36 | syncVirtual KEYWORD2 37 | setProperty KEYWORD2 38 | logEvent KEYWORD2 39 | loadConfigData KEYWORD2 40 | saveConfigData KEYWORD2 41 | getConfigData KEYWORD2 42 | connectToWifi KEYWORD2 43 | handleRequest KEYWORD2 44 | startConfigurationMode KEYWORD2 45 | setHostname KEYWORD2 46 | setConfigPortalIP KEYWORD2 47 | setConfigPortal KEYWORD2 48 | setConfigPortalChannel KEYWORD2 49 | setSTAStaticIPConfig KEYWORD2 50 | getWiFiSSID KEYWORD2 51 | getWiFiPW KEYWORD2 52 | getServerName KEYWORD2 53 | getToken KEYWORD2 54 | getBlynkBTToken KEYWORD2 55 | getBlynkBLEToken KEYWORD2 56 | getBoardName KEYWORD2 57 | getHWPort KEYWORD2 58 | getFullConfigData KEYWORD2 59 | clearConfigData KEYWORD2 60 | resetAndEnterConfigPortal KEYWORD2 61 | resetAndEnterConfigPortalPersistent KEYWORD2 62 | 63 | ################# 64 | # Handler helpers 65 | ################# 66 | 67 | BLYNK_READ KEYWORD2 68 | BLYNK_WRITE KEYWORD2 69 | BLYNK_READ_DEFAULT KEYWORD2 70 | BLYNK_WRITE_DEFAULT KEYWORD2 71 | BLYNK_ATTACH_WIDGET KEYWORD2 72 | BLYNK_CONNECTED KEYWORD2 73 | #BLYNK_DISCONNECTED KEYWORD2 74 | BLYNK_APP_CONNECTED KEYWORD2 75 | BLYNK_APP_DISCONNECTED KEYWORD2 76 | 77 | BLYNK_OUTPUT KEYWORD2 78 | BLYNK_INPUT KEYWORD2 79 | BLYNK_OUTPUT_DEFAULT KEYWORD2 80 | BLYNK_INPUT_DEFAULT KEYWORD2 81 | 82 | #################### 83 | # Variables binding 84 | #################### 85 | 86 | BLYNK_VAR_INT KEYWORD2 87 | BLYNK_VAR_LONG KEYWORD2 88 | BLYNK_VAR_DOUBLE KEYWORD2 89 | BLYNK_VAR_STRING KEYWORD2 90 | 91 | ################# 92 | # Special defines 93 | ################# 94 | 95 | BLYNK_DEBUG KEYWORD2 96 | BLYNK_DEBUG_ALL KEYWORD2 97 | BLYNK_PRINT KEYWORD2 98 | 99 | BLYNK_HEARTBEAT KEYWORD2 100 | BLYNK_EXPERIMENTAL KEYWORD2 101 | BLYNK_NO_BUILTIN KEYWORD2 102 | BLYNK_NO_FLOAT KEYWORD2 103 | BLYNK_NO_FANCY_LOGO KEYWORD2 104 | BLYNK_FANCY_LOGO_3D KEYWORD2 105 | BLYNK_USE_DIRECT_CONNECT KEYWORD2 106 | BLYNK_MAX_SENDBYTES KEYWORD2 107 | BLYNK_MAX_READBYTES KEYWORD2 108 | 109 | ################### 110 | # Periodic actions 111 | ################### 112 | 113 | #BLYNK_EVERY_N_MILLIS KEYWORD2 114 | #BLYNK_EVERY_N_SECONDS KEYWORD2 115 | #BLYNK_EVERY_N_MINUTES KEYWORD2 116 | #BLYNK_EVERY_N_HOURS KEYWORD2 117 | 118 | ####################################### 119 | # Literals (LITERAL1) 120 | ####################################### 121 | 122 | # Virtual pins 123 | V0 LITERAL1 124 | V1 LITERAL1 125 | V2 LITERAL1 126 | V3 LITERAL1 127 | V4 LITERAL1 128 | V5 LITERAL1 129 | V6 LITERAL1 130 | V7 LITERAL1 131 | V8 LITERAL1 132 | V9 LITERAL1 133 | V10 LITERAL1 134 | V11 LITERAL1 135 | V12 LITERAL1 136 | V13 LITERAL1 137 | V14 LITERAL1 138 | V15 LITERAL1 139 | V16 LITERAL1 140 | V17 LITERAL1 141 | V18 LITERAL1 142 | V19 LITERAL1 143 | V20 LITERAL1 144 | V21 LITERAL1 145 | V22 LITERAL1 146 | V23 LITERAL1 147 | V24 LITERAL1 148 | V25 LITERAL1 149 | V26 LITERAL1 150 | V27 LITERAL1 151 | V28 LITERAL1 152 | V29 LITERAL1 153 | V30 LITERAL1 154 | V31 LITERAL1 155 | V32 LITERAL1 156 | V33 LITERAL1 157 | V34 LITERAL1 158 | V35 LITERAL1 159 | V36 LITERAL1 160 | V37 LITERAL1 161 | V38 LITERAL1 162 | V39 LITERAL1 163 | V40 LITERAL1 164 | V41 LITERAL1 165 | V42 LITERAL1 166 | V43 LITERAL1 167 | V44 LITERAL1 168 | V45 LITERAL1 169 | V46 LITERAL1 170 | V47 LITERAL1 171 | V48 LITERAL1 172 | V49 LITERAL1 173 | V50 LITERAL1 174 | V51 LITERAL1 175 | V52 LITERAL1 176 | V53 LITERAL1 177 | V54 LITERAL1 178 | V55 LITERAL1 179 | V56 LITERAL1 180 | V57 LITERAL1 181 | V58 LITERAL1 182 | V59 LITERAL1 183 | V60 LITERAL1 184 | V61 LITERAL1 185 | V62 LITERAL1 186 | V63 LITERAL1 187 | V64 LITERAL1 188 | V65 LITERAL1 189 | V66 LITERAL1 190 | V67 LITERAL1 191 | V68 LITERAL1 192 | V69 LITERAL1 193 | V70 LITERAL1 194 | V71 LITERAL1 195 | V72 LITERAL1 196 | V73 LITERAL1 197 | V74 LITERAL1 198 | V75 LITERAL1 199 | V76 LITERAL1 200 | V77 LITERAL1 201 | V78 LITERAL1 202 | V79 LITERAL1 203 | V80 LITERAL1 204 | V81 LITERAL1 205 | V82 LITERAL1 206 | V83 LITERAL1 207 | V84 LITERAL1 208 | V85 LITERAL1 209 | V86 LITERAL1 210 | V87 LITERAL1 211 | V88 LITERAL1 212 | V89 LITERAL1 213 | V90 LITERAL1 214 | V91 LITERAL1 215 | V92 LITERAL1 216 | V93 LITERAL1 217 | V94 LITERAL1 218 | V95 LITERAL1 219 | V96 LITERAL1 220 | V97 LITERAL1 221 | V98 LITERAL1 222 | V99 LITERAL1 223 | V100 LITERAL1 224 | V101 LITERAL1 225 | V102 LITERAL1 226 | V103 LITERAL1 227 | V104 LITERAL1 228 | V105 LITERAL1 229 | V106 LITERAL1 230 | V107 LITERAL1 231 | V108 LITERAL1 232 | V109 LITERAL1 233 | V110 LITERAL1 234 | V111 LITERAL1 235 | V112 LITERAL1 236 | V113 LITERAL1 237 | V114 LITERAL1 238 | V115 LITERAL1 239 | V116 LITERAL1 240 | V117 LITERAL1 241 | V118 LITERAL1 242 | V119 LITERAL1 243 | V120 LITERAL1 244 | V121 LITERAL1 245 | V122 LITERAL1 246 | V123 LITERAL1 247 | V124 LITERAL1 248 | V125 LITERAL1 249 | V126 LITERAL1 250 | V127 LITERAL1 251 | -------------------------------------------------------------------------------- /src/BlynkSimpleEsp32_WF.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BlynkSimpleESP32_WF.h 3 | For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | 12 | Original Blynk Library author: 13 | @file BlynkSimpleESP32.h 14 | @author Volodymyr Shymanskyy 15 | @license This project is released under the MIT License (MIT) 16 | @copyright Copyright (c) 2015 Volodymyr Shymanskyy 17 | @date Oct 2016 18 | @brief 19 | 20 | Version: 1.2.2 21 | 22 | Version Modified By Date Comments 23 | ------- ----------- ---------- ----------- 24 | 1.0.0 K Hoang 25/01/2020 Initial coding 25 | 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi 26 | 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library 27 | 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() 28 | 1.0.4 K Hoang 14/03/2020 Enhance GUI. Reduce code size. 29 | 1.0.5 K Hoang 18/04/2020 MultiWiFi/Blynk. Dynamic custom parameters. SSID password maxlen is 63 now. 30 | Permit special chars # and % in input data. 31 | 1.0.6 K Hoang 24/08/2020 Add Configurable Config Portal Title, Add USE_DEFAULT_CONFIG_DATA and DRD. 32 | Auto format SPIFFS. Update examples. 33 | 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples 34 | 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches 35 | Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP 36 | 1.2.0 K Hoang 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal and many new features. 37 | 1.2.1 K Hoang 13/08/2021 Add auto-reconnect feature for BLE 38 | 1.2.2 K Hoang 13/08/2021 Update `platform.ini` and `library.json` 39 | *****************************************************************************************************************************/ 40 | 41 | #pragma once 42 | 43 | #ifndef BlynkSimpleEsp32_WF_h 44 | #define BlynkSimpleEsp32_WF_h 45 | 46 | #if !( defined(ESP32) ) 47 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 48 | #elif ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_ESP32S2_THING_PLUS || ARDUINO_MICROS2 || \ 49 | ARDUINO_METRO_ESP32S2 || ARDUINO_MAGTAG29_ESP32S2 || ARDUINO_FUNHOUSE_ESP32S2 || \ 50 | ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM ) 51 | #define BOARD_TYPE "ESP32-S2" 52 | #error ESP32-S2 is not supported yet. Please check later. 53 | #elif ( ARDUINO_ESP32C3_DEV ) 54 | #define BOARD_TYPE "ESP32-C3" 55 | #error ESP32-C3 is not supported yet. Please check later. 56 | #else 57 | #define BOARD_TYPE "ESP32" 58 | #endif 59 | 60 | #if !defined(BLYNK_ESP32_BT_WF_VERSION) 61 | #define BLYNK_ESP32_BT_WF_VERSION "BlynkESP32_BT_WF v1.2.2" 62 | #endif 63 | 64 | #define BLYNK_SEND_ATOMIC 65 | 66 | // KH 67 | #define BLYNK_TIMEOUT_MS 30000UL 68 | 69 | #include 70 | #include 71 | #include 72 | #include 73 | 74 | class BlynkWifi 75 | : public BlynkProtocol 76 | { 77 | typedef BlynkProtocol Base; 78 | public: 79 | BlynkWifi(BlynkArduinoClient& transp) 80 | : Base(transp) 81 | {} 82 | 83 | void connectWiFi(const char* ssid, const char* pass) 84 | { 85 | BLYNK_LOG2(BLYNK_F("Con2:"), ssid); 86 | WiFi.mode(WIFI_STA); 87 | if (pass && strlen(pass)) { 88 | WiFi.begin(ssid, pass); 89 | } else { 90 | WiFi.begin(ssid); 91 | } 92 | while (WiFi.status() != WL_CONNECTED) { 93 | BlynkDelay(500); 94 | } 95 | BLYNK_LOG1(BLYNK_F("Con2WiFi")); 96 | 97 | IPAddress myip = WiFi.localIP(); 98 | BLYNK_LOG_IP("IP:", myip); 99 | } 100 | 101 | void config(const char* auth, 102 | const char* domain = BLYNK_DEFAULT_DOMAIN, 103 | uint16_t port = BLYNK_DEFAULT_PORT) 104 | { 105 | Base::begin(auth); 106 | this->conn.begin(domain, port); 107 | } 108 | 109 | void config(const char* auth, 110 | IPAddress ip, 111 | uint16_t port = BLYNK_DEFAULT_PORT) 112 | { 113 | Base::begin(auth); 114 | this->conn.begin(ip, port); 115 | } 116 | 117 | void begin(const char* auth, 118 | const char* ssid, 119 | const char* pass, 120 | const char* domain = BLYNK_DEFAULT_DOMAIN, 121 | uint16_t port = BLYNK_DEFAULT_PORT) 122 | { 123 | connectWiFi(ssid, pass); 124 | config(auth, domain, port); 125 | while (this->connect() != true) {} 126 | } 127 | 128 | void begin(const char* auth, 129 | const char* ssid, 130 | const char* pass, 131 | IPAddress ip, 132 | uint16_t port = BLYNK_DEFAULT_PORT) 133 | { 134 | connectWiFi(ssid, pass); 135 | config(auth, ip, port); 136 | while (this->connect() != true) {} 137 | } 138 | 139 | }; 140 | 141 | static WiFiClient _blynkWifiClient; 142 | static BlynkArduinoClient _blynkTransport(_blynkWifiClient); 143 | 144 | // KH 145 | BlynkWifi Blynk_WF(_blynkTransport); 146 | 147 | #if defined(Blynk) 148 | #undef Blynk 149 | #define Blynk Blynk_WF 150 | #endif 151 | // 152 | 153 | #include 154 | 155 | #endif 156 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | ## BlynkESP32_BT_WF 2 | 3 | [![arduino-library-badge](https://www.ardu-badge.com/badge/BlynkESP32_BT_WF.svg?)](https://www.ardu-badge.com/BlynkESP32_BT_WF) 4 | [![GitHub release](https://img.shields.io/github/release/khoih-prog/BlynkESP32_BT_WF.svg)](https://github.com/khoih-prog/BlynkESP32_BT_WF/releases) 5 | [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/BlynkESP32_BT_WF/blob/master/LICENSE) 6 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) 7 | [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/BlynkESP32_BT_WF.svg)](http://github.com/khoih-prog/BlynkESP32_BT_WF/issues) 8 | 9 | --- 10 | --- 11 | 12 | ## Table of Contents 13 | 14 | * [Changelog](#changelog) 15 | * [Releases v1.2.2](#releases-v122) 16 | * [Releases v1.2.1](#releases-v121) 17 | * [Major Releases v1.2.0](#major-releases-v120) 18 | * [Releases v1.1.1](#releases-v111) 19 | * [Major Releases v1.1.0](#major-releases-v110) 20 | * [Major Releases v1.0.6](#major-releases-v106) 21 | * [Major Releases v1.0.5](#major-releases-v105) 22 | * [Releases v1.0.4](#releases-v104) 23 | * [Releases v1.0.3](#releases-v103) 24 | * [Releases v1.0.2](#releases-v102) 25 | * [Releases v1.0.1](#releases-v101) 26 | * [Releases v1.0.0](#releases-v100) 27 | 28 | --- 29 | --- 30 | 31 | ## Changelog 32 | 33 | ### Releases v1.2.2 34 | 35 | 1. Update `platform.ini` and `library.json` to use original `khoih-prog` instead of `khoih.prog` after PIO fix 36 | 37 | 38 | ### Releases v1.2.1 39 | 40 | 1. Add auto-reconnect feature for BLE. Check [Handle BLE disconnects #2](https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF/issues/2) 41 | 42 | ### Major Releases v1.2.0 43 | 44 | 1. Enable scan of WiFi networks for selection in Configuration Portal. Check [PR for v1.3.0 - Enable scan of WiFi networks #10](https://github.com/khoih-prog/WiFiManager_NINA_Lite/pull/10). Now you can select optional **SCAN_WIFI_NETWORKS**, **MANUAL_SSID_INPUT_ALLOWED** to be able to manually input SSID, not only from a scanned SSID lists and **MAX_SSID_IN_LIST** (from 2-15) 45 | 2. Fix invalid "blank" Config Data treated as Valid. 46 | 3. Permit optionally inputting one set of WiFi SSID/PWD by using `REQUIRE_ONE_SET_SSID_PW == true` 47 | 4. Enforce WiFi PWD minimum length of 8 chars 48 | 5. Minor enhancement to not display garbage when data is invalid 49 | 6. Fix issue of custom Blynk port (different from 8080 or 9443) not working on ESP32. Check [Custom Blynk port not working for BlynkSimpleEsp32_Async_WM.h #4](https://github.com/khoih-prog/Blynk_Async_WM/issues/4) 50 | 7. To permit auto-reset 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) 51 | 8. Fix rare Config Portal bug not updating Config and dynamic Params data successfully in very noisy or weak WiFi situation 52 | 9. Tested with [**Latest ESP32 Core 1.0.6**](https://github.com/espressif/arduino-esp32) for ESP32-based boards. 53 | 10. Update examples 54 | 55 | ### Releases v1.1.1 56 | 57 | 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) 58 | 2. Fix rare Config Portal bug not updating Config and dynamic Params data successfully in very noisy or weak WiFi situation 59 | 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) 60 | 61 | ### Major Releases v1.1.0 62 | 63 | 1. Add support to LittleFS for ESP32 using [LITTLEFS](https://github.com/lorol/LITTLEFS) Library 64 | 2. Clean-up all compiler warnings possible. 65 | 3. Add Table of Contents 66 | 4. Add Version String 67 | 68 | ### Major Releases v1.0.6 69 | 70 | 1. Add Configurable **Config Portal Title** to be either HostName, BoardName or default undistinguishable names. 71 | 2. Add optional default **Credentials as well as Dynamic parameters to be optionally autoloaded into Config Portal** to use or change instead of manually input using USE_DEFAULT_CONFIG_DATA. 72 | 3. Add **DoubleDetectDetector** feature to force Config Portal when double reset is detected within predetermined time, default 10s. 73 | 4. Auto format SPIFFS for first time usage. 74 | 5. Examples are redesigned to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device. 75 | 76 | 77 | #### Major Releases v1.0.5 78 | 79 | 1. **Multiple WiFi Credentials (SSID, Password)** and system will autoconnect to the best and available WiFi SSID. 80 | 2. **Multiple Blynk Credentials (Server, Token)** and system will autoconnect to the available Blynk Servers. 81 | 3. New **powerful-yet-simple-to-use feature to enable adding dynamic custom parameters** from sketch and input using the same Config Portal. Config Portal will be auto-adjusted to match the number of dynamic parameters. 82 | 4. Dynamic custom parameters to be saved **automatically in EEPROM, or SPIFFS**. 83 | 5. WiFi Password max length increased to 63 from 31, according to WPA2 standard. 84 | 6. Permit to input special chars such as **%** and **#** into data fields. 85 | 7. Config Portal AP Channel is configurable (either static or random channel) to avoid channel conflict to other APs. 86 | 87 | #### Releases v1.0.4 88 | 89 | 1. Enhance Config Portal GUI. 90 | 2. Reduce code size. 91 | 92 | #### Releases v1.0.3 93 | 94 | 1. Add checksum for config data integrity. 95 | 2. Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary 96 | 97 | #### Releases v1.0.2 98 | 99 | This new version enables user to eliminate `hardcoding` your Wifi and Blynk credentials, thanks to the `Smart Config Portal`, and have Credentials (WiFi SID/PW, Blynk WiFi/BT/BLE Tokens/ Hardware Port) saved in either SPIFFS or EEPROM. 100 | See more info at [Blynk_WM](https://github.com/khoih-prog/Blynk_WM) 101 | 102 | #### Releases v1.0.1 103 | 104 | This new version 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 by pressing a switch. 105 | 106 | #### Releases v1.0.0 107 | 108 | The Blynk ESP32 libraries for BlueTooth, BLE and WiFi, by design, can't coexist. So that when we'd like to use either WiFi or BlueTooth / BLE, it's not possible within the same sketch. 109 | With this libraries modifications, we now can compile with both options, then select one (WiFi or BT/BLE) to run at run-time by pressing a switch. 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/BlynkSimpleEsp32_BLE_WF.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BlynkSimpleEsp32_BLE_WF.h 3 | For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | 12 | Original Blynk Library author: 13 | @file BlynkSimpleESP32.h 14 | @author Volodymyr Shymanskyy 15 | @license This project is released under the MIT License (MIT) 16 | @copyright Copyright (c) 2015 Volodymyr Shymanskyy 17 | @date Oct 2016 18 | @brief 19 | 20 | Version: 1.2.2 21 | 22 | Version Modified By Date Comments 23 | ------- ----------- ---------- ----------- 24 | 1.0.0 K Hoang 25/01/2020 Initial coding 25 | 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi 26 | 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library 27 | 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() 28 | 1.0.4 K Hoang 14/03/2020 Enhance GUI. Reduce code size. 29 | 1.0.5 K Hoang 18/04/2020 MultiWiFi/Blynk. Dynamic custom parameters. SSID password maxlen is 63 now. 30 | Permit special chars # and % in input data. 31 | 1.0.6 K Hoang 24/08/2020 Add Configurable Config Portal Title, Add USE_DEFAULT_CONFIG_DATA and DRD. 32 | Auto format SPIFFS. Update examples. 33 | 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples 34 | 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches 35 | Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP 36 | 1.2.0 K Hoang 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal and many new features. 37 | 1.2.1 K Hoang 13/08/2021 Add auto-reconnect feature for BLE 38 | 1.2.2 K Hoang 13/08/2021 Update `platform.ini` and `library.json` 39 | *****************************************************************************************************************************/ 40 | 41 | #pragma once 42 | 43 | #ifndef BlynkSimpleEsp32_BLE_WF_h 44 | #define BlynkSimpleEsp32_BLE_WF_h 45 | 46 | #if !( defined(ESP32) ) 47 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 48 | #elif ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_ESP32S2_THING_PLUS || ARDUINO_MICROS2 || \ 49 | ARDUINO_METRO_ESP32S2 || ARDUINO_MAGTAG29_ESP32S2 || ARDUINO_FUNHOUSE_ESP32S2 || \ 50 | ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM ) 51 | #define BOARD_TYPE "ESP32-S2" 52 | #error ESP32-S2 is not supported yet. Please check later. 53 | #elif ( ARDUINO_ESP32C3_DEV ) 54 | #define BOARD_TYPE "ESP32-C3" 55 | #error ESP32-C3 is not supported yet. Please check later. 56 | #else 57 | #define BOARD_TYPE "ESP32" 58 | #endif 59 | 60 | #if !defined(BLYNK_ESP32_BT_WF_VERSION) 61 | #define BLYNK_ESP32_BT_WF_VERSION "BlynkESP32_BT_WF v1.2.2" 62 | #endif 63 | 64 | #ifndef BLYNK_INFO_CONNECTION 65 | #define BLYNK_INFO_CONNECTION "Esp32_BLE" 66 | #endif 67 | 68 | #define BLYNK_SEND_ATOMIC 69 | #define BLYNK_SEND_CHUNK 20 70 | //#define BLYNK_SEND_THROTTLE 20 71 | 72 | // KH 73 | #define BLYNK_TIMEOUT_MS 30000UL 74 | 75 | #include 76 | #include 77 | #include 78 | 79 | #include 80 | #include 81 | #include 82 | #include 83 | 84 | #define SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" 85 | #define CHARACTERISTIC_UUID_RX "713D0003-503E-4C75-BA94-3148F18D941E" 86 | #define CHARACTERISTIC_UUID_TX "713D0002-503E-4C75-BA94-3148F18D941E" 87 | 88 | class BlynkTransportEsp32_BLE : 89 | public BLEServerCallbacks, 90 | public BLECharacteristicCallbacks 91 | { 92 | 93 | public: 94 | BlynkTransportEsp32_BLE() 95 | : mConn (false) 96 | , mName ("Blynk") 97 | {} 98 | 99 | void setDeviceName(const char* name) { 100 | mName = name; 101 | } 102 | 103 | // IP redirect not available 104 | void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {} 105 | 106 | void begin() { 107 | // Create the BLE Device 108 | BLEDevice::init(mName); 109 | 110 | // Create the BLE Server 111 | pServer = BLEDevice::createServer(); 112 | pServer->setCallbacks(this); 113 | 114 | // Create the BLE Service 115 | pService = pServer->createService(SERVICE_UUID); 116 | 117 | // Create a BLE Characteristic 118 | pCharacteristicTX = pService->createCharacteristic( 119 | CHARACTERISTIC_UUID_TX, 120 | BLECharacteristic::PROPERTY_NOTIFY 121 | ); 122 | 123 | pCharacteristicTX->addDescriptor(new BLE2902()); 124 | 125 | pCharacteristicRX = pService->createCharacteristic( 126 | CHARACTERISTIC_UUID_RX, 127 | BLECharacteristic::PROPERTY_WRITE 128 | ); 129 | 130 | pCharacteristicRX->setCallbacks(this); 131 | 132 | // Start the service 133 | pService->start(); 134 | 135 | // Start advertising 136 | pServer->getAdvertising()->addServiceUUID(pService->getUUID()); 137 | pServer->getAdvertising()->start(); 138 | } 139 | 140 | bool connect() { 141 | mBuffRX.clear(); 142 | return mConn = true; 143 | } 144 | 145 | void disconnect() { 146 | mConn = false; 147 | } 148 | 149 | bool connected() { 150 | return mConn; 151 | } 152 | 153 | size_t read(void* buf, size_t len) { 154 | millis_time_t start = BlynkMillis(); 155 | while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) { 156 | if (available() < len) { 157 | delay(1); 158 | } else { 159 | break; 160 | } 161 | } 162 | size_t res = mBuffRX.get((uint8_t*)buf, len); 163 | return res; 164 | } 165 | 166 | size_t write(const void* buf, size_t len) { 167 | pCharacteristicTX->setValue((uint8_t*)buf, len); 168 | pCharacteristicTX->notify(); 169 | return len; 170 | } 171 | 172 | size_t available() { 173 | size_t rxSize = mBuffRX.size(); 174 | return rxSize; 175 | } 176 | 177 | private: 178 | 179 | void onConnect(BLEServer* pServer); 180 | void onDisconnect(BLEServer* pServer); 181 | 182 | void onWrite(BLECharacteristic *pCharacteristic) { 183 | std::string rxValue = pCharacteristic->getValue(); 184 | 185 | if (rxValue.length() > 0) { 186 | uint8_t* data = (uint8_t*)rxValue.data(); 187 | size_t len = rxValue.length(); 188 | 189 | BLYNK_DBG_DUMP(">> ", data, len); 190 | mBuffRX.put(data, len); 191 | } 192 | } 193 | 194 | private: 195 | bool mConn; 196 | const char* mName; 197 | 198 | BLEServer *pServer; 199 | BLEService *pService; 200 | BLECharacteristic *pCharacteristicTX; 201 | BLECharacteristic *pCharacteristicRX; 202 | 203 | BlynkFifo mBuffRX; 204 | }; 205 | 206 | class BlynkEsp32_BLE 207 | : public BlynkProtocol 208 | { 209 | typedef BlynkProtocol Base; 210 | public: 211 | BlynkEsp32_BLE(BlynkTransportEsp32_BLE& transp) 212 | : Base(transp) 213 | 214 | {} 215 | 216 | void begin(const char* auth) 217 | { 218 | Base::begin(auth); 219 | state = DISCONNECTED; 220 | conn.begin(); 221 | } 222 | 223 | void setDeviceName(const char* name) { 224 | conn.setDeviceName(name); 225 | } 226 | 227 | }; 228 | 229 | 230 | static BlynkTransportEsp32_BLE _blynkTransportBLE; 231 | 232 | // KH 233 | BlynkEsp32_BLE Blynk_BLE(_blynkTransportBLE); 234 | 235 | #define Blynk Blynk_BLE 236 | 237 | inline 238 | void BlynkTransportEsp32_BLE::onConnect(BLEServer* pServer) { 239 | BLYNK_LOG1(BLYNK_F("BLECon")); 240 | connect(); 241 | Blynk_BLE.startSession(); 242 | }; 243 | 244 | inline 245 | void BlynkTransportEsp32_BLE::onDisconnect(BLEServer* pServer) { 246 | BLYNK_LOG1(BLYNK_F("BLEDisCon")); 247 | Blynk_BLE.disconnect(); 248 | disconnect(); 249 | 250 | // Start advertising 251 | pServer->getAdvertising()->start(); 252 | } 253 | // 254 | 255 | 256 | #include 257 | 258 | #endif 259 | -------------------------------------------------------------------------------- /examples/PET_Check/PET_Check.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PET_Check.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Example Created by Miguel Alexandre Wisintainer 14 | See https://nina-b302-scanner-presenca.blogspot.com/2020/06/nina-w102-ble-detector-presenca-de-pet.html 15 | Date: 06/06/2020 16 | 17 | Important Notes: 18 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 19 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 20 | 3) To conmpile, use Partition Scheem with large APP size, such as 21 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 22 | b) No OTA (2MB APP, 2MB SPIFFS) 23 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 24 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 25 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 26 | *****************************************************************************************************************************/ 27 | 28 | #include "defines.h" 29 | #include "Credentials.h" 30 | #include "dynamicParams.h" 31 | 32 | bool USE_BLE = true; 33 | long timePreviousMeassure = 0; 34 | 35 | #define WIFI_BLE_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 36 | 37 | BlynkTimer timer; 38 | 39 | #include 40 | Ticker led_ticker; 41 | 42 | int NEAR_PET = 0; 43 | 44 | #define BLYNK_PIN_FORCED_CONFIG V10 45 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 46 | 47 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 48 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 49 | { 50 | if (param.asInt()) 51 | { 52 | Serial.println( F("\nCP Button Hit. Rebooting") ); 53 | 54 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 55 | Blynk.resetAndEnterConfigPortal(); 56 | } 57 | } 58 | 59 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 60 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 61 | { 62 | if (param.asInt()) 63 | { 64 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 65 | 66 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 67 | Blynk.resetAndEnterConfigPortalPersistent(); 68 | } 69 | } 70 | 71 | void set_led(byte status) 72 | { 73 | digitalWrite(LED_BUILTIN , status); 74 | } 75 | 76 | void noticeAlive(void) 77 | { 78 | if (USE_BLE) 79 | Blynk_BLE.virtualWrite(V0, F("OK")); 80 | else 81 | Blynk_WF.virtualWrite(V0, F("OK")); 82 | 83 | if (NEAR_PET == 0) //NOT FOUND PET ON SCAN!!!!! ALERT THE BLYNK 84 | Blynk_WF.notify("Hi, i cant find the PET!!!!"); 85 | 86 | NEAR_PET = 0; //SCAN AGAIN 87 | } 88 | 89 | void heartBeatPrint(void) 90 | { 91 | static int num = 1; 92 | 93 | if (Blynk.connected()) 94 | { 95 | set_led(HIGH); 96 | led_ticker.once_ms(111, set_led, (byte) LOW); 97 | Serial.print(F("B")); 98 | } 99 | else 100 | { 101 | Serial.print(F("F")); 102 | } 103 | 104 | if (num == 80) 105 | { 106 | Serial.println(); 107 | num = 1; 108 | } 109 | else if (num++ % 10 == 0) 110 | { 111 | Serial.print(F(" ")); 112 | } 113 | } 114 | 115 | void checkStatus() 116 | { 117 | static unsigned long checkstatus_timeout = 0; 118 | 119 | #define STATUS_CHECK_INTERVAL 60000L 120 | 121 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 122 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 123 | { 124 | if (!USE_BLE) 125 | { 126 | // report Blynk connection 127 | heartBeatPrint(); 128 | } 129 | 130 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 131 | } 132 | } 133 | 134 | char BLE_Device_Name[] = "PET-Check-BLE"; 135 | 136 | int scanTime = 5; //In seconds 137 | BLEScan* pBLEScan; 138 | 139 | char BLE_Manufacturer_Data[] = "4c000215fda50693a4e24fb1afcfc6eb07647825271b271bc9"; 140 | 141 | class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks 142 | { 143 | void onResult(BLEAdvertisedDevice advertisedDevice) 144 | { 145 | char* manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice.getManufacturerData().data(), advertisedDevice.getManufacturerData().length()); 146 | Serial.println("Advertised Device: " + String(manufacturerdata)); 147 | 148 | if (strcmp(BLE_Manufacturer_Data, manufacturerdata) == 0) 149 | { 150 | NEAR_PET++; //just to identify that found the PET near! 151 | Serial.println(F("Found PET")); 152 | } 153 | } 154 | }; 155 | 156 | void checkPet(void) 157 | { 158 | BLEScanResults foundDevices = pBLEScan->start(scanTime, false); 159 | Serial.print(F("Devices found: ")); 160 | Serial.println(foundDevices.getCount()); 161 | Serial.println(F("Scan done!")); 162 | // delete results fromBLEScan buffer to release memory 163 | pBLEScan->clearResults(); 164 | } 165 | 166 | #if USING_CUSTOMS_STYLE 167 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 169 | #endif 170 | 171 | void setup() 172 | { 173 | Serial.begin(115200); 174 | while (!Serial); 175 | 176 | #if (USE_LITTLEFS) 177 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 178 | #elif (USE_SPIFFS) 179 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 180 | #else 181 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 182 | #endif 183 | 184 | #if USE_SSL 185 | Serial.print(F(" with SSL on ")); 186 | #else 187 | Serial.print(F(" without SSL on ")); 188 | #endif 189 | 190 | Serial.println(ARDUINO_BOARD); 191 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 192 | 193 | #if USE_BLYNK_WM 194 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 195 | #endif 196 | 197 | pinMode(WIFI_BLE_SELECTION_PIN, INPUT_PULLUP); 198 | 199 | pinMode(LED_BUILTIN, OUTPUT); 200 | 201 | if (digitalRead(WIFI_BLE_SELECTION_PIN) == HIGH) 202 | { 203 | USE_BLE = false; 204 | Serial.println(F("GPIO14 HIGH, Use WiFi")); 205 | #if USE_BLYNK_WM 206 | #if ESP32_BLE_WF_DEBUG 207 | Serial.println(F("USE_BLYNK_WM: Blynk_WF begin")); 208 | #endif 209 | // Set config portal channel, defalut = 1. Use 0 => random channel from 1-13 to avoid conflict 210 | Blynk_WF.setConfigPortalChannel(0); 211 | 212 | ////////////////////////////////////////////// 213 | 214 | #if USING_CUSTOMS_STYLE 215 | Blynk.setCustomsStyle(NewCustomsStyle); 216 | #endif 217 | 218 | #if USING_CUSTOMS_HEAD_ELEMENT 219 | Blynk.setCustomsHeadElement(""); 220 | #endif 221 | 222 | #if USING_CORS_FEATURE 223 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 224 | #endif 225 | 226 | ////////////////////////////////////////////// 227 | 228 | Blynk_WF.begin(BLE_Device_Name); 229 | #else 230 | //Blynk_WF.begin(auth, ssid, pass); 231 | #if ESP32_BLE_WF_DEBUG 232 | Serial.println(F("Not USE_BLYNK_WM: Blynk_WF begin")); 233 | #endif 234 | Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 235 | #endif //USE_BLYNK_WM 236 | } 237 | else 238 | { 239 | USE_BLE = true; 240 | Serial.println(F("GPIO14 LOW, Use BLE")); 241 | Blynk_BLE.setDeviceName(BLE_Device_Name); 242 | #if USE_BLYNK_WM 243 | if (Blynk_WF.getBlynkBLEToken() == NO_CONFIG) 244 | { 245 | Serial.println(F("No valid stored BLE auth. Have to run WiFi then enter config portal")); 246 | USE_BLE = false; 247 | 248 | #if ESP32_BLE_WF_DEBUG 249 | Serial.println(F("USE_BLYNK_WM: No BLE Token. Blynk_WF begin")); 250 | #endif 251 | 252 | Blynk_WF.begin(BLE_Device_Name); 253 | } 254 | String BLE_auth = Blynk_WF.getBlynkBLEToken(); 255 | #else 256 | String BLE_auth = auth; 257 | #endif //USE_BLYNK_WM 258 | 259 | if (USE_BLE) 260 | { 261 | Serial.print(F("Connecting Blynk via BLE, using auth = ")); 262 | Serial.println(BLE_auth); 263 | 264 | #if ESP32_BLE_WF_DEBUG 265 | Serial.println(F("USE_BLE: Blynk_BLE begin")); 266 | #endif 267 | 268 | Blynk_BLE.begin(BLE_auth.c_str()); 269 | } 270 | } 271 | 272 | Serial.println(F("Scanning...")); 273 | 274 | BLEDevice::init(""); 275 | //create new scan 276 | pBLEScan = BLEDevice::getScan(); 277 | pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); 278 | 279 | //active scan uses more power, but get results faster 280 | pBLEScan->setActiveScan(true); 281 | 282 | pBLEScan->setInterval(100); 283 | // less or equal setInterval value 284 | pBLEScan->setWindow(99); 285 | 286 | // Important, need to keep constant communication to Blynk Server at least once per ~25s 287 | // Or Blynk will lost and have to (auto)reconnect 288 | timer.setInterval(10000L, noticeAlive); 289 | 290 | // Scan for Pet every 5.1s 291 | timer.setInterval(5100L, checkPet); 292 | } 293 | 294 | void loop() 295 | { 296 | if (USE_BLE) 297 | Blynk_BLE.run(); 298 | else 299 | Blynk_WF.run(); 300 | 301 | timer.run(); 302 | checkStatus(); 303 | } 304 | -------------------------------------------------------------------------------- /src/BlynkSimpleEsp32_BT_WF.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BlynkSimpleEsp32_BT_WF.h 3 | For ESP32 using WiFiManager and WiFi along with BlueTooth / BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | 12 | Original Blynk Library author: 13 | @file BlynkSimpleESP32.h 14 | @author Volodymyr Shymanskyy 15 | @license This project is released under the MIT License (MIT) 16 | @copyright Copyright (c) 2015 Volodymyr Shymanskyy 17 | @date Oct 2016 18 | @brief 19 | 20 | Version: 1.2.2 21 | 22 | Version Modified By Date Comments 23 | ------- ----------- ---------- ----------- 24 | 1.0.0 K Hoang 25/01/2020 Initial coding 25 | 1.0.1 K Hoang 27/01/2020 Enable simultaneously running BT/BLE and WiFi 26 | 1.0.2 K Hoang 04/02/2020 Add Blynk WiFiManager support similar to Blynk_WM library 27 | 1.0.3 K Hoang 24/02/2020 Add checksum, clearConfigData() 28 | 1.0.4 K Hoang 14/03/2020 Enhance GUI. Reduce code size. 29 | 1.0.5 K Hoang 18/04/2020 MultiWiFi/Blynk. Dynamic custom parameters. SSID password maxlen is 63 now. 30 | Permit special chars # and % in input data. 31 | 1.0.6 K Hoang 24/08/2020 Add Configurable Config Portal Title, Add USE_DEFAULT_CONFIG_DATA and DRD. 32 | Auto format SPIFFS. Update examples. 33 | 1.1.0 K Hoang 30/12/2020 Add support to LittleFS. Remove possible compiler warnings. Update examples 34 | 1.1.1 K Hoang 31/01/2021 Add functions to control Config Portal (CP) from software or Virtual Switches 35 | Fix CP and Dynamic Params bugs. To permit autoreset after timeout if DRD/MRD or forced CP 36 | 1.2.0 K Hoang 24/04/2021 Enable scan of WiFi networks for selection in Configuration Portal and many new features. 37 | 1.2.1 K Hoang 13/08/2021 Add auto-reconnect feature for BLE 38 | 1.2.2 K Hoang 13/08/2021 Update `platform.ini` and `library.json` 39 | *****************************************************************************************************************************/ 40 | 41 | #pragma once 42 | 43 | #ifndef BlynkSimpleEsp32_BT_WF_h 44 | #define BlynkSimpleEsp32_BT_WF_h 45 | 46 | #if !( defined(ESP32) ) 47 | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. 48 | #elif ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_ESP32S2_THING_PLUS || ARDUINO_MICROS2 || \ 49 | ARDUINO_METRO_ESP32S2 || ARDUINO_MAGTAG29_ESP32S2 || ARDUINO_FUNHOUSE_ESP32S2 || \ 50 | ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM ) 51 | #define BOARD_TYPE "ESP32-S2" 52 | #error ESP32-S2 is not supported yet. Please check later. 53 | #elif ( ARDUINO_ESP32C3_DEV ) 54 | #define BOARD_TYPE "ESP32-C3" 55 | #error ESP32-C3 is not supported yet. Please check later. 56 | #else 57 | #define BOARD_TYPE "ESP32" 58 | #endif 59 | 60 | #if !defined(BLYNK_ESP32_BT_WF_VERSION) 61 | #define BLYNK_ESP32_BT_WF_VERSION "BlynkESP32_BT_WF v1.2.2" 62 | #endif 63 | 64 | #ifndef BLYNK_INFO_CONNECTION 65 | #define BLYNK_INFO_CONNECTION "ESP32_BT" 66 | #endif 67 | 68 | #define BLYNK_SEND_ATOMIC 69 | #define BLYNK_SEND_CHUNK 40 70 | 71 | // KH 72 | #define BLYNK_TIMEOUT_MS 30000UL 73 | 74 | #include "sdkconfig.h" 75 | 76 | #if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED) 77 | 78 | #ifdef ARDUINO_ARCH_ESP32 79 | #include "esp32-hal-log.h" 80 | #endif 81 | 82 | #include "esp_bt.h" 83 | #include "esp_bt_main.h" 84 | #include "esp_gap_bt_api.h" 85 | #include "esp_bt_device.h" 86 | #include "esp_spp_api.h" 87 | 88 | #include 89 | #include 90 | #include 91 | 92 | class BlynkTransportEsp32_BT 93 | { 94 | public: 95 | BlynkTransportEsp32_BT() 96 | : mConn (false) 97 | , mName ("Blynk") 98 | {} 99 | 100 | void setDeviceName(const char* name) { 101 | mName = name; 102 | } 103 | 104 | // IP redirect not available 105 | void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {} 106 | 107 | void begin() { 108 | instance = this; 109 | 110 | if (!btStarted() && !btStart()) { 111 | BLYNK_LOG1(BLYNK_F("BTStartFailed")); 112 | return; 113 | } 114 | 115 | esp_bluedroid_status_t bt_state = esp_bluedroid_get_status(); 116 | if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) { 117 | if (esp_bluedroid_init()) { 118 | BLYNK_LOG1(BLYNK_F("BTInitFailed")); 119 | return; 120 | } 121 | } 122 | 123 | if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) { 124 | if (esp_bluedroid_enable()) { 125 | BLYNK_LOG1(BLYNK_F("BTEnableFailed")); 126 | return; 127 | } 128 | } 129 | 130 | if (esp_spp_register_callback(esp_spp_cb) != ESP_OK) { 131 | BLYNK_LOG1(BLYNK_F("RegCBFailed")); 132 | return; 133 | } 134 | 135 | if (esp_spp_init(ESP_SPP_MODE_CB) != ESP_OK) { 136 | BLYNK_LOG1(BLYNK_F("SPPInitFailed")); 137 | return; 138 | } 139 | 140 | if (esp_bredr_tx_power_set(ESP_PWR_LVL_N2, ESP_PWR_LVL_P7) != ESP_OK) 141 | { 142 | BLYNK_LOG1(BLYNK_F("TXPwrSetFailed")); 143 | }; 144 | 145 | if (esp_bt_dev_set_device_name(mName) != ESP_OK) 146 | { 147 | BLYNK_LOG1(BLYNK_F("BESetNameFailed")); 148 | } 149 | } 150 | 151 | bool connect() { 152 | mBuffRX.clear(); 153 | return mConn = true; 154 | } 155 | 156 | void disconnect() { 157 | mConn = false; 158 | } 159 | 160 | bool connected() { 161 | return mConn; 162 | } 163 | 164 | size_t read(void* buf, size_t len) { 165 | millis_time_t start = BlynkMillis(); 166 | while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) { 167 | if (available() < len) { 168 | delay(1); 169 | } else { 170 | break; 171 | } 172 | } 173 | size_t res = mBuffRX.get((uint8_t*)buf, len); 174 | return res; 175 | } 176 | 177 | size_t write(const void* buf, size_t len) { 178 | if (!spp_handle) { 179 | return 0; 180 | } 181 | 182 | esp_err_t err = esp_spp_write(spp_handle, len, (uint8_t *)buf); 183 | return (err == ESP_OK) ? len : 0; 184 | } 185 | 186 | size_t available() { 187 | size_t rxSize = mBuffRX.size(); 188 | return rxSize; 189 | } 190 | 191 | 192 | static 193 | void putData(uint8_t* data, uint16_t len) { 194 | if (instance) 195 | { 196 | // BLYNK_DBG_DUMP(">> ", data, len); 197 | instance->mBuffRX.put(data, len); 198 | } 199 | } 200 | 201 | private: 202 | static BlynkTransportEsp32_BT* instance; 203 | static uint32_t spp_handle; 204 | 205 | static void onConnect(); 206 | static void onDisconnect(); 207 | 208 | bool mConn; 209 | const char* mName; 210 | 211 | BlynkFifo mBuffRX; 212 | 213 | static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) 214 | { 215 | switch (event) 216 | { 217 | case ESP_SPP_INIT_EVT: // Once the SPP callback has been registered, ESP_SPP_INIT_EVT is triggered 218 | esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); 219 | esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, "SPP_SERVER"); 220 | break; 221 | 222 | case ESP_SPP_CLOSE_EVT:// After the SPP disconnection, ESP_SPP_CLOSE_EVT is triggered. 223 | spp_handle = 0; 224 | onDisconnect(); 225 | break; 226 | 227 | case ESP_SPP_DATA_IND_EVT:// Data received 228 | if (param->data_ind.len > 0) 229 | { 230 | instance->putData((uint8_t*)param->data_ind.data, param->data_ind.len); 231 | } 232 | else 233 | { 234 | BLYNK_LOG1(BLYNK_F("SPP_DATA_ERROR")); 235 | } 236 | break; 237 | 238 | case ESP_SPP_CONG_EVT: // SPP connection congestion status changed 239 | BLYNK_LOG1(BLYNK_F("SPP_CONG_EVT")); 240 | break; 241 | 242 | case ESP_SPP_SRV_OPEN_EVT://Server connection open 243 | spp_handle = param->open.handle; 244 | onConnect(); 245 | break; 246 | 247 | default: 248 | break; 249 | } 250 | } 251 | }; 252 | 253 | class BlynkEsp32_BT 254 | : public BlynkProtocol 255 | { 256 | typedef BlynkProtocol Base; 257 | public: 258 | BlynkEsp32_BT(BlynkTransportEsp32_BT& transp) 259 | : Base(transp) 260 | {} 261 | 262 | void begin(const char* auth) 263 | { 264 | Base::begin(auth); 265 | state = DISCONNECTED; 266 | conn.begin(); 267 | } 268 | 269 | // KH 270 | void begin(const char* auth, char* ssid, char* pass) 271 | { 272 | begin(auth); 273 | } 274 | 275 | void setDeviceName(const char* name) { 276 | conn.setDeviceName(name); 277 | } 278 | 279 | }; 280 | 281 | BlynkTransportEsp32_BT* BlynkTransportEsp32_BT::instance = NULL; 282 | uint32_t BlynkTransportEsp32_BT::spp_handle = 0; 283 | 284 | // KH 285 | static BlynkTransportEsp32_BT _blynkTransport_BT; 286 | BlynkEsp32_BT Blynk_BT(_blynkTransport_BT); 287 | 288 | #define Blynk Blynk_BT 289 | 290 | void BlynkTransportEsp32_BT::onConnect() { 291 | BLYNK_LOG1(BLYNK_F("BTCon")); 292 | Blynk_BT.startSession(); 293 | }; 294 | 295 | void BlynkTransportEsp32_BT::onDisconnect() { 296 | BLYNK_LOG1(BLYNK_F("BTDisCon")); 297 | Blynk_BT.disconnect(); 298 | } 299 | // 300 | 301 | #include 302 | 303 | #endif 304 | #endif 305 | -------------------------------------------------------------------------------- /examples/ESP32_BT_WF/ESP32_BT_WF.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | ESP32_BT_WF.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | bool USE_BT = true; 29 | long timePreviousMeassure = 0; 30 | 31 | #define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 32 | 33 | BlynkTimer timer; 34 | 35 | #include 36 | Ticker led_ticker; 37 | 38 | #define BLYNK_PIN_FORCED_CONFIG V10 39 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 40 | 41 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 42 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 43 | { 44 | if (param.asInt()) 45 | { 46 | Serial.println( F("\nCP Button Hit. Rebooting") ); 47 | 48 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 49 | Blynk.resetAndEnterConfigPortal(); 50 | } 51 | } 52 | 53 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 54 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 55 | { 56 | if (param.asInt()) 57 | { 58 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 59 | 60 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 61 | Blynk.resetAndEnterConfigPortalPersistent(); 62 | } 63 | } 64 | 65 | void set_led(byte status) 66 | { 67 | digitalWrite(LED_BUILTIN, status); 68 | } 69 | 70 | void noticeAlive(void) 71 | { 72 | if (USE_BT) 73 | Blynk_BT.virtualWrite(V0, F("OK")); 74 | else 75 | Blynk_WF.virtualWrite(V0, F("OK")); 76 | } 77 | 78 | void heartBeatPrint(void) 79 | { 80 | static int num = 1; 81 | 82 | if (Blynk.connected()) 83 | { 84 | set_led(HIGH); 85 | led_ticker.once_ms(111, set_led, (byte) LOW); 86 | Serial.print(F("B")); 87 | } 88 | else 89 | { 90 | Serial.print(F("F")); 91 | } 92 | 93 | if (num == 80) 94 | { 95 | Serial.println(); 96 | num = 1; 97 | } 98 | else if (num++ % 10 == 0) 99 | { 100 | Serial.print(F(" ")); 101 | } 102 | } 103 | 104 | void checkStatus() 105 | { 106 | static unsigned long checkstatus_timeout = 0; 107 | 108 | #define STATUS_CHECK_INTERVAL 60000L 109 | 110 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 111 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 112 | { 113 | if (!USE_BT) 114 | { 115 | // report Blynk connection 116 | heartBeatPrint(); 117 | } 118 | 119 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 120 | } 121 | } 122 | 123 | char BT_Device_Name[] = "GeigerCounter-BT"; 124 | 125 | #if USING_CUSTOMS_STYLE 126 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 128 | #endif 129 | 130 | void setup() 131 | { 132 | Serial.begin(115200); 133 | while (!Serial); 134 | 135 | #if (USE_LITTLEFS) 136 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 137 | #elif (USE_SPIFFS) 138 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 139 | #else 140 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 141 | #endif 142 | 143 | #if USE_SSL 144 | Serial.print(F(" with SSL on ")); 145 | #else 146 | Serial.print(F(" without SSL on ")); 147 | #endif 148 | 149 | Serial.println(ARDUINO_BOARD); 150 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 151 | 152 | #if USE_BLYNK_WM 153 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 154 | #endif 155 | 156 | pinMode(WIFI_BT_SELECTION_PIN, INPUT_PULLUP); 157 | 158 | #if BLYNK_USE_BT_ONLY 159 | Blynk_BT.setDeviceName(BT_Device_Name); 160 | 161 | #if ESP32_BT_WF_DEBUG 162 | Serial.println(F("Blynk_BT begin")); 163 | #endif 164 | 165 | Blynk_BT.begin(auth); 166 | #else 167 | if (digitalRead(WIFI_BT_SELECTION_PIN) == HIGH) 168 | { 169 | USE_BT = false; 170 | Serial.println(F("GPIO14 HIGH, Use WiFi")); 171 | #if USE_BLYNK_WM 172 | #if ESP32_BT_WF_DEBUG 173 | Serial.println(F("USE_BLYNK_WM: Blynk_WF begin")); 174 | #endif 175 | // Set config portal SSID and Password 176 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 177 | // Set config portal IP address 178 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 179 | 180 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 181 | Blynk_WF.setConfigPortalChannel(0); 182 | 183 | // From v1.0.6, select either one of these to set static IP + DNS 184 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 185 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 186 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 187 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 188 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 189 | 190 | ////////////////////////////////////////////// 191 | 192 | #if USING_CUSTOMS_STYLE 193 | Blynk.setCustomsStyle(NewCustomsStyle); 194 | #endif 195 | 196 | #if USING_CUSTOMS_HEAD_ELEMENT 197 | Blynk.setCustomsHeadElement(""); 198 | #endif 199 | 200 | #if USING_CORS_FEATURE 201 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 202 | #endif 203 | 204 | ////////////////////////////////////////////// 205 | 206 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 207 | //Blynk.begin(); 208 | // Use this to personalize DHCP hostname (RFC952 conformed) 209 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 210 | //Blynk.begin("ESP32-BT-WM"); 211 | 212 | Blynk_WF.begin(BT_Device_Name); 213 | #else 214 | //Blynk_WF.begin(auth, ssid, pass); 215 | #if ESP32_BT_WF_DEBUG 216 | Serial.println(F("Not USE_BLYNK_WM: Blynk_WF begin")); 217 | #endif 218 | Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 219 | #endif 220 | } 221 | else 222 | { 223 | USE_BT = true; 224 | Serial.println(F("GPIO14 LOW, Use BT")); 225 | Blynk_BT.setDeviceName(BT_Device_Name); 226 | #if USE_BLYNK_WM 227 | if (Blynk_WF.getBlynkBTToken() == NO_CONFIG) //String("blank")) 228 | { 229 | Serial.println(F("No valid stored BT auth. Have to run WiFi then enter config portal")); 230 | USE_BT = false; 231 | 232 | #if ESP32_BT_WF_DEBUG 233 | Serial.println(F("USE_BLYNK_WM: No BT Token. Blynk_WF begin")); 234 | #endif 235 | 236 | Blynk_WF.begin(BT_Device_Name); 237 | } 238 | String BT_auth = Blynk_WF.getBlynkBTToken(); 239 | #else 240 | String BT_auth = auth; 241 | #endif 242 | 243 | if (USE_BT) 244 | { 245 | Serial.print(F("Connecting Blynk via BT, using auth = ")); 246 | Serial.println(BT_auth); 247 | 248 | #if ESP32_BT_WF_DEBUG 249 | Serial.println(F("USE_BT: Blynk_BT begin")); 250 | #endif 251 | 252 | Blynk_BT.begin(BT_auth.c_str()); 253 | } 254 | } 255 | #endif 256 | 257 | // Important, need to keep constant communication to Blynk Server at least once per ~25s 258 | // Or Blynk will lost and have to (auto)reconnect 259 | timer.setInterval(10000L, noticeAlive); 260 | } 261 | 262 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 263 | void displayCredentials() 264 | { 265 | Serial.println(F("\nYour stored Credentials :")); 266 | 267 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 268 | { 269 | Serial.print(myMenuItems[i].displayName); 270 | Serial.print(F(" = ")); 271 | Serial.println(myMenuItems[i].pdata); 272 | } 273 | } 274 | 275 | void displayCredentialsInLoop() 276 | { 277 | static bool displayedCredentials = false; 278 | 279 | if (!displayedCredentials) 280 | { 281 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 282 | { 283 | if (!strlen(myMenuItems[i].pdata)) 284 | { 285 | break; 286 | } 287 | 288 | if ( i == (NUM_MENU_ITEMS - 1) ) 289 | { 290 | displayedCredentials = true; 291 | displayCredentials(); 292 | } 293 | } 294 | } 295 | } 296 | 297 | #endif 298 | 299 | void loop() 300 | { 301 | #if BLYNK_USE_BT_ONLY 302 | Blynk_BT.run(); 303 | #else 304 | if (USE_BT) 305 | Blynk_BT.run(); 306 | else 307 | Blynk_WF.run(); 308 | #endif 309 | 310 | timer.run(); 311 | checkStatus(); 312 | 313 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 314 | displayCredentialsInLoop(); 315 | #endif 316 | } 317 | -------------------------------------------------------------------------------- /examples/ESP32_BLE_WF/ESP32_BLE_WF.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | ESP32_BLE_WF.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | bool USE_BLE = true; 29 | long timePreviousMeassure = 0; 30 | 31 | #define WIFI_BLE_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 32 | 33 | BlynkTimer timer; 34 | 35 | #include 36 | Ticker led_ticker; 37 | 38 | #define BLYNK_PIN_FORCED_CONFIG V10 39 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 40 | 41 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 42 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 43 | { 44 | if (param.asInt()) 45 | { 46 | Serial.println( F("\nCP Button Hit. Rebooting") ); 47 | 48 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 49 | Blynk.resetAndEnterConfigPortal(); 50 | } 51 | } 52 | 53 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 54 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 55 | { 56 | if (param.asInt()) 57 | { 58 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 59 | 60 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 61 | Blynk.resetAndEnterConfigPortalPersistent(); 62 | } 63 | } 64 | 65 | void set_led(byte status) 66 | { 67 | digitalWrite(LED_BUILTIN, status); 68 | } 69 | 70 | void noticeAlive(void) 71 | { 72 | if (USE_BLE) 73 | Blynk_BLE.virtualWrite(V0, F("OK")); 74 | else 75 | Blynk_WF.virtualWrite(V0, F("OK")); 76 | } 77 | 78 | void heartBeatPrint(void) 79 | { 80 | static int num = 1; 81 | 82 | if (Blynk.connected()) 83 | { 84 | set_led(HIGH); 85 | led_ticker.once_ms(111, set_led, (byte) LOW); 86 | Serial.print(F("B")); 87 | } 88 | else 89 | { 90 | Serial.print(F("F")); 91 | } 92 | 93 | if (num == 80) 94 | { 95 | Serial.println(); 96 | num = 1; 97 | } 98 | else if (num++ % 10 == 0) 99 | { 100 | Serial.print(F(" ")); 101 | } 102 | } 103 | 104 | void checkStatus() 105 | { 106 | static unsigned long checkstatus_timeout = 0; 107 | 108 | #define STATUS_CHECK_INTERVAL 60000L 109 | 110 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 111 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 112 | { 113 | if (!USE_BLE) 114 | { 115 | // report Blynk connection 116 | heartBeatPrint(); 117 | } 118 | 119 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 120 | } 121 | } 122 | 123 | char BLE_Device_Name[] = "GeigerCounter-BLE"; 124 | 125 | #if USING_CUSTOMS_STYLE 126 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 128 | #endif 129 | 130 | void setup() 131 | { 132 | Serial.begin(115200); 133 | while (!Serial); 134 | 135 | delay(200); 136 | 137 | #if (USE_LITTLEFS) 138 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 139 | #elif (USE_SPIFFS) 140 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 141 | #else 142 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 143 | #endif 144 | 145 | #if USE_SSL 146 | Serial.print(F(" with SSL on ")); 147 | #else 148 | Serial.print(F(" without SSL on ")); 149 | #endif 150 | 151 | Serial.println(ARDUINO_BOARD); 152 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 153 | 154 | #if USE_BLYNK_WM 155 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 156 | #endif 157 | 158 | pinMode(WIFI_BLE_SELECTION_PIN, INPUT_PULLUP); 159 | 160 | #if BLYNK_USE_BLE_ONLY 161 | Blynk_BLE.setDeviceName(BLE_Device_Name); 162 | 163 | #if ESP32_BLE_WF_DEBUG 164 | Serial.println(F("Blynk_BLE begin")); 165 | #endif 166 | 167 | Blynk_BLE.begin(auth); 168 | #else 169 | if (digitalRead(WIFI_BLE_SELECTION_PIN) == HIGH) 170 | { 171 | USE_BLE = false; 172 | Serial.println(F("GPIO14 HIGH, Use WiFi")); 173 | #if USE_BLYNK_WM 174 | #if ESP32_BLE_WF_DEBUG 175 | Serial.println(F("USE_BLYNK_WM: Blynk_WF begin")); 176 | #endif 177 | 178 | // Set config portal SSID and Password 179 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 180 | // Set config portal IP address 181 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 182 | 183 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 184 | Blynk_WF.setConfigPortalChannel(0); 185 | 186 | // From v1.0.6, select either one of these to set static IP + DNS 187 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 188 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 189 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 190 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 191 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 192 | 193 | 194 | ////////////////////////////////////////////// 195 | 196 | #if USING_CUSTOMS_STYLE 197 | Blynk.setCustomsStyle(NewCustomsStyle); 198 | #endif 199 | 200 | #if USING_CUSTOMS_HEAD_ELEMENT 201 | Blynk.setCustomsHeadElement(""); 202 | #endif 203 | 204 | #if USING_CORS_FEATURE 205 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 206 | #endif 207 | 208 | ////////////////////////////////////////////// 209 | 210 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 211 | //Blynk.begin(); 212 | // Use this to personalize DHCP hostname (RFC952 conformed) 213 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 214 | //Blynk.begin("ESP32-BLE-WM"); 215 | 216 | Blynk_WF.begin(BLE_Device_Name); 217 | #else 218 | //Blynk_WF.begin(auth, ssid, pass); 219 | #if ESP32_BLE_WF_DEBUG 220 | Serial.println(F("Not USE_BLYNK_WM: Blynk_WF begin")); 221 | #endif 222 | Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 223 | #endif 224 | } 225 | else 226 | { 227 | USE_BLE = true; 228 | Serial.println(F("GPIO14 LOW, Use BLE")); 229 | Blynk_BLE.setDeviceName(BLE_Device_Name); 230 | #if USE_BLYNK_WM 231 | if (Blynk_WF.getBlynkBLEToken() == NO_CONFIG) //String("blank")) 232 | { 233 | Serial.println(F("No valid stored BLE auth. Have to run WiFi then enter config portal")); 234 | USE_BLE = false; 235 | 236 | #if ESP32_BLE_WF_DEBUG 237 | Serial.println(F("USE_BLYNK_WM: No BLE Token. Blynk_WF begin")); 238 | #endif 239 | 240 | Blynk_WF.begin(BLE_Device_Name); 241 | } 242 | String BLE_auth = Blynk_WF.getBlynkBLEToken(); 243 | #else 244 | String BLE_auth = auth; 245 | #endif 246 | 247 | if (USE_BLE) 248 | { 249 | Serial.print(F("Connecting Blynk via BLE, using auth = ")); 250 | Serial.println(BLE_auth); 251 | 252 | #if ESP32_BLE_WF_DEBUG 253 | Serial.println(F("USE_BLE: Blynk_BLE begin")); 254 | #endif 255 | 256 | Blynk_BLE.begin(BLE_auth.c_str()); 257 | } 258 | } 259 | #endif 260 | 261 | // Important, need to keep constant communication to Blynk Server at least once per ~25s 262 | // Or Blynk will lost and have to (auto)reconnect 263 | timer.setInterval(10000L, noticeAlive); 264 | } 265 | 266 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 267 | void displayCredentials() 268 | { 269 | Serial.println(F("\nYour stored Credentials :")); 270 | 271 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 272 | { 273 | Serial.print(myMenuItems[i].displayName); 274 | Serial.print(F(" = ")); 275 | Serial.println(myMenuItems[i].pdata); 276 | } 277 | } 278 | 279 | void displayCredentialsInLoop() 280 | { 281 | static bool displayedCredentials = false; 282 | 283 | if (!displayedCredentials) 284 | { 285 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 286 | { 287 | if (!strlen(myMenuItems[i].pdata)) 288 | { 289 | break; 290 | } 291 | 292 | if ( i == (NUM_MENU_ITEMS - 1) ) 293 | { 294 | displayedCredentials = true; 295 | displayCredentials(); 296 | } 297 | } 298 | } 299 | } 300 | 301 | #endif 302 | 303 | void loop() 304 | { 305 | #if BLYNK_USE_BLE_ONLY 306 | Blynk_BLE.run(); 307 | #else 308 | if (USE_BLE) 309 | Blynk_BLE.run(); 310 | else 311 | Blynk_WF.run(); 312 | #endif 313 | 314 | timer.run(); 315 | checkStatus(); 316 | 317 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 318 | displayCredentialsInLoop(); 319 | #endif 320 | } 321 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BT/Geiger_Counter_BT.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Geiger_Counter_BT.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | bool USE_BT = true; 29 | 30 | #define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 31 | #define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 32 | #define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 33 | 34 | #define CONV_FACTOR 0.00658 35 | #define SCREEN_WIDTH 128 36 | #define SCREEN_HEIGHT 32 37 | #define OLED_RESET 4 38 | #define DEBOUNCE_TIME_MICRO_SEC 4200L 39 | #define MEASURE_INTERVAL_MS 20000L 40 | #define COUNT_PER_MIN_CONVERSION (60000 / MEASURE_INTERVAL_MS) 41 | #define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 ) 42 | 43 | float voltage = 0; 44 | long countPerMinute = 0; 45 | long timePrevious = 0; 46 | long timePreviousMeassure = 0; 47 | long _time = 0; 48 | long countPrevious = 0; 49 | float radiationValue = 0.0; 50 | float radiationDose = 0; 51 | 52 | void IRAM_ATTR countPulse(); 53 | volatile unsigned long last_micros; 54 | volatile long count = 0; 55 | 56 | BlynkTimer timer; 57 | 58 | #include 59 | Ticker led_ticker; 60 | 61 | #define BLYNK_PIN_FORCED_CONFIG V10 62 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 63 | 64 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 65 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 66 | { 67 | if (param.asInt()) 68 | { 69 | Serial.println( F("\nCP Button Hit. Rebooting") ); 70 | 71 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 72 | Blynk.resetAndEnterConfigPortal(); 73 | } 74 | } 75 | 76 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 77 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 78 | { 79 | if (param.asInt()) 80 | { 81 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 82 | 83 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 84 | Blynk.resetAndEnterConfigPortalPersistent(); 85 | } 86 | } 87 | 88 | void IRAM_ATTR countPulse() 89 | { 90 | if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) 91 | { 92 | count++; 93 | last_micros = micros(); 94 | } 95 | } 96 | 97 | void sendDatatoBlynk() 98 | { 99 | #if BLYNK_USE_BT_ONLY 100 | Blynk_BT.virtualWrite(V1, countPerMinute); 101 | Blynk_BT.virtualWrite(V3, radiationValue); 102 | Blynk_BT.virtualWrite(V5, radiationDose); 103 | Blynk_BT.virtualWrite(V7, voltage); 104 | #else 105 | if (USE_BT) 106 | { 107 | Blynk_BT.virtualWrite(V1, countPerMinute); 108 | Blynk_BT.virtualWrite(V3, radiationValue); 109 | Blynk_BT.virtualWrite(V5, radiationDose); 110 | Blynk_BT.virtualWrite(V7, voltage); 111 | } 112 | else 113 | { 114 | Blynk_WF.virtualWrite(V1, countPerMinute); 115 | Blynk_WF.virtualWrite(V3, radiationValue); 116 | Blynk_WF.virtualWrite(V5, radiationDose); 117 | Blynk_WF.virtualWrite(V7, voltage); 118 | } 119 | #endif 120 | } 121 | 122 | void Serial_Display() 123 | { 124 | Serial.print(F("cpm = ")); 125 | Serial.printf("%4lu", countPerMinute); 126 | Serial.print(F(" - ")); 127 | Serial.print(F("RadiationValue = ")); 128 | Serial.printf("%5.3f", radiationValue); 129 | Serial.print(F(" uSv/h")); 130 | Serial.print(F(" - ")); 131 | Serial.print(F("Equivalent RadiationDose = ")); 132 | Serial.printf("%6.4f", radiationDose); 133 | Serial.println(F(" uSv")); 134 | } 135 | 136 | void set_led(byte status) 137 | { 138 | digitalWrite(LED_BUILTIN, status); 139 | } 140 | 141 | void heartBeatPrint(void) 142 | { 143 | static int num = 1; 144 | 145 | if (Blynk.connected()) 146 | { 147 | set_led(HIGH); 148 | led_ticker.once_ms(111, set_led, (byte) LOW); 149 | Serial.print(F("B")); 150 | } 151 | else 152 | { 153 | Serial.print(F("F")); 154 | } 155 | 156 | if (num == 80) 157 | { 158 | Serial.println(); 159 | num = 1; 160 | } 161 | else if (num++ % 10 == 0) 162 | { 163 | Serial.print(F(" ")); 164 | } 165 | } 166 | 167 | #define USE_SIMULATION true 168 | //#define USE_SIMULATION false 169 | 170 | void checkStatus() 171 | { 172 | if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS) 173 | { 174 | if (!USE_BT) 175 | { 176 | if (Blynk.connected()) 177 | Serial.println(F("B")); 178 | else 179 | Serial.println(F("F")); 180 | } 181 | 182 | timePreviousMeassure = millis(); 183 | 184 | noInterrupts(); 185 | countPerMinute = COUNT_PER_MIN_CONVERSION * count; 186 | interrupts(); 187 | 188 | radiationValue = countPerMinute * CONV_FACTOR; 189 | radiationDose = radiationDose + (radiationValue / float(240.0)); 190 | 191 | // can optimize this calculation 192 | voltage = (float) analogRead(VOLTAGER_INPUT_PIN) * VOLTAGE_FACTOR; 193 | 194 | if (radiationDose > 99.999) 195 | { 196 | radiationDose = 0; 197 | } 198 | 199 | Serial_Display(); 200 | 201 | #if USE_SIMULATION 202 | count += 10; 203 | if (count >= 1000) 204 | count = 0; 205 | #else 206 | count = 0; 207 | #endif 208 | 209 | // report Blynk connection 210 | heartBeatPrint(); 211 | } 212 | } 213 | 214 | char BT_Device_Name[] = "GeigerCounter-BT"; 215 | 216 | #if USING_CUSTOMS_STYLE 217 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 219 | #endif 220 | 221 | void setup() 222 | { 223 | Serial.begin(115200); 224 | while (!Serial); 225 | 226 | #if (USE_LITTLEFS) 227 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 228 | #elif (USE_SPIFFS) 229 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 230 | #else 231 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 232 | #endif 233 | 234 | #if USE_SSL 235 | Serial.print(F(" with SSL on ")); 236 | #else 237 | Serial.print(F(" without SSL on ")); 238 | #endif 239 | 240 | Serial.println(ARDUINO_BOARD); 241 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 242 | 243 | #if USE_BLYNK_WM 244 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 245 | #endif 246 | 247 | pinMode(GEIGER_INPUT_PIN, INPUT); 248 | attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH); 249 | 250 | #if BLYNK_USE_BT_ONLY 251 | Blynk_BT.setDeviceName(BT_Device_Name); 252 | Blynk_BT.begin(auth); 253 | #else 254 | if (digitalRead(WIFI_BT_SELECTION_PIN) == HIGH) 255 | { 256 | USE_BT = false; 257 | Serial.println(F("GPIO14 HIGH, Use WiFi")); 258 | #if USE_BLYNK_WM 259 | // Set config portal SSID and Password 260 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 261 | // Set config portal IP address 262 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 263 | 264 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 265 | Blynk_WF.setConfigPortalChannel(0); 266 | 267 | // From v1.0.6, select either one of these to set static IP + DNS 268 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 269 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 270 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 271 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 272 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 273 | 274 | ////////////////////////////////////////////// 275 | 276 | #if USING_CUSTOMS_STYLE 277 | Blynk.setCustomsStyle(NewCustomsStyle); 278 | #endif 279 | 280 | #if USING_CUSTOMS_HEAD_ELEMENT 281 | Blynk.setCustomsHeadElement(""); 282 | #endif 283 | 284 | #if USING_CORS_FEATURE 285 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 286 | #endif 287 | 288 | ////////////////////////////////////////////// 289 | 290 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 291 | //Blynk.begin(); 292 | // Use this to personalize DHCP hostname (RFC952 conformed) 293 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 294 | //Blynk.begin("ESP32-BT-WM"); 295 | 296 | Blynk_WF.begin(BT_Device_Name); 297 | #else 298 | //Blynk_WF.begin(auth, ssid, pass); 299 | Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 300 | #endif 301 | } 302 | else 303 | { 304 | USE_BT = true; 305 | Serial.println(F("GPIO14 LOW, Use BT")); 306 | Blynk_BT.setDeviceName(BT_Device_Name); 307 | #if USE_BLYNK_WM 308 | if (Blynk_WF.getBlynkBTToken() == NO_CONFIG) //String("blank")) 309 | { 310 | Serial.println(F("No valid stored BT auth. Have to run WiFi then enter config portal")); 311 | USE_BT = false; 312 | Blynk_WF.begin(BT_Device_Name); 313 | } 314 | String BT_auth = Blynk_WF.getBlynkBTToken(); 315 | #else 316 | String BT_auth = auth; 317 | #endif 318 | 319 | if (USE_BT) 320 | { 321 | Serial.print(F("Connecting Blynk via BT, using auth = ")); 322 | Serial.println(BT_auth); 323 | Blynk_BT.begin(BT_auth.c_str()); 324 | } 325 | } 326 | #endif 327 | 328 | timer.setInterval(5000L, sendDatatoBlynk); 329 | } 330 | 331 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 332 | void displayCredentials() 333 | { 334 | Serial.println(F("\nYour stored Credentials :")); 335 | 336 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 337 | { 338 | Serial.print(myMenuItems[i].displayName); 339 | Serial.print(F(" = ")); 340 | Serial.println(myMenuItems[i].pdata); 341 | } 342 | } 343 | 344 | void displayCredentialsInLoop() 345 | { 346 | static bool displayedCredentials = false; 347 | 348 | if (!displayedCredentials) 349 | { 350 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 351 | { 352 | if (!strlen(myMenuItems[i].pdata)) 353 | { 354 | break; 355 | } 356 | 357 | if ( i == (NUM_MENU_ITEMS - 1) ) 358 | { 359 | displayedCredentials = true; 360 | displayCredentials(); 361 | } 362 | } 363 | } 364 | } 365 | 366 | #endif 367 | 368 | void loop() 369 | { 370 | #if BLYNK_USE_BT_ONLY 371 | Blynk_BT.run(); 372 | #else 373 | if (USE_BT) 374 | Blynk_BT.run(); 375 | else 376 | Blynk_WF.run(); 377 | #endif 378 | 379 | timer.run(); 380 | checkStatus(); 381 | 382 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 383 | displayCredentialsInLoop(); 384 | #endif 385 | } 386 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_BLE/Geiger_Counter_BLE.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Geiger_Counter_BLE.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | bool USE_BLE = true; 29 | 30 | #define WIFI_BLE_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 31 | #define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 32 | #define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 33 | 34 | #define CONV_FACTOR 0.00658 35 | #define SCREEN_WIDTH 128 36 | #define SCREEN_HEIGHT 32 37 | #define OLED_RESET 4 38 | #define DEBOUNCE_TIME_MICRO_SEC 4200L 39 | #define MEASURE_INTERVAL_MS 20000L 40 | #define COUNT_PER_MIN_CONVERSION (60000 / MEASURE_INTERVAL_MS) 41 | #define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 ) 42 | 43 | float voltage = 0; 44 | long countPerMinute = 0; 45 | long timePrevious = 0; 46 | long timePreviousMeassure = 0; 47 | long _time = 0; 48 | long countPrevious = 0; 49 | float radiationValue = 0.0; 50 | float radiationDose = 0; 51 | 52 | void IRAM_ATTR countPulse(); 53 | volatile unsigned long last_micros; 54 | volatile long count = 0; 55 | 56 | BlynkTimer timer; 57 | 58 | #include 59 | Ticker led_ticker; 60 | 61 | #define BLYNK_PIN_FORCED_CONFIG V10 62 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 63 | 64 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 65 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 66 | { 67 | if (param.asInt()) 68 | { 69 | Serial.println( F("\nCP Button Hit. Rebooting") ); 70 | 71 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 72 | Blynk.resetAndEnterConfigPortal(); 73 | } 74 | } 75 | 76 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 77 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 78 | { 79 | if (param.asInt()) 80 | { 81 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 82 | 83 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 84 | Blynk.resetAndEnterConfigPortalPersistent(); 85 | } 86 | } 87 | 88 | void IRAM_ATTR countPulse() 89 | { 90 | if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) 91 | { 92 | count++; 93 | last_micros = micros(); 94 | } 95 | } 96 | 97 | void sendDatatoBlynk() 98 | { 99 | #if BLYNK_USE_BLE_ONLY 100 | Blynk_BLE.virtualWrite(V1, countPerMinute); 101 | Blynk_BLE.virtualWrite(V3, radiationValue); 102 | Blynk_BLE.virtualWrite(V5, radiationDose); 103 | Blynk_BLE.virtualWrite(V7, voltage); 104 | #else 105 | if (USE_BLE) 106 | { 107 | Blynk_BLE.virtualWrite(V1, countPerMinute); 108 | Blynk_BLE.virtualWrite(V3, radiationValue); 109 | Blynk_BLE.virtualWrite(V5, radiationDose); 110 | Blynk_BLE.virtualWrite(V7, voltage); 111 | } 112 | else 113 | { 114 | Blynk_WF.virtualWrite(V1, countPerMinute); 115 | Blynk_WF.virtualWrite(V3, radiationValue); 116 | Blynk_WF.virtualWrite(V5, radiationDose); 117 | Blynk_WF.virtualWrite(V7, voltage); 118 | } 119 | #endif 120 | } 121 | 122 | void Serial_Display() 123 | { 124 | Serial.print(F("cpm = ")); 125 | Serial.printf("%4lu", countPerMinute); 126 | Serial.print(F(" - ")); 127 | Serial.print(F("RadiationValue = ")); 128 | Serial.printf("%5.3f", radiationValue); 129 | Serial.print(F(" uSv/h")); 130 | Serial.print(F(" - ")); 131 | Serial.print(F("Equivalent RadiationDose = ")); 132 | Serial.printf("%6.4f", radiationDose); 133 | Serial.println(F(" uSv")); 134 | } 135 | 136 | void set_led(byte status) 137 | { 138 | digitalWrite(LED_BUILTIN, status); 139 | } 140 | 141 | void heartBeatPrint(void) 142 | { 143 | static int num = 1; 144 | 145 | if (Blynk.connected()) 146 | { 147 | set_led(HIGH); 148 | led_ticker.once_ms(111, set_led, (byte) LOW); 149 | Serial.print(F("B")); 150 | } 151 | else 152 | { 153 | Serial.print(F("F")); 154 | } 155 | 156 | if (num == 80) 157 | { 158 | Serial.println(); 159 | num = 1; 160 | } 161 | else if (num++ % 10 == 0) 162 | { 163 | Serial.print(F(" ")); 164 | } 165 | } 166 | 167 | #define USE_SIMULATION true 168 | //#define USE_SIMULATION false 169 | 170 | void checkStatus() 171 | { 172 | if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS) 173 | { 174 | if (!USE_BLE) 175 | { 176 | if (Blynk.connected()) 177 | Serial.println(F("B")); 178 | else 179 | Serial.println(F("F")); 180 | } 181 | 182 | timePreviousMeassure = millis(); 183 | 184 | noInterrupts(); 185 | countPerMinute = COUNT_PER_MIN_CONVERSION * count; 186 | interrupts(); 187 | 188 | radiationValue = countPerMinute * CONV_FACTOR; 189 | radiationDose = radiationDose + (radiationValue / float(240.0)); 190 | 191 | // can optimize this calculation 192 | voltage = (float) analogRead(VOLTAGER_INPUT_PIN) * VOLTAGE_FACTOR; 193 | 194 | if (radiationDose > 99.999) 195 | { 196 | radiationDose = 0; 197 | } 198 | 199 | Serial_Display(); 200 | 201 | #if USE_SIMULATION 202 | count += 10; 203 | if (count >= 1000) 204 | count = 0; 205 | #else 206 | count = 0; 207 | #endif 208 | 209 | // report Blynk connection 210 | heartBeatPrint(); 211 | } 212 | } 213 | 214 | char BLE_Device_Name[] = "GeigerCounter-BLE"; 215 | 216 | #if USING_CUSTOMS_STYLE 217 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 219 | #endif 220 | 221 | void setup() 222 | { 223 | Serial.begin(115200); 224 | while (!Serial); 225 | 226 | #if (USE_LITTLEFS) 227 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 228 | #elif (USE_SPIFFS) 229 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 230 | #else 231 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 232 | #endif 233 | 234 | #if USE_SSL 235 | Serial.print(F(" with SSL on ")); 236 | #else 237 | Serial.print(F(" without SSL on ")); 238 | #endif 239 | 240 | Serial.println(ARDUINO_BOARD); 241 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 242 | 243 | #if USE_BLYNK_WM 244 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 245 | #endif 246 | 247 | pinMode(GEIGER_INPUT_PIN, INPUT); 248 | attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH); 249 | 250 | #if BLYNK_USE_BLE_ONLY 251 | Blynk_BLE.setDeviceName(BLE_Device_Name); 252 | Blynk_BLE.begin(auth); 253 | #else 254 | if (digitalRead(WIFI_BLE_SELECTION_PIN) == HIGH) 255 | { 256 | USE_BLE = false; 257 | Serial.println(F("GPIO14 HIGH, Use WiFi")); 258 | #if USE_BLYNK_WM 259 | // Set config portal SSID and Password 260 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 261 | // Set config portal IP address 262 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 263 | 264 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 265 | Blynk_WF.setConfigPortalChannel(0); 266 | 267 | // From v1.0.6, select either one of these to set static IP + DNS 268 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 269 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 270 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 271 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 272 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 273 | 274 | ////////////////////////////////////////////// 275 | 276 | #if USING_CUSTOMS_STYLE 277 | Blynk.setCustomsStyle(NewCustomsStyle); 278 | #endif 279 | 280 | #if USING_CUSTOMS_HEAD_ELEMENT 281 | Blynk.setCustomsHeadElement(""); 282 | #endif 283 | 284 | #if USING_CORS_FEATURE 285 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 286 | #endif 287 | 288 | ////////////////////////////////////////////// 289 | 290 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 291 | //Blynk.begin(); 292 | // Use this to personalize DHCP hostname (RFC952 conformed) 293 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 294 | //Blynk.begin("ESP32-BLE-WM"); 295 | 296 | Blynk_WF.begin(BLE_Device_Name); 297 | #else 298 | //Blynk_WF.begin(auth, ssid, pass); 299 | Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 300 | #endif 301 | } 302 | else 303 | { 304 | USE_BLE = true; 305 | Serial.println(F("GPIO14 LOW, Use BLE")); 306 | Blynk_BLE.setDeviceName(BLE_Device_Name); 307 | #if USE_BLYNK_WM 308 | if (Blynk_WF.getBlynkBLEToken() == NO_CONFIG) //String("blank")) 309 | { 310 | Serial.println(F("No valid stored BLE auth. Have to run WiFi then enter config portal")); 311 | USE_BLE = false; 312 | Blynk_WF.begin(BLE_Device_Name); 313 | } 314 | String BLE_auth = Blynk_WF.getBlynkBLEToken(); 315 | #else 316 | String BLE_auth = auth; 317 | #endif 318 | 319 | if (USE_BLE) 320 | { 321 | Serial.print(F("Connecting Blynk via BLE, using auth = ")); 322 | Serial.println(BLE_auth); 323 | Blynk_BLE.begin(BLE_auth.c_str()); 324 | } 325 | } 326 | #endif 327 | 328 | timer.setInterval(5000L, sendDatatoBlynk); 329 | } 330 | 331 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 332 | void displayCredentials() 333 | { 334 | Serial.println(F("\nYour stored Credentials :")); 335 | 336 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 337 | { 338 | Serial.print(myMenuItems[i].displayName); 339 | Serial.print(F(" = ")); 340 | Serial.println(myMenuItems[i].pdata); 341 | } 342 | } 343 | 344 | void displayCredentialsInLoop() 345 | { 346 | static bool displayedCredentials = false; 347 | 348 | if (!displayedCredentials) 349 | { 350 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 351 | { 352 | if (!strlen(myMenuItems[i].pdata)) 353 | { 354 | break; 355 | } 356 | 357 | if ( i == (NUM_MENU_ITEMS - 1) ) 358 | { 359 | displayedCredentials = true; 360 | displayCredentials(); 361 | } 362 | } 363 | } 364 | } 365 | 366 | #endif 367 | 368 | void loop() 369 | { 370 | #if BLYNK_USE_BLE_ONLY 371 | Blynk_BLE.run(); 372 | #else 373 | if (USE_BLE) 374 | Blynk_BLE.run(); 375 | else 376 | Blynk_WF.run(); 377 | #endif 378 | 379 | timer.run(); 380 | checkStatus(); 381 | 382 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 383 | displayCredentialsInLoop(); 384 | #endif 385 | } 386 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_WF/Geiger_Counter_OLED_BT_WF.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Geiger_Counter_OLED_BT_WF.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 34 | #define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 35 | #define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 36 | 37 | // OLED SSD1306 128x32 38 | #define OLED_RESET_PIN 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 39 | #define SCREEN_WIDTH 128 40 | #define SCREEN_HEIGHT 32 41 | 42 | #define CONV_FACTOR 0.00658 43 | 44 | #define DEBOUNCE_TIME_MICRO_SEC 4200L 45 | #define MEASURE_INTERVAL_MS 20000L 46 | #define COUNT_PER_MIN_CONVERSION (60000 / MEASURE_INTERVAL_MS) 47 | #define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 ) 48 | 49 | float voltage = 0; 50 | long countPerMinute = 0; 51 | long timePrevious = 0; 52 | long timePreviousMeassure = 0; 53 | long _time = 0; 54 | long countPrevious = 0; 55 | float radiationValue = 0.0; 56 | float radiationDose = 0; 57 | 58 | void IRAM_ATTR countPulse(); 59 | volatile unsigned long last_micros; 60 | volatile long count = 0; 61 | 62 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET_PIN); 63 | BlynkTimer timer; 64 | 65 | #include 66 | Ticker led_ticker; 67 | 68 | #define BLYNK_PIN_FORCED_CONFIG V10 69 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 70 | 71 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 72 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 73 | { 74 | if (param.asInt()) 75 | { 76 | Serial.println( F("\nCP Button Hit. Rebooting") ); 77 | 78 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 79 | Blynk.resetAndEnterConfigPortal(); 80 | } 81 | } 82 | 83 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 84 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 85 | { 86 | if (param.asInt()) 87 | { 88 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 89 | 90 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 91 | Blynk.resetAndEnterConfigPortalPersistent(); 92 | } 93 | } 94 | 95 | void IRAM_ATTR countPulse() 96 | { 97 | if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) 98 | { 99 | count++; 100 | last_micros = micros(); 101 | } 102 | } 103 | 104 | void sendDatatoBlynk() 105 | { 106 | // For BT 107 | Blynk_BT.virtualWrite(V1, countPerMinute); 108 | Blynk_BT.virtualWrite(V3, radiationValue); 109 | Blynk_BT.virtualWrite(V5, radiationDose); 110 | Blynk_BT.virtualWrite(V7, voltage); 111 | 112 | // For WiFi 113 | Blynk_WF.virtualWrite(V1, countPerMinute); 114 | Blynk_WF.virtualWrite(V3, radiationValue); 115 | Blynk_WF.virtualWrite(V5, radiationDose); 116 | Blynk_WF.virtualWrite(V7, voltage); 117 | 118 | } 119 | 120 | void Serial_Display() 121 | { 122 | Serial.print(F("cpm = ")); 123 | Serial.printf("%4lu", countPerMinute); 124 | Serial.print(F(" - ")); 125 | Serial.print(F("RadiationValue = ")); 126 | Serial.printf("%5.3f", radiationValue); 127 | Serial.print(F(" uSv/h")); 128 | Serial.print(F(" - ")); 129 | Serial.print(F("Equivalent RadiationDose = ")); 130 | Serial.printf("%6.4f", radiationDose); 131 | Serial.println(F(" uSv")); 132 | } 133 | 134 | void OLED_Display() 135 | { 136 | display.setCursor(0, 0); 137 | display.clearDisplay(); 138 | display.setTextSize(1); 139 | display.setTextColor(WHITE); 140 | display.print(countPerMinute, DEC); 141 | display.setCursor(40, 0); 142 | display.print("CPM"); 143 | display.setCursor(0, 10); 144 | display.print(radiationDose, 3); 145 | display.setCursor(40, 10); 146 | display.print("uSv"); 147 | display.setCursor(0, 20); 148 | display.println(voltage, 2); 149 | display.setCursor(40, 20); 150 | display.println("V"); 151 | 152 | if (radiationValue < 9.99) 153 | { 154 | display.setTextSize(2); 155 | } 156 | else 157 | { 158 | display.setTextSize(1); 159 | } 160 | 161 | display.setCursor(65, 10); 162 | display.print(radiationValue, 2); 163 | display.setTextSize(1); 164 | display.setCursor(90, 25); 165 | display.print("uSv/h"); 166 | display.display(); 167 | } 168 | 169 | void set_led(byte status) 170 | { 171 | digitalWrite(LED_BUILTIN, status); 172 | } 173 | 174 | void heartBeatPrint(void) 175 | { 176 | static int num = 1; 177 | 178 | if (Blynk.connected()) 179 | { 180 | set_led(HIGH); 181 | led_ticker.once_ms(111, set_led, (byte) LOW); 182 | Serial.print(F("B")); 183 | } 184 | else 185 | { 186 | Serial.print(F("F")); 187 | } 188 | 189 | if (num == 80) 190 | { 191 | Serial.println(); 192 | num = 1; 193 | } 194 | else if (num++ % 10 == 0) 195 | { 196 | Serial.print(F(" ")); 197 | } 198 | } 199 | 200 | #define USE_SIMULATION true 201 | 202 | void checkStatus() 203 | { 204 | if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS) 205 | { 206 | timePreviousMeassure = millis(); 207 | 208 | noInterrupts(); 209 | countPerMinute = COUNT_PER_MIN_CONVERSION * count; 210 | interrupts(); 211 | 212 | radiationValue = countPerMinute * CONV_FACTOR; 213 | radiationDose = radiationDose + (radiationValue / float(240.0)); 214 | 215 | // can optimize this calculation 216 | voltage = (float) analogRead(VOLTAGER_INPUT_PIN) * VOLTAGE_FACTOR; 217 | 218 | if (radiationDose > 99.999) 219 | { 220 | radiationDose = 0; 221 | } 222 | 223 | Serial_Display(); 224 | OLED_Display(); 225 | 226 | #if USE_SIMULATION 227 | count += 10; 228 | if (count >= 1000) 229 | count = 0; 230 | #else 231 | count = 0; 232 | #endif 233 | 234 | // report Blynk connection 235 | heartBeatPrint(); 236 | } 237 | } 238 | 239 | bool valid_BT_token = false; 240 | 241 | char BT_Device_Name[] = "GeigerCounter-BT"; 242 | 243 | #if USING_CUSTOMS_STYLE 244 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 246 | #endif 247 | 248 | void setup() 249 | { 250 | Serial.begin(115200); 251 | while (!Serial); 252 | 253 | #if (USE_LITTLEFS) 254 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 255 | #elif (USE_SPIFFS) 256 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 257 | #else 258 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 259 | #endif 260 | 261 | #if USE_SSL 262 | Serial.print(F(" with SSL on ")); 263 | #else 264 | Serial.print(F(" without SSL on ")); 265 | #endif 266 | 267 | Serial.println(ARDUINO_BOARD); 268 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 269 | 270 | #if USE_BLYNK_WM 271 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 272 | #endif 273 | 274 | pinMode(GEIGER_INPUT_PIN, INPUT); 275 | attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH); 276 | 277 | if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 278 | Serial.println(F("SSD1306 allocation failed")); 279 | for (;;); 280 | } 281 | display.display(); 282 | delay(200); 283 | display.clearDisplay(); 284 | 285 | Serial.println(F("Use WiFi to connect Blynk")); 286 | 287 | #if USE_BLYNK_WM 288 | // Set config portal SSID and Password 289 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 290 | // Set config portal IP address 291 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 292 | 293 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 294 | Blynk_WF.setConfigPortalChannel(0); 295 | 296 | // From v1.0.6, select either one of these to set static IP + DNS 297 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 298 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 299 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 300 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 301 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 302 | 303 | ////////////////////////////////////////////// 304 | 305 | #if USING_CUSTOMS_STYLE 306 | Blynk.setCustomsStyle(NewCustomsStyle); 307 | #endif 308 | 309 | #if USING_CUSTOMS_HEAD_ELEMENT 310 | Blynk.setCustomsHeadElement(""); 311 | #endif 312 | 313 | #if USING_CORS_FEATURE 314 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 315 | #endif 316 | 317 | ////////////////////////////////////////////// 318 | 319 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 320 | //Blynk.begin(); 321 | // Use this to personalize DHCP hostname (RFC952 conformed) 322 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 323 | //Blynk.begin("ESP32-BT-WM"); 324 | 325 | Blynk_WF.begin(BT_Device_Name); 326 | #else 327 | //Blynk_WF.begin(WiFi_auth, ssid, pass); 328 | Blynk_WF.begin(WiFi_auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 329 | #endif 330 | 331 | Serial.println(F("Use BT to connect Blynk")); 332 | Blynk_BT.setDeviceName(BT_Device_Name); 333 | 334 | #if USE_BLYNK_WM 335 | String BT_auth = Blynk_WF.getBlynkBTToken(); 336 | Serial.print(F("BT_auth = ")); 337 | Serial.println(BT_auth); 338 | 339 | if (BT_auth == NO_CONFIG) //String("blank")) 340 | { 341 | Serial.println(F("No valid stored BT auth. Have to run WiFi then enter config portal")); 342 | valid_BT_token = false; 343 | } 344 | else 345 | { 346 | valid_BT_token = true; 347 | Blynk_BT.begin(BT_auth.c_str()); 348 | } 349 | 350 | #else 351 | Blynk_BT.begin(BT_auth); 352 | #endif 353 | 354 | timer.setInterval(5000L, sendDatatoBlynk); 355 | } 356 | 357 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 358 | void displayCredentials() 359 | { 360 | Serial.println(F("\nYour stored Credentials :")); 361 | 362 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 363 | { 364 | Serial.print(myMenuItems[i].displayName); 365 | Serial.print(F(" = ")); 366 | Serial.println(myMenuItems[i].pdata); 367 | } 368 | } 369 | 370 | void displayCredentialsInLoop() 371 | { 372 | static bool displayedCredentials = false; 373 | 374 | if (!displayedCredentials) 375 | { 376 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 377 | { 378 | if (!strlen(myMenuItems[i].pdata)) 379 | { 380 | break; 381 | } 382 | 383 | if ( i == (NUM_MENU_ITEMS - 1) ) 384 | { 385 | displayedCredentials = true; 386 | displayCredentials(); 387 | } 388 | } 389 | } 390 | } 391 | 392 | #endif 393 | 394 | void loop() 395 | { 396 | if (valid_BT_token) 397 | Blynk_BT.run(); 398 | 399 | Blynk_WF.run(); 400 | timer.run(); 401 | checkStatus(); 402 | 403 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 404 | displayCredentialsInLoop(); 405 | #endif 406 | } 407 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED/Geiger_Counter_OLED.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Geiger_Counter_OLED.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | bool USE_BT = true; 34 | 35 | #define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 36 | #define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 37 | #define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 38 | 39 | // OLED SSD1306 128x32 40 | #define OLED_RESET_PIN 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 41 | #define SCREEN_WIDTH 128 42 | #define SCREEN_HEIGHT 32 43 | 44 | #define CONV_FACTOR 0.00658 45 | 46 | #define DEBOUNCE_TIME_MICRO_SEC 4200L 47 | #define MEASURE_INTERVAL_MS 20000L 48 | #define COUNT_PER_MIN_CONVERSION (60000 / MEASURE_INTERVAL_MS) 49 | #define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 ) 50 | 51 | float voltage = 0; 52 | long countPerMinute = 0; 53 | long timePrevious = 0; 54 | long timePreviousMeassure = 0; 55 | long _time = 0; 56 | long countPrevious = 0; 57 | float radiationValue = 0.0; 58 | float radiationDose = 0; 59 | 60 | void IRAM_ATTR countPulse(); 61 | volatile unsigned long last_micros; 62 | volatile long count = 0; 63 | 64 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET_PIN); 65 | BlynkTimer timer; 66 | 67 | #include 68 | Ticker led_ticker; 69 | 70 | #define BLYNK_PIN_FORCED_CONFIG V10 71 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 72 | 73 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 74 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 75 | { 76 | if (param.asInt()) 77 | { 78 | Serial.println( F("\nCP Button Hit. Rebooting") ); 79 | 80 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 81 | Blynk.resetAndEnterConfigPortal(); 82 | } 83 | } 84 | 85 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 86 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 87 | { 88 | if (param.asInt()) 89 | { 90 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 91 | 92 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 93 | Blynk.resetAndEnterConfigPortalPersistent(); 94 | } 95 | } 96 | 97 | void IRAM_ATTR countPulse() 98 | { 99 | if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) 100 | { 101 | count++; 102 | last_micros = micros(); 103 | } 104 | } 105 | 106 | void sendDatatoBlynk() 107 | { 108 | #if BLYNK_USE_BT_ONLY 109 | Blynk_BT.virtualWrite(V1, countPerMinute); 110 | Blynk_BT.virtualWrite(V3, radiationValue); 111 | Blynk_BT.virtualWrite(V5, radiationDose); 112 | Blynk_BT.virtualWrite(V7, voltage); 113 | #else 114 | if (USE_BT) 115 | { 116 | Blynk_BT.virtualWrite(V1, countPerMinute); 117 | Blynk_BT.virtualWrite(V3, radiationValue); 118 | Blynk_BT.virtualWrite(V5, radiationDose); 119 | Blynk_BT.virtualWrite(V7, voltage); 120 | } 121 | else 122 | { 123 | Blynk_WF.virtualWrite(V1, countPerMinute); 124 | Blynk_WF.virtualWrite(V3, radiationValue); 125 | Blynk_WF.virtualWrite(V5, radiationDose); 126 | Blynk_WF.virtualWrite(V7, voltage); 127 | } 128 | #endif 129 | } 130 | 131 | void Serial_Display() 132 | { 133 | Serial.print(F("cpm = ")); 134 | Serial.printf("%4lu", countPerMinute); 135 | Serial.print(F(" - ")); 136 | Serial.print(F("RadiationValue = ")); 137 | Serial.printf("%5.3f", radiationValue); 138 | Serial.print(F(" uSv/h")); 139 | Serial.print(F(" - ")); 140 | Serial.print(F("Equivalent RadiationDose = ")); 141 | Serial.printf("%6.4f", radiationDose); 142 | Serial.println(F(" uSv")); 143 | } 144 | 145 | void OLED_Display() 146 | { 147 | display.setCursor(0, 0); 148 | display.clearDisplay(); 149 | display.setTextSize(1); 150 | display.setTextColor(WHITE); 151 | display.print(countPerMinute, DEC); 152 | display.setCursor(40, 0); 153 | display.print("CPM"); 154 | display.setCursor(0, 10); 155 | display.print(radiationDose, 3); 156 | display.setCursor(40, 10); 157 | display.print("uSv"); 158 | display.setCursor(0, 20); 159 | display.println(voltage, 2); 160 | display.setCursor(40, 20); 161 | display.println("V"); 162 | 163 | if (radiationValue < 9.99) 164 | { 165 | display.setTextSize(2); 166 | } 167 | else 168 | { 169 | display.setTextSize(1); 170 | } 171 | 172 | display.setCursor(65, 10); 173 | display.print(radiationValue, 2); 174 | display.setTextSize(1); 175 | display.setCursor(90, 25); 176 | display.print("uSv/h"); 177 | display.display(); 178 | } 179 | 180 | void set_led(byte status) 181 | { 182 | digitalWrite(LED_BUILTIN, status); 183 | } 184 | 185 | void heartBeatPrint(void) 186 | { 187 | static int num = 1; 188 | 189 | if (Blynk.connected()) 190 | { 191 | set_led(HIGH); 192 | led_ticker.once_ms(111, set_led, (byte) LOW); 193 | Serial.print(F("B")); 194 | } 195 | else 196 | { 197 | Serial.print(F("F")); 198 | } 199 | 200 | if (num == 80) 201 | { 202 | Serial.println(); 203 | num = 1; 204 | } 205 | else if (num++ % 10 == 0) 206 | { 207 | Serial.print(F(" ")); 208 | } 209 | } 210 | 211 | #define USE_SIMULATION false 212 | 213 | void checkStatus() 214 | { 215 | if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS) 216 | { 217 | timePreviousMeassure = millis(); 218 | 219 | noInterrupts(); 220 | countPerMinute = COUNT_PER_MIN_CONVERSION * count; 221 | interrupts(); 222 | 223 | radiationValue = countPerMinute * CONV_FACTOR; 224 | radiationDose = radiationDose + (radiationValue / float(240.0)); 225 | 226 | // can optimize this calculation 227 | voltage = (float) analogRead(VOLTAGER_INPUT_PIN) * VOLTAGE_FACTOR; 228 | 229 | if (radiationDose > 99.999) 230 | { 231 | radiationDose = 0; 232 | } 233 | 234 | Serial_Display(); 235 | OLED_Display(); 236 | 237 | #if USE_SIMULATION 238 | count += 10; 239 | if (count >= 1000) 240 | count = 0; 241 | #else 242 | count = 0; 243 | #endif 244 | 245 | // report Blynk connection 246 | heartBeatPrint(); 247 | } 248 | } 249 | 250 | char BT_Device_Name[] = "GeigerCounter-BT"; 251 | 252 | #if USING_CUSTOMS_STYLE 253 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 255 | #endif 256 | 257 | void setup() 258 | { 259 | Serial.begin(115200); 260 | while (!Serial); 261 | 262 | #if (USE_LITTLEFS) 263 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 264 | #elif (USE_SPIFFS) 265 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 266 | #else 267 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 268 | #endif 269 | 270 | #if USE_SSL 271 | Serial.print(F(" with SSL on ")); 272 | #else 273 | Serial.print(F(" without SSL on ")); 274 | #endif 275 | 276 | Serial.println(ARDUINO_BOARD); 277 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 278 | 279 | #if USE_BLYNK_WM 280 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 281 | #endif 282 | 283 | pinMode(GEIGER_INPUT_PIN, INPUT); 284 | attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH); 285 | 286 | if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 287 | Serial.println(F("SSD1306 allocation failed")); 288 | for (;;); 289 | } 290 | display.display(); 291 | delay(200); 292 | display.clearDisplay(); 293 | 294 | #if BLYNK_USE_BT_ONLY 295 | Blynk_BT.setDeviceName(BT_Device_Name); 296 | Blynk_BT.begin(auth); 297 | #else 298 | if (digitalRead(WIFI_BT_SELECTION_PIN) == HIGH) 299 | { 300 | USE_BT = false; 301 | Serial.println(F("GPIO14 HIGH, Use WiFi")); 302 | #if USE_BLYNK_WM 303 | // Set config portal SSID and Password 304 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 305 | // Set config portal IP address 306 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 307 | 308 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 309 | Blynk_WF.setConfigPortalChannel(0); 310 | 311 | // From v1.0.6, select either one of these to set static IP + DNS 312 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 313 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 314 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 315 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 316 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 317 | 318 | ////////////////////////////////////////////// 319 | 320 | #if USING_CUSTOMS_STYLE 321 | Blynk.setCustomsStyle(NewCustomsStyle); 322 | #endif 323 | 324 | #if USING_CUSTOMS_HEAD_ELEMENT 325 | Blynk.setCustomsHeadElement(""); 326 | #endif 327 | 328 | #if USING_CORS_FEATURE 329 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 330 | #endif 331 | 332 | ////////////////////////////////////////////// 333 | 334 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 335 | //Blynk.begin(); 336 | // Use this to personalize DHCP hostname (RFC952 conformed) 337 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 338 | //Blynk.begin("ESP32-BT-WM"); 339 | 340 | Blynk_WF.begin(BT_Device_Name); 341 | #else 342 | //Blynk_WF.begin(auth, ssid, pass); 343 | Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 344 | #endif 345 | } 346 | else 347 | { 348 | USE_BT = true; 349 | Serial.println(F("GPIO14 LOW, Use BT")); 350 | Blynk_BT.setDeviceName(BT_Device_Name); 351 | #if USE_BLYNK_WM 352 | if (Blynk_WF.getBlynkBTToken() == NO_CONFIG) //String("blank")) 353 | { 354 | Serial.println(F("No valid stored BT auth. Have to run WiFi then enter config portal")); 355 | USE_BT = false; 356 | Blynk_WF.begin(BT_Device_Name); 357 | } 358 | String BT_auth = Blynk_WF.getBlynkBTToken(); 359 | #else 360 | String BT_auth = auth; 361 | #endif 362 | 363 | if (USE_BT) 364 | { 365 | Serial.print(F("Connecting Blynk via BT, using auth = ")); 366 | Serial.println(BT_auth); 367 | Blynk_BT.begin(BT_auth.c_str()); 368 | } 369 | } 370 | #endif 371 | 372 | timer.setInterval(5000L, sendDatatoBlynk); 373 | } 374 | 375 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 376 | void displayCredentials() 377 | { 378 | Serial.println(F("\nYour stored Credentials :")); 379 | 380 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 381 | { 382 | Serial.print(myMenuItems[i].displayName); 383 | Serial.print(F(" = ")); 384 | Serial.println(myMenuItems[i].pdata); 385 | } 386 | } 387 | 388 | void displayCredentialsInLoop() 389 | { 390 | static bool displayedCredentials = false; 391 | 392 | if (!displayedCredentials) 393 | { 394 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 395 | { 396 | if (!strlen(myMenuItems[i].pdata)) 397 | { 398 | break; 399 | } 400 | 401 | if ( i == (NUM_MENU_ITEMS - 1) ) 402 | { 403 | displayedCredentials = true; 404 | displayCredentials(); 405 | } 406 | } 407 | } 408 | } 409 | 410 | #endif 411 | 412 | void loop() 413 | { 414 | #if BLYNK_USE_BT_ONLY 415 | Blynk_BT.run(); 416 | #else 417 | if (USE_BT) 418 | Blynk_BT.run(); 419 | else 420 | Blynk_WF.run(); 421 | #endif 422 | 423 | timer.run(); 424 | checkStatus(); 425 | 426 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 427 | displayCredentialsInLoop(); 428 | #endif 429 | } 430 | -------------------------------------------------------------------------------- /examples/Geiger_Counter_OLED_BT_BLE_WF/Geiger_Counter_OLED_BT_BLE_WF.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Geiger_Counter_OLED_BT_BLE_WF.ino 3 | For ESP32 using WiFi along with BlueTooth BLE 4 | 5 | BlynkESP32_BT_WF is a library for inclusion of both ESP32 Blynk BT/BLE and WiFi libraries. 6 | Then select either one or both at runtime. 7 | 8 | Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /**************************************************************************************************************************** 13 | Important Notes: 14 | 1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true 15 | 2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false 16 | 3) To conmpile, use Partition Scheem with large APP size, such as 17 | a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM 18 | b) No OTA (2MB APP, 2MB SPIFFS) 19 | c) No OTA (2MB APP, 2MB FATFS) if use EEPROM 20 | d) Huge APP (3MB No OTA, 1MB SPIFFS) <===== Preferable if use SPIFFS 21 | e) Minimal SPIFFS (1.9MB APP with OTA, 190KB SPIFFS) 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | #include "Credentials.h" 26 | #include "dynamicParams.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define WIFI_BT_SELECTION_PIN 14 //Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 34 | #define GEIGER_INPUT_PIN 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 35 | #define VOLTAGER_INPUT_PIN 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 36 | 37 | // OLED SSD1306 128x32 38 | #define OLED_RESET_PIN 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 39 | #define SCREEN_WIDTH 128 40 | #define SCREEN_HEIGHT 32 41 | 42 | #define CONV_FACTOR 0.00658 43 | 44 | #define DEBOUNCE_TIME_MICRO_SEC 4200L 45 | #define MEASURE_INTERVAL_MS 20000L 46 | #define COUNT_PER_MIN_CONVERSION (60000 / MEASURE_INTERVAL_MS) 47 | #define VOLTAGE_FACTOR ( ( 4.2 * (3667 / 3300) ) / 4096 ) 48 | 49 | float voltage = 0; 50 | long countPerMinute = 0; 51 | long timePrevious = 0; 52 | long timePreviousMeassure = 0; 53 | long _time = 0; 54 | long countPrevious = 0; 55 | float radiationValue = 0.0; 56 | float radiationDose = 0; 57 | 58 | void IRAM_ATTR countPulse(); 59 | volatile unsigned long last_micros; 60 | volatile long count = 0; 61 | 62 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET_PIN); 63 | BlynkTimer timer; 64 | 65 | #include 66 | Ticker led_ticker; 67 | 68 | #define BLYNK_PIN_FORCED_CONFIG V10 69 | #define BLYNK_PIN_FORCED_PERS_CONFIG V20 70 | 71 | // Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal 72 | BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG) 73 | { 74 | if (param.asInt()) 75 | { 76 | Serial.println( F("\nCP Button Hit. Rebooting") ); 77 | 78 | // This will keep CP once, clear after reset, even you didn't enter CP at all. 79 | Blynk.resetAndEnterConfigPortal(); 80 | } 81 | } 82 | 83 | // Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal 84 | BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG) 85 | { 86 | if (param.asInt()) 87 | { 88 | Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 89 | 90 | // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. 91 | Blynk.resetAndEnterConfigPortalPersistent(); 92 | } 93 | } 94 | 95 | void IRAM_ATTR countPulse() 96 | { 97 | if ((long)(micros() - last_micros) >= DEBOUNCE_TIME_MICRO_SEC) 98 | { 99 | count++; 100 | last_micros = micros(); 101 | } 102 | } 103 | 104 | void sendDatatoBlynk() 105 | { 106 | #if USE_BLE_NOT_BT 107 | // For BLE 108 | Blynk_BLE.virtualWrite(V1, countPerMinute); 109 | Blynk_BLE.virtualWrite(V3, radiationValue); 110 | Blynk_BLE.virtualWrite(V5, radiationDose); 111 | Blynk_BLE.virtualWrite(V7, voltage); 112 | #else 113 | // For BT 114 | Blynk_BT.virtualWrite(V1, countPerMinute); 115 | Blynk_BT.virtualWrite(V3, radiationValue); 116 | Blynk_BT.virtualWrite(V5, radiationDose); 117 | Blynk_BT.virtualWrite(V7, voltage); 118 | #endif 119 | 120 | // For WiFi 121 | Blynk_WF.virtualWrite(V1, countPerMinute); 122 | Blynk_WF.virtualWrite(V3, radiationValue); 123 | Blynk_WF.virtualWrite(V5, radiationDose); 124 | Blynk_WF.virtualWrite(V7, voltage); 125 | 126 | } 127 | 128 | void Serial_Display() 129 | { 130 | Serial.print(F("cpm = ")); 131 | Serial.printf("%4lu", countPerMinute); 132 | Serial.print(F(" - ")); 133 | Serial.print(F("RadiationValue = ")); 134 | Serial.printf("%5.3f", radiationValue); 135 | Serial.print(F(" uSv/h")); 136 | Serial.print(F(" - ")); 137 | Serial.print(F("Equivalent RadiationDose = ")); 138 | Serial.printf("%6.4f", radiationDose); 139 | Serial.println(F(" uSv")); 140 | } 141 | 142 | 143 | void OLED_Display() 144 | { 145 | display.setCursor(0, 0); 146 | display.clearDisplay(); 147 | display.setTextSize(1); 148 | display.setTextColor(WHITE); 149 | display.print(countPerMinute, DEC); 150 | display.setCursor(40, 0); 151 | display.print("CPM"); 152 | display.setCursor(0, 10); 153 | display.print(radiationDose, 3); 154 | display.setCursor(40, 10); 155 | display.print("uSv"); 156 | display.setCursor(0, 20); 157 | display.println(voltage, 2); 158 | display.setCursor(40, 20); 159 | display.println("V"); 160 | 161 | if (radiationValue < 9.99) 162 | { 163 | display.setTextSize(2); 164 | } 165 | else 166 | { 167 | display.setTextSize(1); 168 | } 169 | 170 | display.setCursor(65, 10); 171 | display.print(radiationValue, 2); 172 | display.setTextSize(1); 173 | display.setCursor(90, 25); 174 | display.print("uSv/h"); 175 | display.display(); 176 | } 177 | 178 | void set_led(byte status) 179 | { 180 | digitalWrite(LED_BUILTIN, status); 181 | } 182 | 183 | void heartBeatPrint(void) 184 | { 185 | static int num = 1; 186 | 187 | if (Blynk.connected()) 188 | { 189 | set_led(HIGH); 190 | led_ticker.once_ms(111, set_led, (byte) LOW); 191 | Serial.print(F("B")); 192 | } 193 | else 194 | { 195 | Serial.print(F("F")); 196 | } 197 | 198 | if (num == 80) 199 | { 200 | Serial.println(); 201 | num = 1; 202 | } 203 | else if (num++ % 10 == 0) 204 | { 205 | Serial.print(F(" ")); 206 | } 207 | } 208 | 209 | #define USE_SIMULATION true 210 | 211 | void checkStatus() 212 | { 213 | if (millis() - timePreviousMeassure > MEASURE_INTERVAL_MS) 214 | { 215 | timePreviousMeassure = millis(); 216 | 217 | noInterrupts(); 218 | countPerMinute = COUNT_PER_MIN_CONVERSION * count; 219 | interrupts(); 220 | 221 | radiationValue = countPerMinute * CONV_FACTOR; 222 | radiationDose = radiationDose + (radiationValue / float(240.0)); 223 | 224 | // can optimize this calculation 225 | voltage = (float) analogRead(VOLTAGER_INPUT_PIN) * VOLTAGE_FACTOR; 226 | 227 | if (radiationDose > 99.999) 228 | { 229 | radiationDose = 0; 230 | } 231 | 232 | Serial_Display(); 233 | OLED_Display(); 234 | 235 | #if USE_SIMULATION 236 | count += 10; 237 | if (count >= 1000) 238 | count = 0; 239 | #else 240 | count = 0; 241 | #endif 242 | 243 | // report Blynk connection 244 | heartBeatPrint(); 245 | } 246 | } 247 | 248 | bool valid_BT_BLE_token = false; 249 | char BLE_Device_Name[] = "GeigerCounter-BLE"; 250 | char BT_Device_Name[] = "GeigerCounter-BT"; 251 | 252 | #if USING_CUSTOMS_STYLE 253 | const char NewCustomsStyle[] /*PROGMEM*/ = ""; 255 | #endif 256 | 257 | void setup() 258 | { 259 | Serial.begin(115200); 260 | while (!Serial); 261 | 262 | #if (USE_LITTLEFS) 263 | Serial.print(F("\nStarting ESP32_BLE_WF using LITTLEFS")); 264 | #elif (USE_SPIFFS) 265 | Serial.print(F("\nStarting ESP32_BLE_WF using SPIFFS")); 266 | #else 267 | Serial.print(F("\nStarting ESP32_BLE_WF using EEPROM")); 268 | #endif 269 | 270 | #if USE_SSL 271 | Serial.print(F(" with SSL on ")); 272 | #else 273 | Serial.print(F(" without SSL on ")); 274 | #endif 275 | 276 | Serial.println(ARDUINO_BOARD); 277 | Serial.println(BLYNK_ESP32_BT_WF_VERSION); 278 | 279 | #if USE_BLYNK_WM 280 | Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); 281 | #endif 282 | 283 | pinMode(GEIGER_INPUT_PIN, INPUT); 284 | attachInterrupt(GEIGER_INPUT_PIN, countPulse, HIGH); 285 | 286 | if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 287 | Serial.println(F("SSD1306 allocation failed")); 288 | for (;;); 289 | } 290 | display.display(); 291 | delay(200); 292 | display.clearDisplay(); 293 | 294 | Serial.println(F("Use WiFi to connect Blynk")); 295 | 296 | #if USE_BLYNK_WM 297 | // Set config portal SSID and Password 298 | Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); 299 | // Set config portal IP address 300 | Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); 301 | 302 | // Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict 303 | Blynk_WF.setConfigPortalChannel(0); 304 | 305 | // From v1.0.6, select either one of these to set static IP + DNS 306 | Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); 307 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 308 | // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); 309 | //Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), 310 | // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); 311 | 312 | ////////////////////////////////////////////// 313 | 314 | #if USING_CUSTOMS_STYLE 315 | Blynk.setCustomsStyle(NewCustomsStyle); 316 | #endif 317 | 318 | #if USING_CUSTOMS_HEAD_ELEMENT 319 | Blynk.setCustomsHeadElement(""); 320 | #endif 321 | 322 | #if USING_CORS_FEATURE 323 | Blynk.setCORSHeader("Your Access-Control-Allow-Origin"); 324 | #endif 325 | 326 | ////////////////////////////////////////////// 327 | 328 | // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX 329 | //Blynk.begin(); 330 | // Use this to personalize DHCP hostname (RFC952 conformed) 331 | // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char 332 | //Blynk.begin("ESP32-BT-WM"); 333 | 334 | Blynk_WF.begin("GeigerCounter-WiFi"); 335 | #else 336 | //Blynk_WF.begin(WiFi_auth, ssid, pass); 337 | Blynk_WF.begin(WiFi_auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT); 338 | #endif 339 | 340 | #if USE_BLE_NOT_BT 341 | Serial.println(F("Use BLE to connect Blynk")); 342 | Blynk_BLE.setDeviceName(BLE_Device_Name); 343 | 344 | #if USE_BLYNK_WM 345 | String BLE_auth = Blynk_WF.getBlynkBLEToken(); 346 | Serial.print(F("BLE_auth = ")); 347 | Serial.println(BLE_auth); 348 | 349 | if (BLE_auth == NO_CONFIG) //String("blank")) 350 | { 351 | Serial.println(F("No valid stored BLE auth. Have to run WiFi then enter config portal")); 352 | valid_BT_BLE_token = false; 353 | } 354 | else 355 | { 356 | valid_BT_BLE_token = true; 357 | Blynk_BLE.begin(BLE_auth.c_str()); 358 | } 359 | 360 | #else 361 | Blynk_BLE.begin(BLE_auth); 362 | #endif 363 | 364 | #else 365 | Serial.println(F("Use BT to connect Blynk")); 366 | Blynk_BT.setDeviceName(BT_Device_Name); 367 | 368 | #if USE_BLYNK_WM 369 | String BT_auth = Blynk_WF.getBlynkBTToken(); 370 | Serial.print(F("BT_auth = ")); 371 | Serial.println(BT_auth); 372 | 373 | if (BT_auth == NO_CONFIG) //String("blank")) 374 | { 375 | Serial.println(F("No valid stored BT auth. Have to run WiFi then enter config portal")); 376 | valid_BT_BLE_token = false; 377 | } 378 | else 379 | { 380 | valid_BT_BLE_token = true; 381 | Blynk_BT.begin(BT_auth.c_str()); 382 | } 383 | 384 | #else 385 | Blynk_BT.begin(BT_auth); 386 | #endif 387 | 388 | #endif 389 | 390 | timer.setInterval(5000L, sendDatatoBlynk); 391 | } 392 | 393 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 394 | void displayCredentials() 395 | { 396 | Serial.println(F("\nYour stored Credentials :")); 397 | 398 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 399 | { 400 | Serial.print(myMenuItems[i].displayName); 401 | Serial.print(F(" = ")); 402 | Serial.println(myMenuItems[i].pdata); 403 | } 404 | } 405 | 406 | void displayCredentialsInLoop() 407 | { 408 | static bool displayedCredentials = false; 409 | 410 | if (!displayedCredentials) 411 | { 412 | for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) 413 | { 414 | if (!strlen(myMenuItems[i].pdata)) 415 | { 416 | break; 417 | } 418 | 419 | if ( i == (NUM_MENU_ITEMS - 1) ) 420 | { 421 | displayedCredentials = true; 422 | displayCredentials(); 423 | } 424 | } 425 | } 426 | } 427 | 428 | #endif 429 | 430 | void loop() 431 | { 432 | if (valid_BT_BLE_token) 433 | { 434 | #if USE_BLE_NOT_BT 435 | Blynk_BLE.run(); 436 | #else 437 | Blynk_BT.run(); 438 | #endif 439 | } 440 | 441 | Blynk_WF.run(); 442 | timer.run(); 443 | checkStatus(); 444 | 445 | #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) 446 | displayCredentialsInLoop(); 447 | #endif 448 | } 449 | --------------------------------------------------------------------------------