How To Install Using Arduino Library Manager
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.
Now from Version 1.0.2, you can eliminate hardcoding
your Wifi and Blynk credentials, thanks to the Smart Config Portal
, and have Credentials (WiFi SID/PW, Blynk WiFi/BT/BLE Tokens/ Hardware Port) saved in either SPIFFS or EEPROM.
Sample Code
#define BLYNK_PRINT Serial
#define USE_BLYNK_WM true
//#define USE_BLYNK_WM false
#define USE_SPIFFS true
//#define USE_SPIFFS false
#if (!USE_SPIFFS)
// EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE
#define EEPROM_SIZE (2 * 1024)
// EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE
#define EEPROM_START 768
#endif
// Force some params in Blynk, only valid for library version 1.0.1 and later
#define TIMEOUT_RECONNECT_WIFI 10000L
#define RESET_IF_CONFIG_TIMEOUT true
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
// Those above #define's must be placed before #include <BlynkSimpleEsp32_WFM.h>
//#define BLYNK_USE_BLE_ONLY true
#define BLYNK_USE_BLE_ONLY false
#include <BlynkSimpleEsp32_BLE_WF.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#if !BLYNK_USE_BLE_ONLY
#if USE_BLYNK_WM
#warning Please select 1.3MB+ for APP (Minimal SPIFFS (1.9MB APP, OTA), HugeAPP(3MB APP, NoOTA) or NoOA(2MB APP)
#include <BlynkSimpleEsp32_WFM.h>
#else
#include <BlynkSimpleEsp32_WF.h>
String cloudBlynkServer = "account.duckdns.org";
//String cloudBlynkServer = "192.168.2.110";
#define BLYNK_SERVER_HARDWARE_PORT 8080
char ssid[] = "SSID";
char pass[] = "PASS";
#endif
#endif
#if (BLYNK_USE_BLE_ONLY || !USE_BLYNK_WM)
// Blynk token shared between BLE and WiFi
char auth[] = "****";
#endif
bool USE_BLE = true;
void setup()
{
Serial.begin(115200);
Serial.println(F("\nStarting ESP32_BLE_WF"));
pinMode(WIFI_BLE_SELECTION_PIN, INPUT);
#if BLYNK_USE_BLE_ONLY
Blynk_BLE.setDeviceName(BLE_Device_Name);
Blynk_BLE.begin(auth);
#else
if (digitalRead(WIFI_BLE_SELECTION_PIN) == HIGH)
{
USE_BLE = false;
Serial.println(F("GPIO14 HIGH, Use WiFi"));
#if USE_BLYNK_WM
Blynk_WF.begin(BLE_Device_Name);
#else
Blynk_WF.begin(auth, ssid, pass, cloudBlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
#endif
}
else
{
USE_BLE = true;
Serial.println(F("GPIO14 LOW, Use BLE"));
Blynk_BLE.setDeviceName(BLE_Device_Name);
#if USE_BLYNK_WM
if (Blynk_WF.getBlynkBLEToken() == String("nothing"))
{
Serial.println(F("No valid stored BLE auth. Have to run WiFi then enter config portal"));
USE_BLE = false;
Blynk_WF.begin(BLE_Device_Name);
}
String BLE_auth = Blynk_WF.getBlynkBLEToken();
#else
String BLE_auth = auth;
#endif
if (USE_BLE)
{
Serial.print(F("Connecting Blynk via BLE, using auth = "));
Serial.println(BLE_auth);
Blynk_BLE.begin(BLE_auth.c_str());
}
}
#endif
}
void loop()
{
#if BLYNK_USE_BLE_ONLY
Blynk_BLE.run();
#else
if (USE_BLE)
Blynk_BLE.run();
else
Blynk_WF.run();
#endif
}
and this is the terminal debug output when running both WiFi and BT at the same time using example ESP32_BLE_WF
Starting ESP32_BLE_WF
GPIO14 LOW, Use BLE
[51] Load configfile
[52] OK
[52] Header = ESP32_WFM, SSID = ***, PW = ***
[52] Server = account.duckdns.org, Port = 8080, Token = ****
[56] BT Token = ****, BLE Token = ****
[64] Board Name = Geiger-OLED-BLE-BT
Connecting Blynk via BLE, using auth = ****
[149]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.6.1 on ESP32
[75491] BLE connect
[77327] Ready
This is the link to Blynk
Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it and do many other cool things.
You can install and use Local Blynk Server (RPi Zero W, 3B+, 4, Laptop, PC, etc) to have full control.
The Server source code is in Public Domain and written in Java. You can download, compile and use to be sure having full control.