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

Parents
  • 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

Reply
  • 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

Children
Related