BLE.setDeviceName() only realistically works for 14 or fewer characters

,

Hi,

I was running into an issue with BLE.setDeviceName() where my Android app would stop finding the provisioning mode advertisement. It looks like the actual advertising data is getting truncated down to 31 bytes (as found here) but the documentation for BLE.setDeviceName() says the max length is 20, without saying the advertising data will be truncated if it above 14 characters long. This truncation would be less of an issue if it didn't truncate the entire BleAdvertisingData packet.

Here are some logs to show what mean.

0000421773 [app] INFO: BLE device name: 'OriAAAAAAAAAA' [13]
advData[30]>
0201060e094f7269414141414141414141410bffedcb2000303439334430

0001142001 [app] INFO: BLE device name: 'OriAAAAAAAAAAA' [14]
advData[31]>
0201060f094f726941414141414141414141410bffedcb2000303232363530

0000641769 [app] INFO: BLE device name: 'OriAAAAAAAAAAAA' [15]
advData[31]>
02010610094f72694141414141414141414141410bffedcb20003032323644

You can see that for the 13 character BLE name, the BleAdvertisingData is of length 30. All good.

For the 14 character name, it bumps up to the BLE_MAX_ADV_DATA_LEN of 31. Still good.

But for the 15 character name, we remain at a length of 31 but it wasn't the name that was truncated, it was the manufacturer data, specifically the 6 byte setup code. This alone wouldn't be an issue but my app looks for the whole manufacturing data section as well as the scanner expecting there to be more total bytes.

As I write this, I'm now seeing the comment in ble_provisioning_mode_handler.cpp saying that the true max length of the device name is 14 bytes, but that doesn't seem to show up on the BLE reference. If it truncated the name itself and not the whole structure, the packet wouldn't be corrupted and would still be able to be read by my poor little Android scanning app, who currently can't parse the ScanResult. I can try to work around this by scanning for all BLE advertisements and manually parsing them instead of having Android use a scan filter on the service UUID, or having a shorter name or maybe add something to the scanResponseData. It might be a good idea to add a note somewhere more user facing.

1 Like

The documentation for setDeviceName now lists the practical limitation of 14 characters as well as the actual limit of 20.

1 Like