SerialBT periodically stutters and breaks messages

SuperFire101
Posts: 2
Joined: Wed Mar 27, 2024 8:07 pm

SerialBT periodically stutters and breaks messages

Postby SuperFire101 » Wed Mar 27, 2024 10:22 pm

Hey!

I am working on a DIY IoT project with my kid (we're building a piano! :D ) involving connecting our esp32 (WROOM32) over Bluetooth to my Android smartphone and transmitting continuous sensors' readings (hopefully at around 10Hz).

The issue we're facing is that every several seconds (periodically!) the SerialBT messages jam/lag/tear-up on the receiving end for about 3 seconds at a time, and this jumbles my entire application, as we need to parse the sensors' readings in real-time.

On a normal wired Serial connection, there is no issue and the messages flow like a charm, even when lagging in a Serial-Bluetooth connection in parallel.

To debug this issue, we've written a very minimal code - that only connects via SerialBT and sends the same message over & over again, with a 100ms delay (attached below).

We've ruled out the following possible problems:

Disconnected all sensors/cables

Tried 3 different ESP32s to try and rule out defective modules (but still a possibility)

Tried 2 Android phones to rule out phone problem

Using the "Serial Bluetooth Terminal" app on Android to rule out any bugs in our app

Ran it over a battery in an elevator to rule out radio-wave interference

What could cause this issue??

Please help us! The kid (& me lol) are losing interest as we've hit this unsolvable problem that no one on the internet seems to have encountered/solved :roll:

Thanks in advance!

Code: Select all

/*##### delay solver #####*/
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
String packet = "1,2,3,4,5,6,7,8";
void setup() {
Serial.begin(115200);
  // BT CONNECT
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
delay(100);
SerialBT.println(packet);
Serial.println(packet);
}

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: SerialBT periodically stutters and breaks messages

Postby lbernstone » Sat Mar 30, 2024 7:23 pm

I don't have a good answer for you, other than you are asking the system to do too much. Here's a couple recommendations
1) I doubt you really need the data every 100ms. Collect 10 data points and send them in a single packet. This is a lot less network overhead, and easier to sequence.
2) Bluetooth classic is not nearly as efficient in resources as BLE. The NimBLE Server example won't take a lot of modification to send your data, and gives you a lot more ability to pre-define what the data should look like. It will use less memory on the device, and on newer MCUs can use the 2M data rate.

SuperFire101
Posts: 2
Joined: Wed Mar 27, 2024 8:07 pm

Re: SerialBT periodically stutters and breaks messages

Postby SuperFire101 » Sun Mar 31, 2024 1:39 pm

Thanks a lot! will look into that.
And a general update: it is probably somehow related to a Samsung/Galaxy software issue. We've tried 2 Samsung phones that yielded the same behavior (thus ruled out the phone being the problem) but when we later tried a friend's Pixel and then a Xiaomi phone - on both it worked perfectly just like a wired connection would.

For future reference: if anyone has an idea to why would that be the case, I'm curious to know :D

Who is online

Users browsing this forum: Google [Bot] and 66 guests