RE: [NUS, Bluetooth] bt_conn

Hello,

I am programming BLE with the nRF52840-DK. [Toolchain Manager: v1.3.0, IDE: Visual Studio Code (VSCode), SDK: ncs v2.6.0, window11 pro]

I am using NUS to work with Bluetooth. I am programming new code by looking at the examples peripheral_uart and central_uart. I have a question about the variable bt_conn (in 'conn_internal.h') that exists in the examples peripheral_uart and central_uart

  1. Is the bt_conn (in 'conn_internal.h') variable the information of the currently connected Bluetooth device, or is it the information of the Bluetooth device that holds this code? (
  2. The code below is the callback function code for connected in peripheral_uart. At this time, info.role is output as peripheral. I am confused whether the function bt_conn_get_info(conn, &info) puts the information of the Bluetooth device connected to conn into info or if it puts the Bluetooth information of conn into info."
    static void connected(struct bt_conn *conn, uint8_t err){
    	char addr[BT_ADDR_LE_STR_LEN];
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    	if (err) {
    		LOG_INF("connected - connected: Connection failed (err %u)", err);
    		return;
    	}
    	LOG_INF("connected - Connected %s", addr);
    	current_conn = bt_conn_ref(conn);
    	struct bt_conn_info info = {0};
    	err = bt_conn_get_info(conn, &info);
    	LOG_INF("connected - bt_conn_get_info >>> err:%d", err);
    	LOG_INF("connected - Connected as %s", info.role == BT_CONN_ROLE_CENTRAL ? "central" : "peripheral");
    	LOG_INF("connected - Conn. interval is %u units", info.le.interval);
    }
    
    static struct bt_conn_cb conn_callbacks = {
    	.connected    = connected,
    	.disconnected = disconnected,
    	.security_changed = security_changed,
    	.le_param_updated = le_param_updated,
    	.le_data_len_updated = le_data_length_updated,
    	.le_phy_updated =  le_phy_updated,
    };
Parents
  • Hi,

    Is the bt_conn (in 'conn_internal.h') variable the information of the currently connected Bluetooth device, or is it the information of the Bluetooth device that holds this code? (

    This is an information structure internal to the host subsystem, holding information about a connection. It should not be used directly by the application, as internal structures are not documented and may change without notice. Instead, information from this structure should be fetched through the public API of bt_conn_get_info().

    The code below is the callback function code for connected in peripheral_uart. At this time, info.role is output as peripheral. I am confused whether the function bt_conn_get_info(conn, &info) puts the information of the Bluetooth device connected to conn into info or if it puts the Bluetooth information of conn into info."

    bt_conn_get_info() puts information about the connection into info. This includes some information about the device connected over that connection, but it also includes information about the connection itself from the local device's point of view. In particular the le field, which is of type struct bt_conn_le_info, contains information about the device running the code (local device), as well as information about the device connected to it over the given connection (remote device).

    Regards,
    Terje

Reply
  • Hi,

    Is the bt_conn (in 'conn_internal.h') variable the information of the currently connected Bluetooth device, or is it the information of the Bluetooth device that holds this code? (

    This is an information structure internal to the host subsystem, holding information about a connection. It should not be used directly by the application, as internal structures are not documented and may change without notice. Instead, information from this structure should be fetched through the public API of bt_conn_get_info().

    The code below is the callback function code for connected in peripheral_uart. At this time, info.role is output as peripheral. I am confused whether the function bt_conn_get_info(conn, &info) puts the information of the Bluetooth device connected to conn into info or if it puts the Bluetooth information of conn into info."

    bt_conn_get_info() puts information about the connection into info. This includes some information about the device connected over that connection, but it also includes information about the connection itself from the local device's point of view. In particular the le field, which is of type struct bt_conn_le_info, contains information about the device running the code (local device), as well as information about the device connected to it over the given connection (remote device).

    Regards,
    Terje

Children
No Data
Related