This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What event to wait for to know when mtu has been successfully negotiated with a central device?

I am trying to detect when mtu has been successfully negotiated through the ble_evt_handler function, which is passed into NRF_SDH_BLE_OBSERVER as shown below:

// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);

I am currently checking for the event BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST, and associating that with a new mtu being set successfully. I use this event to trigger a message being sent from the nRF52840 to my central device (an Android phone, a Google Pixel 2).

The logic is that whenever the nRF52840 and Android phone connect, they always negotiate an mtu of the largest characteristic value size (512 bytes), and so I don't want the device to transmit anything until after this mtu has been negotiated.

This seems to work most of the time, but sometimes I will get an error on the central side when it tries to reply to the message from the nRf52840 where it will still think that the mtu of the connection is 20 bytes.

This makes me think that the BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST is the wrong event to check for on the device side (even the name seems to imply that it does not really mean that mtu was changed successfully yet, just that there was a request to change it).

My question is, is there any event like "BLE_GATTS_EVT_MTU_CHANGED_SUCCESSFULLY", or something along those lines, where when this event occurs I know for sure that the mtu of the connection has been set successfully for both the device and the central? I tried to look through the events and didn't see anything that looked like this.

Thank you. (And happy holidays)

Related