How to change peripheral mtu default size?

Hi 

    I need to change the default mtu size(peripheral device), but it always 23,unless phone requeset mtu size.

ncs2.7.0

nrf54L15pdk 

any peripheral demo

I need this value changed to  247, My phone can accept 247.

When I change BT_ATT_DEFAULT_LE_MTU to 247 it's works,but my android phone can't find service.

I'm worried that this approach will cause other problems.

I need your help, thanks.

  • I found it way to solve this problem.

    static struct bt_gatt_exchange_params exchange_params;
    
    static void exchange_func(struct bt_conn *conn, uint8_t att_err,
                              struct bt_gatt_exchange_params *params)
    {
        LOG_INF("MTU exchange %s", att_err == 0 ? "successful" : "failed");
        if (!att_err) {
            uint16_t payload_mtu =
                bt_gatt_get_mtu(conn) - 3; // 3 bytes used for Attribute headers.
            LOG_INF("New MTU: %d bytes", payload_mtu);
        }
    }
    
    static void update_mtu(struct bt_conn *conn)
    {
        int err;
        exchange_params.func = exchange_func;
    
        err = bt_gatt_exchange_mtu(conn, &exchange_params);
        if (err) {
            LOG_ERR("bt_gatt_exchange_mtu failed (err %d)", err);
        }
    }
    
    static void adv_evt_handler(adv_evt_t evt)
    {
        if (evt.statu) {
            LOG_INF("connected");
            update_mtu(evt.conn);
        } else {
            LOG_INF("disconnected reason=0x%x", evt.reason);
    #if CONFIG_BT_EXT_ADV
            mt_adv_start();
    #endif
        }
    }

Related