nRF5340 LE disconnection Issue.

Hi,

We are using nRF5340 DK and the nRF Connect SDK Version 2.6.1.

We are experiencing an issue with disconnections. We use bt_conn_ref() when receiving the connected event and bt_conn_unref() when receiving the disconnection event.

However, sometimes after a disconnection, when we retry, we encounter the error: "bt_conn: bt_conn_exists_le: Found valid connection (0x20001a18) with address FF:F5:55:5A:D6:6A (random) in disconnected state".

Why does this issue occur even after the disconnection event has been processed?

If we call bt_conn_unref() twice during the disconnection event as shown in the below code (essentially incrementing once upon connection and decrementing twice upon disconnection), the issue does not occur.

void connected(struct bt_conn *conn, uint8_t conn_err){
	bt_conn_ref(conn);
}
void disconnected(struct bt_conn *conn, uint8_t reason){
 	bt_conn_unref(conn);
 	bt_conn_unref(conn);	
}

Could this behavior be due to an internal counter issue?

Parents
  • Hi,

    I'm not aware of any known issues where the Bluetooth host fails to release its own reference. Are you developing a peripheral or central application?

    Thanks,

    Vidar

  • Hi, 

    Thanks for the response.

    We are developing a mesh network. Our requirement is the one device can connect to three other devices. Using one connection as a peripheral and up to two connections as a central for mesh connections.

  • Hi

    Thanks for the response.

    I followed the example implementation you suggested, but the issue persists. 

  • Hi,

    Could you provide a complete log showing the error?

    Best regards,
    Dejan

  • Hi,

    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    
    [00:00:00.017,944] <inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.017,944] <inf> bt_hci_core: hci_vs_init: HW Variant: nRF53x (0x0003)
    [00:00:00.017,974] <inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
    [00:00:00.019,805] <inf> bt_hci_core: bt_dev_show_info: Identity: FF:F5:55:5A:D6:6A (random)
    [00:00:00.019,836] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.4 (0x0d) revision 0x218f, manufacturer 0x0059
    [00:00:00.019,836] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.4 (0x0d) subver 0x218f
    
    [DISCOVERY]: Discovery Mode Fast Scanning
    [DISCOVERY]: Discovery Mode Fast Advertising
    
    [CONN]: Connecting to Node:34628, DeviceAddress:D9:55:D0:0F:78:7D (random)
    [CONN]: ####### CONNECTED as CENTRAL  MacAddr:D9:55:D0:0F:78:7D (random) #######
    [CONN]: CONN_COUNT:1, ConnDataIndex:0, conn_handle:0, k_uptime_get_32():2745
    [DISCOVERY]: Discovery Mode Slow Scanning
    [CONN]: MTU exchange done
    
    èONN]: ####### CONNECTED as PERIPHERAL,  MacAddr:FA:8F:B8:34:60:23 (random) #######
    [CONN]: CONN_COUNT:2, ConnDataIndex:1, conn_handle:9, k_uptime_get_32():6873
    [DISCOVERY]: Discovery Mode Slow Scanning
    
    [CONN]: Force disconnecting Node:34628, conn->handle:0
    [CONN]: ####### DISCONNECTED Reason: 22  MacAddr:D9:55:D0:0F:78:7D (random) #######
    [CONN]: CONN_COUNT:1, conn_handle:0, conn->state:0, k_uptime_get_32():6977
    
    [RECONN]:Reconnection Nodeid:34628, Addr:D9:55:D0:0F:78:7D (random)
    [CONN]: Connecting to Node:34628, DeviceAddress:D9:55:D0:0F:78:7D (random)
    [00:00:06.980,743] <wrn> bt_conn: bt_conn_exists_le: Found valid connection (0x20001aa0) with address D9:55:D0:0F:78:7D (random) in disconnected state
    [ERROR]: Create conn failed (err -22)
    
    

    In the provided logs, you can observe the connection and disconnection sequences.

    Initially, I connected to the device with the address D9:55:D0:0F:78:7D as a master. Then, I connected to the device with the address FA:8F:B8:34:60:23 as a peripheral.

    Afterward, I disconnected the first device, D9:55:D0:0F:78:7D, and received a disconnection event indicating that the state is disconnected.

    However, when I attempted to reconnect to the last disconnected device, an error occurred stating, "Found valid connection (0x20001aa0) with address D9:55:D0:0F:78:7D (random) in disconnected state."

  • AKV said:
    However, when I attempted to reconnect to the last disconnected device, an error occurred stating, "Found valid connection (0x20001aa0) with address D9:55:D0:0F:78:7D (random) in disconnected state."

    Where does your application attempt to reconnect, is it within the disconnected callback, or right after?

  • Hi,

    Thanks for the response.

    I was retrying the disconnected callback. Now, I've added a flag to the disconnect callback, I will check the disconnect flag and initiate the connection from a separate thread, rather than reconnecting from the disconnect callback.

    This approach has significantly reduced the failure rate, but occasionally the error "Found valid connection (0x20001aa0) with address D9:55:D0:0F:78:7D (random) in disconnected state" still occurs.

    I've observed that there are occasional connectivity issues as well,

    1. Failed to connect to D9:55:D0:0F:78:7D (random) with ERROR (2).


    2. Post connection the issue "MTU exchange failed (err 14)" occurs and then disconnect.

