Peripheral is connected to two Centrals, each with two Gatt Services, occurred mtu exchange fail.

Hello,

I am using three nrf52840 DKs to test sending gatt notify data. They are one peripheral and two central.

When they each have only one Gatt Customer Service, peripheral can connect to both centrals at the same time and successfully send gatt notify data to them.

But when they both have two Gatt Customer Services, when peripheral connects to the second central, the first central will crash, and the second central will have mtu exchange fail (-14).

Is it possible for one peripheral to connect to two centrals at the same time, one central to register two Gatt Services, and then send gatt_notify at the same time?

Parents
  • Hi,

    Multiple connections in the peripheral role is possible and supported, but then your application needs to properly support it. So you need to keep track of the connections, and make all connection related API calls with the correct connection object (bt_conn struct) which is typically the first argument, etc. As you see something happen on one link when you do something on the other link, that indocate to me that perhaps you do not have a clean handling of the connections in your application?

  • Thank you for your reply.

    I don’t quite understand what you mean. Do you mean that some steps were not completed when I connected?

    These are what I do when connected:

    void connected(struct bt_conn *conn, uint8_t err)
    {
    	LOG_INF("connected");
    	char addr[BT_ADDR_LE_STR_LEN];
    	static struct bt_gatt_exchange_params exchange_params;
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (err != 0) {
    		LOG_INF("Failed to connect to %s (%u)", addr, err);
    		return;
    	}
    
    	LOG_INF("Connected to %s", addr);
    
    	exchange_params.func = exchange_func;
    	err = bt_gatt_exchange_mtu(conn, &exchange_params);
    	if (err) {
    		LOG_INF("MTU exchange failed (err %d)", err);
    	}
    	memcpy(&uuid, &test_uuid.uuid, sizeof(uuid));
    	discover_params.uuid = &uuid.uuid;
        discover_params.func = discover_func;
    	discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE;
    	discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
    	discover_params.type = BT_GATT_DISCOVER_PRIMARY;
        err = bt_gatt_discover(conn,&discover_params);
    	if (err) {
    		LOG_ERR("Discover failed(err %d)\n", err);
    		return;
    	}
    #if CONFIG_TWO_GATT_SERVICE
    	memcpy(&uuid_2, &test_uuid_2.uuid, sizeof(uuid_2));
    	discover_params_2.uuid = &uuid_2.uuid;
        discover_params_2.func = discover_func_2;
    	discover_params_2.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE;
    	discover_params_2.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
    	discover_params_2.type = BT_GATT_DISCOVER_PRIMARY;
        err = bt_gatt_discover(conn,&discover_params_2);
    	if (err) {
    		LOG_ERR("Discover failed(err %d)\n", err);
    		return;
    	}
    #endif
    }

    If I set CONFIG_TWO_GATT_SERVICE to n, peripheral can successfully connect to two centrals.

    But if I set CONFIG_TWO_GATT_SERVICE to y, the error I mentioned above will occur when peripheral connects to the second central.

  • Hi,

    I don't know anything more than you have written, so the reason for my initial question was to ask if you handle multiple connections properly in your peripheral application (as most smaples are only designed for a single connection).

    The code snippet you have shown here is that from the central or peripheral side? (I ask as a GATT client can be present on both)? And do you have logs from both sentrals and the peripheral you can share that may shed some light on this? For instance, what happens on the first central when it "crashes"? And what happens on the peripheral side? Knowing more about the implemetnation would be usefull as well.

  • The code I shown is from the peripheral side.

    I added CONFIG_BT_MAX_CONN=2 and CONFIG_BT_MAX_PAIRED=2 to the peripheral application so that it can connect to two centrals at the same time.

    After the peripheral is connected to the central, it will continuously transmit data to the central, and the central will also output the received data to the log.

    When the second central device connected, the first central device stopped outputting logs and didn't seem to be doing anything, so I thought it "crashes".

    At this time, peripheral does not output any special message.

    I will share the detailed logs and code next week.

Reply
  • The code I shown is from the peripheral side.

    I added CONFIG_BT_MAX_CONN=2 and CONFIG_BT_MAX_PAIRED=2 to the peripheral application so that it can connect to two centrals at the same time.

    After the peripheral is connected to the central, it will continuously transmit data to the central, and the central will also output the received data to the log.

    When the second central device connected, the first central device stopped outputting logs and didn't seem to be doing anything, so I thought it "crashes".

    At this time, peripheral does not output any special message.

    I will share the detailed logs and code next week.

Children
No Data
Related