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

  • I see that you have opened this thread from Verified, is there something else you need assistance in this topic Seongmin? 

    Terje is on summer vacation, so I will try to assist you if you have any further queries in this related topic.

  • Thank you for your attention
    I was not satisfied with tesc's response. Could you please explain the structure variables in conn: 'uint16_t handle; enum bt_conn_type type; uint8_t role'? I'm curious about whether they contain information about the local device, the remote device, or both.

Reply Children
  • seongmincho said:
    Could you please explain the structure variables in conn: 'uint16_t handle; enum bt_conn_type type; uint8_t role'?
    In the context of Bluetooth connections, a handle is typically a unique identifier assigned to a specific connection. This handle is used to manage and track the state of individual connections when multiple devices are connected.
    In the context of the bt_conn structure, it's important to note that the structure is opaque, meaning its internal fields are not directly accessible. You should be using the connection management API to get access to this info.
    The connection type for our devices is always LE Connection.
    The role of the device is either a central or a peripheral.
    seongmincho said:
    I'm curious about whether they contain information about the local device, the remote device, or both.

    No, you cannot get that info from this struct. There is no one API where you get all the info about local or peer device. Based on what specific information you are looking for, there is different API for each of those. For example, if you want to know peer device address, you need to look for API or callbacks that give you info with variables type bt_addr_le_t. 

  • glad I could help. Assuming that my reply helped, I am marking the reply as verified so that it could help others who stumble upon this thread.
    I see that you have marked the reply as verified, thank you.

  • Related