Sending and receving data with a minimal latency with BLE

Anh-Minh
Posts: 13
Joined: Wed May 16, 2018 3:21 pm

Sending and receving data with a minimal latency with BLE

Postby Anh-Minh » Tue Jun 12, 2018 9:32 am

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

chegewara
Posts: 873
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Tue Jun 12, 2018 12:42 pm


Anh-Minh
Posts: 13
Joined: Wed May 16, 2018 3:21 pm

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

Postby Anh-Minh » Tue Jun 12, 2018 2:25 pm

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 ?


JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

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

Postby JoaoLopesF » Tue Jun 12, 2018 7:16 pm

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

chegewara
Posts: 873
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Wed Jun 13, 2018 1:48 am

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.

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

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

Postby JoaoLopesF » Wed Jun 13, 2018 12:58 pm

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

Who is online

Users browsing this forum: Bing [Bot] and 22 guests