Issues with MTU auto negotiation with peer

Well, after spending countless hours learning about BLE + MTU, diving through the Device OS source code and even writing my own Arduino BLU peripheral to emulate the BMS device, I now realize I made a couple of stupid mistakes.

#1 - I saw the BMS android app set MTU of 40 and referencing the battery state at index 36 and manually setting the MTU to 40, I assumed the BMS characteristic notify size was 40. Well, stupid me didn’t really notice the source code took the received packet of 20 bytes and converted it into a 40 position character string. Meaning a 0x58 packet byte got converted to the ascii string “88”. :frowning:

#2 - While the ERROR I was getting from the Device OS was just like that other thread, that was a red herring. When I coded up my own BLE peripheral with a known good BLE stack (Arduino BLE on Seeed XIAO nrf52840), I noticed the same ERROR messages coming from the Argon/Device OS. It seems the Device OS tries to run the MTU negotiation until it’s successful and after the 2nd or 3rd time it works correctly. After I adjusted the code that talks to the BMS device to allow some time between the connection and the first time I send a command, I then saw a proper MTU negotiation occur. :partying_face:

BTW - in case anyone cares, in Device OS 5.1.0, here is the proper command to manually set the MTU size:

hal_ble_gatt_server_set_desired_att_mtu(40, NULL);

Hopefully this tale will help anyone else coming in new to BLE to avoid the mistakes I made: check your assumptions and bias at the door. :slight_smile:

4 Likes