Skip to content

Bluetooth looses data at high speed #8808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
EricHarbers opened this issue Oct 25, 2023 · 1 comment · Fixed by #8859
Closed
1 task done

Bluetooth looses data at high speed #8808

EricHarbers opened this issue Oct 25, 2023 · 1 comment · Fixed by #8859
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: Test needed Issue needs testing
Milestone

Comments

@EricHarbers
Copy link

Related area

BluetoothSerial.cpp driver (V2.0.14)

Hardware specification

ESP32 dev module

Is your feature request related to a problem?

On Arduino BSP I have created a program that reads data from the serial port and sends it to the Bluetooth SPP serial port. At high speeds (260 KBit/s) the bluetooth module looses data. If you connect to the Bluetooth SPP port using eg a PC with a client app, it will not receive all sent bytes.

Describe the solution you'd like

After searching around in my software, I concluded that the Bluetooth module would loose the data bytes.
Then I started looking around in the BluetoothSerial.cpp driver and found the initialisation of the Bluetooth Serial process. When I change the task priority of the Bluetooth Process, the problem is solved.

The change I have made is in the function "_init_bt()".
I changed this code:

if(!_spp_task_handle){
    xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, 10, &_spp_task_handle, 0);
    if(!_spp_task_handle){
        log_e("Network Event Task Start Failed!");
        return false;
    }
}

The changed code:

if(!_spp_task_handle){
    xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, configMAX_PRIORITIES-1, &_spp_task_handle, 0);
    if(!_spp_task_handle){
        log_e("Network Event Task Start Failed!");
        return false;
    }
}

I found this because other processes in the ESP32 module will have the (configMAX_PRIORITIES-1) priority.
After changing the priority, I have had no data loose at all.

Describe alternatives you've considered

In my code, I have made the transfer from serial port to SPP as fast as possible.
At first I transferred the data byte by byte. Now I transfer the data in blocks, using the read and write functions.
I 've looked around on the internet, but I couldn't find any good solution to my problem.
BluetoothSerial_changed.zip
ESP32_Myomed.zip

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.
@EricHarbers EricHarbers added the Type: Feature request Feature request for Arduino ESP32 label Oct 25, 2023
@lucasssvaz lucasssvaz added Status: Test needed Issue needs testing Area: BT&Wifi BT & Wifi related issues and removed Type: Feature request Feature request for Arduino ESP32 labels Oct 25, 2023
@SuGlider
Copy link
Collaborator

SuGlider commented Nov 9, 2023

@EricHarbers -Thanks for the report about this issue and the solution you have found.
It makes a lot of sense to change it to the highest possible priority, given that it is a Wireless interface and it may need to be on the high priority in order to achieve performance and throughput.

I'll add a PR to change it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Test needed Issue needs testing
Projects
Development

Successfully merging a pull request may close this issue.

3 participants