ESP-32 Bluetooth read delay

FluidDynamics
Posts: 3
Joined: Tue Dec 26, 2023 7:52 am

ESP-32 Bluetooth read delay

Postby FluidDynamics » Tue Dec 26, 2023 8:16 am

Hey Folks,
I've been searching the web and this forum for an answer, but didn't find one.

So the problem is that i have always a delay of about 1000ms when I send a message to the ESP-32 before showing up in the serial monitor. For me, it seems some sort of read timeout, but couldn't figure it out. Does anyone know why there could be such a delay?

I'm using the SerialToSerialBT example. https://github.com/espressif/arduino-es ... rialBT.ino

I'm using PlatformIO and the Arduino Framework. I'm sending the data from an Android 13 Device with Serial Bluetooth Terminal. https://play.google.com/store/apps/deta ... l=de&gl=US.

I've also tested another older Android device. Same problem here.

Code: Select all

platform = espressif32
board = az-delivery-devkit-v4
board_build.mcu = esp32
framework = arduino
When I use

Code: Select all

if (SerialBT.available()) {
    Serial.println(SerialBT.readString());
}
the weird delay shows up. Seems to be always 1000ms + general Bluetooth delay (~20 - 100ms). What I'm doing wrong?

Code: Select all

#include "BluetoothSerial.h"

String device_name = "ESP32-BT-Slave";

// Check if Bluetooth is available
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

// Check Serial Port Profile
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;

void setup() {
    Serial.begin(115200);
    SerialBT.begin(device_name); //Bluetooth device name
    //SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin
    Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
}

void loop() {
    if (Serial.available()) {
        SerialBT.write(Serial.read());
    }
    if (SerialBT.available()) {
        Serial.println(SerialBT.readString());
    }
}

Thank you in advance and best regards. Cheers.

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

Re: ESP-32 Bluetooth read delay

Postby lbernstone » Tue Dec 26, 2023 6:07 pm

The hardware uart on esp32 has a buffer. If you don't fill that buffer, it eventually times out, and flushes it. This all can be controlled if you need more responsiveness and you know you have short (or even fixed) messages.
https://github.com/espressif/arduino-es ... e_Demo.ino

FluidDynamics
Posts: 3
Joined: Tue Dec 26, 2023 7:52 am

Re: ESP-32 Bluetooth read delay

Postby FluidDynamics » Tue Dec 26, 2023 6:29 pm

Okay, thanks for that information. I'm relatively new to this topic. Can you show me a sample how to implement that for a faster Bluetooth communication?

Best regards.

FluidDynamics
Posts: 3
Joined: Tue Dec 26, 2023 7:52 am

Re: ESP-32 Bluetooth read delay

Postby FluidDynamics » Wed Dec 27, 2023 4:33 pm

I lifted

Code: Select all

RX_QUEUE_SIZE
and

Code: Select all

TX_QUEUE_SIZE
in BluetoothSerial.cpp. That solved my problem.

Who is online

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