BLE transmission speed is very slow

Amanoo
Posts: 3
Joined: Mon Nov 08, 2021 2:21 pm

BLE transmission speed is very slow

Postby Amanoo » Mon Nov 08, 2021 2:40 pm

I am trying to build an Android app that interfaces with the ESP32 using BLE. I am using the RxBluetoothKotlin library from Vincent Masselis for the Android side. For the ESP32 side, I am using the default Kolban libraries that are included in the Arduino IDE. My phone is a OnePlus 5T and my ESP32 is a MH ET Live ESP32DevKIT. My Android app can be found here, and my ESP32 program here.

The whole system works pretty much perfectly for me in terms of pure functionality. That is to say, every button does what it's supposed to do, and I get the exact behaviour I had expected to get. However, the communication itself is very slow. Around 200 bytes/second. My test button in the Android app requests a bunch of text data from the ESP32, and displays this in a dialog. It also lists a number which represents the time between request and reception in milliseconds. Using this, I get around 2 seconds for 440 bytes of data. When I send less data, the time decreases approximately linearly with data size. 40 bytes of data will take around 200ms, and 20 bytes or under typically takes less than 100ms.

This seems rather slow to me. From what I understand, I should be able to at least get a few kilobytes per second. I have tried taking the microcontroller and my phone to a few different locations, hoping to eliminate interference. I have tried to mess with BLEDevice::setPower and BLEDevice::setMTU, as well as setting RxBluetoothGatt.requestMtu(500) on the Android side. Everything so far seems to have had little to no effect. The only thing that did anything, was adding the line "pServer->updatePeerMTU(0,500);" in my loop during the connection phase. This caused the first 23 bytes of data to be repeated whenever I pressed the test button in my app, and made the data transfer take about 3 seconds. If I'm lucky, I can get maybe a bit under 1.8 seconds for 440 bytes, but this is a very small change when I'm expecting an order of magnitude of difference, and might even be down to pure chance rather than anything I did.

Does anyone have an idea of how to increase my transfer speed?

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

Re: BLE transmission speed is very slow

Postby chegewara » Tue Nov 09, 2021 3:02 am

Something is not working correctly. My suggestion is to run nrf connect and change MTU in it after connecting, then check logs and see if it works.
If it works, then android app is problem most likely.

Amanoo
Posts: 3
Joined: Mon Nov 08, 2021 2:21 pm

Re: BLE transmission speed is very slow

Postby Amanoo » Tue Nov 09, 2021 8:01 pm

chegewara wrote:
Tue Nov 09, 2021 3:02 am
Something is not working correctly. My suggestion is to run nrf connect and change MTU in it after connecting, then check logs and see if it works.
If it works, then android app is problem most likely.
I've got the nRF Connect app installed. Looking at the logs in debug mode, I can see a time stamp when gatt.readCharacteristic(UUID) is executed, and a time stamp when a read response is received. The difference is about 2 seconds. In other words, I'm seeing the same delay in my nRF Connect app. Looks like that at least rules out my Android app. That's one piece of the puzzle solved.

I have also changed my code to only set the characteristic value in a callback instead of inside the main loop, meaning a value is only set when the phone requests data from the ESP32. I can then slow the data transfer down by adding a delay in the callback. Not super useful, at least when I had a 1 second delay in my code, I get a 3 second delay instead of 2 seconds. Which confirms that what I think I'm seeing really is what I'm actually seeing, if that makes sense.

So yeah, long story short, I can confirm that the nRF Connect app has the same slow transmission speed that my own app has. Which means my app is not the culprit. Good to know, now I need to figure out what *is*.

Amanoo
Posts: 3
Joined: Mon Nov 08, 2021 2:21 pm

Re: BLE transmission speed is very slow

Postby Amanoo » Thu Nov 11, 2021 12:26 am

I have messed around with partition schemes in my IDE, uploaded the code to my ESP32, then messed around some more with a larger MTU and higher priority, and now it seems I'm getting about 10kByte/s. Still not as fast as BLE should be capable of, but a lot closer. The weird thing is, MTU and priority didn't seem to do much earlier. I'm really not sure why it's working now. Still not as fast as it should be, but a lot closer for no clear reason.

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

Re: BLE transmission speed is very slow

Postby chegewara » Sat Nov 13, 2021 9:15 am

Depends how you are sending data (notify, indicate, write, write with no response) you should be able to achieve 40-100kB/s with android device.

I only one time had similar issue like you and i still dont know why. It was when ive been trying to perform OTA over BLE on esp32 ble mesh node. I know that ble mesh is using radio very extensive, and it was before ble mesh + ble optimization has been implemented by espressif, so i just accepted it.

Who is online

Users browsing this forum: No registered users and 82 guests