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 :
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
Sending and receving data with a minimal latency with BLE
Re: Sending and receving data with a minimal latency with BLE
In your case you should be able to go down to about 2x7.5ms. Here is material you need:
https://esp-idf.readthedocs.io/en/lates ... e_params_t
https://esp-idf.readthedocs.io/en/lates ... t8uint16_t
and for server:
https://github.com/espressif/esp-idf/bl ... .c#L21-L32
https://esp-idf.readthedocs.io/en/lates ... e_params_t
https://esp-idf.readthedocs.io/en/lates ... t8uint16_t
and for server:
https://github.com/espressif/esp-idf/bl ... .c#L21-L32
Re: Sending and receving data with a minimal latency with BLE
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
Here are some considerations from the phone side:
https://punchthrough.com/blog/posts/max ... nd-android
https://punchthrough.com/blog/posts/max ... er-att-mtu
https://punchthrough.com/blog/posts/max ... nd-android
https://punchthrough.com/blog/posts/max ... er-att-mtu
-
- Posts: 59
- Joined: Thu Aug 17, 2017 5:40 pm
Re: Sending and receving data with a minimal latency with BLE
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
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
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.
-
- Posts: 59
- Joined: Thu Aug 17, 2017 5:40 pm
Re: Sending and receving data with a minimal latency with BLE
Hi, chegewara
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
Usually the ESP32 act as server and mobile App act as client.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.
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: Baidu [Spider], Bing [Bot] and 104 guests