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

nRF52832 get current connection MTU size

Hi. After my nRF52832 peripheral connects to an android / iOS, I am trying to read the MTU size that has been negotiated with the following code;

/**@brief Function for handling events from the GATT library. */
void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
{
    current_mtu = p_evt->params.att_mtu_effective; //Get this info for personal band

    if ((m_conn_handle == p_evt->conn_handle) && (p_evt->evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED))
    {
        m_ble_nus_max_data_len = p_evt->params.att_mtu_effective - OPCODE_LENGTH - HANDLE_LENGTH;
    }
}

current_mtu is being set as 27 after connecting.

However the android phone is reporting the MTU size as 247. Also we are able to send 240 byte NUS messages, so am pretty sure att_mtu_effective is not correct.

How do I read the current MTU?

Thanks

Phil

  • Hi Philip

    It seems like your MTU size changes upon connecting to the Android phone and you're reading the MTU size before connection.

    If you use the gatt_evt_handler() that is used in many of our examples you should be able to see if this is changed upon connection.

    /**@brief GATT module event handler.
     */
    static void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
    {
        if (p_evt->evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED)
        {
            NRF_LOG_INFO("GATT ATT MTU on connection 0x%x changed to %d.",
                         p_evt->conn_handle,
                         p_evt->params.att_mtu_effective);
        }
    
        ble_hrs_on_gatt_evt(&m_hrs, p_evt);
    }
    
    

    Due to the summer holidays in Norway, our support team is understaffed this week, and delayed replies must be expected. Sorry for the inconvenience!

    Best regards,

    Simon

  • Hi Simon,

    Yes that is where I am setting current_mtu at the moment in the gatt_evt_handler ? The only difference between your example and mine is that I don't have the if statement.

    My code will update the "current_mtu" value every time there is a gatt_event of any type.

    Phil

  • Hi Philip

    You have to set the current_mtu = p_evt->params.att_mtu_effective inside of the if condition in order to get the updated MTU value. As of now you only get the value that the chip says it is before the update every time.

    Best regards,

    Simon

  • Hmm ok ill try that.

    I thought the mtu value would get updated each time the event handler triggers so when the mtu update happens it would over-right the original value.

    Maybe you have some build macro or similar so only conditions that are listed are triggered in the event handler. Ill see what happens when I add it in.

    Thanks

    Phil

Related