petewarden / ble_file_transfer

Example of transferring file data over BLE using an Arduino Nano Sense and WebBLE

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The one that limits the maximum block size

xtnctx opened this issue · comments

- The maximum block size is set to 128 bytes, since going over that seems to affect the reliability of the connection. We should be able to get up to 512 bytes theoretically, but I don't know why this doesn't work.

It's the MTU 🎉

Arduino Nano 33 BLE Sense is using nRF52840 and it is the one that limits the block size or the amount of bytes that can be send.

The nRF52840 supports the increase of the data packet length from the default 27 to the maximum value allowed by the Bluetooth spec which is 251 bytes.

Detailed discussion on their website


I also use your code for my project, and its true that we got slower data transmission. With Bluetooth 5.x, it should've 512 bytes per block.

I've found the solution for faster transmission of data by requesting MTU size after connection has been made.

// Only tested on android using Flutter and flutter_blue_plus package (https://pub.dev/packages/flutter_blue_plus)
if (Platform.isAndroid) await device!.requestMtu(512);

Even though I requested 512 of MTU size I only got 247. It automatically chooses the highest MTU size that can handle based on what you requested. Now I can send data faster compared to the default MTU size.

In the arduino code, I also did some experiment by making file_block_byte_count around 200-247 but I got disconnected somehow. You're right, it affects reliability of the connection. I also found this value the safest, it doesn't matter if its lower than the new MTU. What more important is it makes significantly faster with a new higher MTU.