Reply
  • Hi,

    Thanks for the response.

    I was retrying the disconnected callback. Now, I've added a flag to the disconnect callback, I will check the disconnect flag and initiate the connection from a separate thread, rather than reconnecting from the disconnect callback.

    This approach has significantly reduced the failure rate, but occasionally the error "Found valid connection (0x20001aa0) with address D9:55:D0:0F:78:7D (random) in disconnected state" still occurs.

    I've observed that there are occasional connectivity issues as well,

    1. Failed to connect to D9:55:D0:0F:78:7D (random) with ERROR (2).


    2. Post connection the issue "MTU exchange failed (err 14)" occurs and then disconnect.

Children
  • Hi,

    Rather than triggering the re-connect from a separate thread, please try to do it from the system workqueue. This should help ensure that the processing of the disconnect event in the BT host is completed before the connection is initated again. Here is an example of how you can define a workqueue item: https://github.com/nrfconnect/sdk-nrf/blob/8765c758005e4e65d40dafd9d2f2d4a2be5639fa/samples/bluetooth/peripheral_hr_coded/src/main.c#L38 

    AKV said:

    I've observed that there are occasional connectivity issues as well,

    1. Failed to connect to D9:55:D0:0F:78:7D (random) with ERROR (2).


    2. Post connection the issue "MTU exchange failed (err 14)" occurs and then disconnect.

    The error could indicate that the bt_conn_le_create() timed out. Are you calling bt_conn_le_create() instead of scan_start() when receiving the disconnect event?

    The MTU exchange should not be initiated if there was a connection error.

  • Hi,

    Thanks for the response.

    Rather than triggering the re-connect from a separate thread, please try to do it from the system workqueue.

    I have also tried using the system workqueue method, and it works as well.

    However, the two errors, 

    "Found valid connection (0x20001aa0) with address D9:55:D0:0F:78:7D (random) in disconnected state" and post connection the "MTU exchange failed (err 14)" are still occasionally occurs.

    Are you calling bt_conn_le_create() instead of scan_start() when receiving the disconnect event?

    To initiate the connection, I first stop the scan using the bt_le_scan_stop() function, and then I use the bt_conn_le_create() function to initiate the connection.

  • Hi,

    Thanks for the additional information, In your application, are you calling the bt_gatt_exchange_mtu() to initiate the MTU exchange? This should only be called if there was no connection error. 

    Could you post code code snippets to show how your connected and disconnected callbacks are implemented?

    Best regards,

    Vidar

  • Hi 

    Thanks for the response.

    Please find the attached connection make, connected event and disconnected event code portion

    int ConnectToPeripheral(bt_addr_le_t *addr, uint16_t nodeId){
    
    	int err;
    	static struct bt_le_conn_param *param;
    	static struct bt_conn_le_create_param *create_conn_param;
    	bt_addr_le_t *deviceAddr = addr;
    	param = BT_LE_CONN_PARAM_DEFAULT; 
    	param->interval_max = CONN_INTERVAL_MAX;
    	param->interval_min = CONN_INTERVAL_MIN;
    	param->timeout = SUPERVISION_TIMEOUT;
    	create_conn_param = BT_CONN_LE_CREATE_CONN;
    	create_conn_param->timeout = 150;
    
        err = bt_le_scan_stop();
        if (err) {
            LOGT(ERROR,"Stop LE scan failed before connection (err %d)", err);				
        }else{
    		scanActive=false;
    	}
    
    	err = bt_conn_le_create(deviceAddr, create_conn_param, param, &pending_central_conn);
    	return err;
    }
    
    static void connected(struct bt_conn *conn, uint8_t conn_err)
    {
    	struct bt_conn_info info;
    	char ConnectedAddr[BT_ADDR_LE_STR_LEN];
    	int ret=0;
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), ConnectedAddr, sizeof(ConnectedAddr));
    
    	if (conn_err) {
    		LOGT(ERROR,"Failed to connect to %s (%u)", ConnectedAddr, conn_err);
    		bt_conn_unref(conn);		
    
    		if(!scanActive){			 
            	discovery_State_Manage(SCANNING,FAST);    		
    		}
    		return;
    	}	
    
    	if (info.role == BT_CONN_ROLE_CENTRAL) {		
    		update_le_parame(conn);		
    	}
    
    	if(info.role == BT_CONN_ROLE_PERIPHERAL){
    		bt_conn_ref(conn);
    	}  
    
    }
    
    static void disconnected(struct bt_conn *conn, uint8_t reason)
    {	
    	LOGT(CONN,"####### DISCONNECTED Reason: %d #######",reason);	
    
    	if(conn){          
            bt_conn_unref(conn);
        }
    	
    }
    
    static void update_le_parame(struct bt_conn *conn){
    
    	int err;
    
    	exchange_params.func = exchange_func;
    	err = bt_gatt_exchange_mtu(conn, &exchange_params);
    	if (err) {
    		LOGT(ERROR,"MTU exchange failed (err %d)", err);
    	}	
    
    	err = bt_conn_le_phy_update(conn, conn_phy);
    	if (err) {
    		LOGT(ERROR,"PHY update failed: %d", err);
    	}
    
    }
    
    
    
    

  • Hi,

    Thanks for the code. In the connected callback, it seems that you are using the 'info' variable without initializing it. I would have expected to see a call to the bt_conn_get_info() function to assign the connection information to the variable.

Related