BLE communication between EPS32 and Mobile phones

eldadwasserman
Posts: 7
Joined: Tue Oct 31, 2017 7:44 am

BLE communication between EPS32 and Mobile phones

Postby eldadwasserman » Tue Jan 23, 2018 7:32 pm

Hi,

I need some help regarding BLE communication between ESP32 and Android / IOS . (2 ways communication).
I have existing project that works great with Android mobile phone by using OTG USB cable. I want to do the communication with BLE instead USB cable.

The ESP32 transmit 2400 bytes per second of data to the mobile non stop. The mobile send commands to the EPS32 like "start TX" / "Stop TX" "Change parameters" etc...
The transmission timing from the ESP32 to the mobile phone is 48 bytes every 20MSEC - this is a real time project - I must keep this communication speed accurate.

I need someone to help me with the BLE code / function that will be easy for me to add this functionality to my project.

My development environment is ESP-IDF with eclipse.

Thanks for any help !!!!

my direct email is eldad.wasserman@gmail.com

Eldad

Lucas.Hutchinson
Posts: 77
Joined: Tue Apr 26, 2016 5:10 am

Re: BLE communication between EPS32 and Mobile phones

Postby Lucas.Hutchinson » Wed Jan 24, 2018 12:49 am

This can be achieved with some simple modifications to the gatt_server or gatt_server_service_table examples in the IDF.

You will first need to set your interval to 20ms.

You can set this with the following code:

Code: Select all

esp_ble_conn_update_params_t conn_params; //todo maybe turn this into malloc/free
memcpy(conn_params.bda, client_addr, BLE_MAC_ADDR_LEN);
conn_params.min_int = 16; // x 1.25ms
conn_params.max_int = 16; // x 1.25ms
conn_params.latency = 0x00; //number of skippable connection events
conn_params.timeout = 320; // x 6.25ms, time before peripherial will assume connection is dropped.
esp_ble_gap_update_conn_params(&conn_params);
Then you need to ensure that you have a large enough MTU (think ble packet size) to send all the data you want in one packet (yes you could do this with multiple packets, but it is going to be much easier with one packet).
Since you need to transfer only 48 bytes per interval you need to set this to 51 bytes or more (48+3 byte packet overhead inside the BLE protocol).

iOS automatically negotiates a larger MTU of 185 on connection.
Android doesnt, but there is a simple function call that you can use to set the MTU. For various reasons relating to how BLE is implemented setting this to 185 on android as well is a good idea.

You should also support notifications on the characteristic that you want to use to send the information to the phone.
Then when you connect with the phone you should enable notifications on this characteristic.

You can then use this function call to send data to the phone:

Code: Select all

esp_ble_gatts_send_indicate
I hope this puts you on the right track.

Who is online

Users browsing this forum: kurta999, Majestic-12 [Bot] and 34 guests