BLE 4 Coded
Posted: Mon Jan 09, 2023 1:49 pm
I am using an ESP32-S3-WROOM-1 chip as a BLE 5 GATT client (this is what we call the “brain”) and an ESP32-C3-WROOM-02 as the BLE 5 GATT server (this is a “sensor”). Both devices are headless, there are no buttons or screens.
To conserve battery life on the sensor, the sensor will go into a deep sleep state and wake up periodically to transmit information to the brain. I had a lot of trouble understanding the best way to implement the BLE functionality, but I was able to piece together a solution based on the ESP32 code examples. Although it seems to work, it needs to be improved. Let me share with you, my concerns. I greatly appreciate any help you can offer.
To aid in my explanation, I have provided you a link to a folder on my OneDrive. The password is: 3SPHelp$
https://1drv.ms/u/s!AqYgHKn2LJ7yhbYRWzB4R_Arxl-HAg?e=0X7LdK
• ble_client.c – BLE code used on the brain. Some contents of the file has been changed/deleted.
• ble_server.c – BLE code used on the sensor. Some contents of the file has been changed/deleted.
• ble5-gatt-slow-esp-idf.mp4 – Video to demonstrate the poor performance connecting via BLE.
Q1. It takes a very long time to establish a connection between the GATT server and client.
When the sensor wakes up, the process of connecting, reading data, and disconnecting will take about 27 seconds. This is a very long time and I wonder how it can be improved. If you watch the video I have provided you, it will be clear what I am referring to.
In the video:
• The brain is shown on the left and the sensor is on the right. Ignore the information that is displayed on the screen when the video begins.
• At 0:03 the sensor begins wakes up and begins to advertise. The brain starts the connection process almost immediately - this is fantastic.
• At 0:07 the connection is established. It took almost 4 seconds. Now the devices show the “ESP_LE_AUTH_REQ_SC_BOND” message.
• At 0:20 the devices have bonded. This took 13 seconds. It is too long in my opinion.
• The last several seconds of the video, data is transferred.
How can I improve the length of time needed for the entire process I illustrated above. As I mentioned earlier, I struggled to understand best practices implementing BLE using IDF. Do I even need to “bond” the devices? Can I skip any of the steps?
Q2. Am I using BLE 5 long range (coded)?
At the time I developed this, there were very few examples with BLE 5 coded. In this design, I want to use BLE 5 coded at the longest range possible. I do not need to send a lot of data and I do not need to send data at a fast speed. Distance is very important to me.
I was unable to confirm my code establishes a BLE 5 coded connection. As an example, I couldn’t figure out how to have the sensor send the BLE advertisement using BLE 5 coded. If the advertisement is not received by the brain, then it will not know to establish a connection.
Are you able to either review my code files to see if I have correctly set the BLE protocols and advertising correctly? Or, if you can provide a more complete BLE 5 coded example with GATT I am happy to do this myself.
To conserve battery life on the sensor, the sensor will go into a deep sleep state and wake up periodically to transmit information to the brain. I had a lot of trouble understanding the best way to implement the BLE functionality, but I was able to piece together a solution based on the ESP32 code examples. Although it seems to work, it needs to be improved. Let me share with you, my concerns. I greatly appreciate any help you can offer.
To aid in my explanation, I have provided you a link to a folder on my OneDrive. The password is: 3SPHelp$
https://1drv.ms/u/s!AqYgHKn2LJ7yhbYRWzB4R_Arxl-HAg?e=0X7LdK
• ble_client.c – BLE code used on the brain. Some contents of the file has been changed/deleted.
• ble_server.c – BLE code used on the sensor. Some contents of the file has been changed/deleted.
• ble5-gatt-slow-esp-idf.mp4 – Video to demonstrate the poor performance connecting via BLE.
Q1. It takes a very long time to establish a connection between the GATT server and client.
When the sensor wakes up, the process of connecting, reading data, and disconnecting will take about 27 seconds. This is a very long time and I wonder how it can be improved. If you watch the video I have provided you, it will be clear what I am referring to.
In the video:
• The brain is shown on the left and the sensor is on the right. Ignore the information that is displayed on the screen when the video begins.
• At 0:03 the sensor begins wakes up and begins to advertise. The brain starts the connection process almost immediately - this is fantastic.
• At 0:07 the connection is established. It took almost 4 seconds. Now the devices show the “ESP_LE_AUTH_REQ_SC_BOND” message.
• At 0:20 the devices have bonded. This took 13 seconds. It is too long in my opinion.
• The last several seconds of the video, data is transferred.
How can I improve the length of time needed for the entire process I illustrated above. As I mentioned earlier, I struggled to understand best practices implementing BLE using IDF. Do I even need to “bond” the devices? Can I skip any of the steps?
Q2. Am I using BLE 5 long range (coded)?
At the time I developed this, there were very few examples with BLE 5 coded. In this design, I want to use BLE 5 coded at the longest range possible. I do not need to send a lot of data and I do not need to send data at a fast speed. Distance is very important to me.
I was unable to confirm my code establishes a BLE 5 coded connection. As an example, I couldn’t figure out how to have the sensor send the BLE advertisement using BLE 5 coded. If the advertisement is not received by the brain, then it will not know to establish a connection.
Are you able to either review my code files to see if I have correctly set the BLE protocols and advertising correctly? Or, if you can provide a more complete BLE 5 coded example with GATT I am happy to do this myself.