<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to get the BLE device name after connection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/104507/how-to-get-the-ble-device-name-after-connection</link><description>Dear Support Team 
 
 We are testing the central_uart with peripheral_uart sample in NCS v2.4.0, we would like to know that how to get the device name in the central_uart sample after BLE connection. Many thanks.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 10 Oct 2023 15:05:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/104507/how-to-get-the-ble-device-name-after-connection" /><item><title>RE: How to get the BLE device name after connection</title><link>https://devzone.nordicsemi.com/thread/449625?ContentTypeID=1</link><pubDate>Tue, 10 Oct 2023 15:05:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a625a22-298d-4876-bef9-f86aa3016fc4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can read the device name for instance like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint8_t device_name_read_cb(struct bt_conn *conn, uint8_t err,
			    struct bt_gatt_read_params *params,
			    const void *data, uint16_t length)
{
	char device_name_str[249];

	if (err != BT_ATT_ERR_SUCCESS) {
		LOG_INF(&amp;quot;Device name read failed: 0x%02X&amp;quot;, err);
	}

	snprintf(device_name_str, sizeof(device_name_str), &amp;quot;%s&amp;quot;, (char *)data);

	LOG_INF(&amp;quot;Device name: %s&amp;quot;, device_name_str);

	return 0;
}

void read_print_device_name(struct bt_conn *conn)
{
	static struct bt_gatt_read_params read_params;
	static struct bt_uuid_16 uuid;
	memcpy(&amp;amp;uuid, BT_UUID_GAP_DEVICE_NAME, sizeof(uuid));

	read_params.func = device_name_read_cb;
	read_params.handle_count = 0;
	read_params.by_uuid.start_handle = 1;
	read_params.by_uuid.end_handle = 0xffff;
	read_params.by_uuid.uuid = &amp;amp;uuid.uuid;
	bt_gatt_read(conn, &amp;amp;read_params);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(Call&amp;nbsp;read_print_device_name with the connection handle)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>