What is the maximum number of bytes that can be sent in one packet using BLE on Arduino Nano 33 BLE Sense?

Hi guys,

What is the maximum number of bytes that can be sent in one packet using BLE on Arduino Nano 33 BLE Sense board?

1 Like

The usual answer is 20, unless you enable the extension on both ends.

I think that I achieved that as based on my tests I am able to send 220 bytes in 1 packet from Arduino to my PC and receive them on the other side. But I got some weird results when I tried to send an image so I want to check if this implementation really enables me this 220 bytes packet size.

This is how I defined characteristic:

const int RX_BUFFER_SIZE = 220;
bool RX_BUFFER_FIXED_LENGTH = false;
BLECharacteristic txChar(uuidOftxChar, BLEIndicate, RX_BUFFER_SIZE, RX_BUFFER_FIXED_LENGTH);

This is the way how my image array is created:

// In the end it is 3080 bytes array 
for (int index = 0; index < jpeg_length; index++) {
    jpeg_buffer[index] = SPI.transfer(0x00);
  }

And finally this is how I send the data:

int i = 0;
  while(i<jpeg_length){
        
    txChar.writeValue(jpeg_buffer+i, 220);
    i+=220;
  }

Can you just confirm me that these parts were coded good? Thanks :slight_smile:

The buffer size does not equal packet size. If your BLEcharacteristics has more bytes the library can still transmit the data by using multiple data packets. A standard data packet has a maximum payload of 27 bytes. There are some complications in the standard that are not worth getting into the details.

Why do you worry about the packet size? I would recommend focusing on creating a good service and characteristics that you can use for a long time and you can leave the rest to the ArduinoBLE library.

I am worried in this case as I need specifically to send this image array gotten from the ArduCam module to my device for the further analysis. If I can only send 27 bytes then I will need to repeat sending task (loop cycles) for around 114 times (3080/27=114.07). It works perfect when I am sending super simple message (0 or 1) but for this more important purpose I am a bit worried how to implement it to be honest. I have already struggled a lot by trying 100 different ways to send this image properly and for me this option with 220 bytes separated in 14 packets sounded nice :confused:

I think that the max characteristic length in the Arduino BLE library is 512 bytes. As @Klaus_K says, the library will break that down into packets.

I have seen some postings where using the max characteristic size creates issues and you should experiment to see what you can reliably do. Setting the characteristic length to 128 and 256 before going to 512 would be worthwhile.

See the three articles in this analysis to see why there is really not much to gain by trying to change the MTU and packet size. There is a lot of other overhead at play.
https://punchthrough.com/maximizing-ble-throughput-on-ios-and-android/

The link to the very nice discussion provided above by cattledog has this comment, which answers the question raised by the thread title.

The caution about the data packet length extension in v4.2 applies to iOS and Android.

Based on my experiments the maximum that I was able to send is 240 bytes but I set it to 220 bytes because of number of cycles that I need to perform on my PC (3080/220=13) to avoid some extra random bytes. I defined some counters on both sides and they counted 3080 bytes sent/received on both sides. Now I am concerned that some of those bytes also included header and other parts that every packet has. I also have to include that into my counts or?

P.S. everything else I tried above 240, BLE always sends max 240 based on the number of sent/received packets.

I tried with the simple array of chars starting with 0 up to 127 and it seems that everything is received correctly except two additional signs \ that should not be at all. Using bleak library on Windows I am able to receive ASCII characters and they matched, so maybe the image received from the Arduino is not weird. However, I am still struggling to find a way how to convert it into some format visible to me. Do you maybe know the solution?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.