I just added a bluetooth serial connection to my ESP32 project to send data back to a laptop. About 13k/second is being sent 130 bytes every 10ms. The throughput very slow, it stutters with frequent pauses.
I wrote a simple test program and found out that when Blynk is not active, the data comes through full speed but once Blynk.begin is called the bluetooth serial connection pauses, stutters and doesn’t run full speed. You don’t have to be doing anything with Blynk, just starting it up is enough to cause problems. Doesn’t matter if you call Blynk.run or not, same problem either way.
Here is test code. Fill in an app key and wifi info. As is it should work fine, just load it on an ESP32, pair to a bluetooth capable PC and open the COM port with a terminal program like putty. If you uncomment the Blynk.begin line the output on the PC should be slower and stutter.
#include "BluetoothSerial.h"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
unsigned long
loop_start,
next_loop;
int
barber_pole=10;
uint8_t
buff[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz!@#$%^\n";
uint8_t newline[]="\n";
const char auth[] = "your key";
const char ssid[] = "your ssid";
const char pass[] = "your pass";
void setup() {
Serial.begin(115200);
SerialBT.begin("yourname"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
loop_start = micros();
next_loop = 0;
// Blynk.begin(auth, ssid, pass);
}
void loop() {
int i;
if((loop_start=micros()) < next_loop)
return;
next_loop = loop_start + 10000; // every 10ms (100hz)
if(barber_pole < 130)
barber_pole++;
else
barber_pole = 10;
i = SerialBT.write(buff,barber_pole);
Serial.println(i);
i = SerialBT.write(newline,1);
// Blynk.run();
}```