Page 1 of 1

Sending and receving data with a minimal latency with BLE

Posted: Tue Jun 12, 2018 9:32 am
by Anh-Minh
Hi everybody,

I am currently working on a project in which i want to control a device from an app ( for example, control the gain of a sound, by moving a slider ) with BLE. To do this, the app and the device has both their own characteristic, and they will send a command/answer by writing on these characteristic. This is how it works :

Image

The application cannot send another command until it has not received the answer of the previous command. If you move the slider in the app, the next command to set the gain will be send only when the previous answer is received by the app,that is why i want the delay between sending and receiving an answer to be very short, almost instantaneous to be smooth while moving the slider.

Each command are approximatly 100 bytes, and a respond is ~50 bytes. The problem is, that with this lenghth of data, i have some latency, varying from 400ms to 1s sometimes to send a command to the device and receiving the answer. So i tried, to reduce my data length to < 20 bytes ( which is the size the data doesn't have to be truncated, right ? ) and the latency drops to 20ms to 40ms which is good. But i have to reduce in consequence all my commands and responses.

First of all, is this latency between sending, and receiving long data via BLE is normal ? ( due to BLE specifications i guess ). Is there any way i can reduce this latency with long commands/answer ?

Thank you :D

Re: Sending and receving data with a minimal latency with BLE

Posted: Tue Jun 12, 2018 12:42 pm
by chegewara

Re: Sending and receving data with a minimal latency with BLE

Posted: Tue Jun 12, 2018 2:25 pm
by Anh-Minh
Ok, i will try to use these functions. I am currently using C++ BLE by Kolban to work with BLE, where should i call these functions ?

Re: Sending and receving data with a minimal latency with BLE

Posted: Tue Jun 12, 2018 4:53 pm
by bobolink

Re: Sending and receving data with a minimal latency with BLE

Posted: Tue Jun 12, 2018 7:16 pm
by JoaoLopesF
Hi,

What I learned about Ble MTU:

- Who changes the MTU is the client, the server receives the event of this change
- Usually ESP32 is the server and APP mobile is the client, in this case you only need to change your code for Android, since iOS already changes the MTU automatically to 185 (iOS10 and iOS11)

Please see my answer in another topic: viewtopic.php?f=2&t=5736&start=10#p25559

Re: Sending and receving data with a minimal latency with BLE

Posted: Wed Jun 13, 2018 1:48 am
by chegewara
Situation you are describing here is true because esp32 by default has set local mtu value 500 if i remember or something around it. Its developers implementing choice.

Re: Sending and receving data with a minimal latency with BLE

Posted: Wed Jun 13, 2018 12:58 pm
by JoaoLopesF
Hi, chegewara
Situation you are describing here is true because esp32 by default has set local mtu value 500 if i remember or something around it. Its developers implementing choice.
Usually the ESP32 act as server and mobile App act as client.

MTU -> Who's the boss? is the client!
In this case the mobile app.

For Android, the MTU is set about ~20 bytes.
In my App (if Android is 5.0+), I set it to 185 (equal default of iOS).

I understand that the Esp-IDF default of 500 is only valid, if the client is another ESP32