<?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>Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68021/filtering-ble-devices-by-device-name</link><description>How do I filter and connect to BLE devices using the device name in Zephyr?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 13 Nov 2020 12:21:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68021/filtering-ble-devices-by-device-name" /><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279895?ContentTypeID=1</link><pubDate>Fri, 13 Nov 2020 12:21:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ec5f4b6-b594-4e88-b6b5-6fc17e4c8688</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;You might be exceeding the limit of how much data that can be placed in the bt_data_ad[].&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You will get -22 when that happens (&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/subsys/bluetooth/host/hci_core.c#L6621"&gt;Subsys: Bluetooth: Host: HCI Core L6621&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try removing one of the other entries and see if that helps.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279801?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 16:34:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9efef7b2-4915-4502-9a5a-c728eebe0e14</guid><dc:creator>JPSvanderWalt</dc:creator><description>&lt;p&gt;Hi I am defining it as below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define DEVICE_NAME_LEN		(sizeof(DEVICE_NAME) - 1)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279714?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 12:40:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c814dff-7f14-40a1-b6a6-ad5f2a6a79c5</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;That&amp;#39;s a bit strange. How are you defining DEVICE_NAME_LEN?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279620?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 06:08:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:539af230-7cc4-4f8c-941c-98f9f3148741</guid><dc:creator>JPSvanderWalt</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;I have tried the suggested BT_DATA macro and I am still getting the same error.&amp;nbsp; I even tried to add it to the scan response data with no success.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	//BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME,DEVICE_NAME_LEN),
	BT_DATA_BYTES(BT_DATA_UUID128_ALL,
		0xef, 0x41, 0x16, 0xdf, 0x0a, 0x11, 0x4b, 0x49,
		0xae, 0x5a, 0x65, 0x92, 0xd5, 0xa2, 0x6d, 0xa5),
};

static const struct bt_data sd[] = {
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),

};

err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am not sure if there is something specific I need to add to the config file to enable this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279590?ContentTypeID=1</link><pubDate>Wed, 11 Nov 2020 19:55:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67902dbb-439d-48f0-bd3b-2e09df68dd92</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-22 means invalid argument. You can look up the error codes in &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/master/lib/libc/minimal/include/errno.h"&gt;libc minimal errno.h&lt;/a&gt;&amp;nbsp;or &lt;a href="https://github.com/eblot/newlib/blob/master/newlib/libc/include/sys/errno.h"&gt;newlib errno.h&lt;/a&gt;&amp;nbsp;depending on if your application is built with newlib library or not (&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/CONFIG_NEWLIB_LIBC.html"&gt;CONFIG_NEWLIB_LIBC is&lt;/a&gt;&amp;nbsp;enabled).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You have to add it using the BT_DATA macro like this:&lt;/p&gt;
&lt;p&gt;BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LENGTH)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279346?ContentTypeID=1</link><pubDate>Tue, 10 Nov 2020 17:03:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6833415-ae53-43b9-9dcc-cc397e80948e</guid><dc:creator>JPSvanderWalt</dc:creator><description>&lt;p&gt;I added the device name to the advertising data as bellow:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define DEVICE_NAME			CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN		(sizeof(DEVICE_NAME) - 1)

struct bt_conn *default_conn;

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, DEVICE_NAME),
	BT_DATA_BYTES(BT_DATA_UUID128_ALL,
		0xef, 0x41, 0x16, 0xdf, 0x0a, 0x11, 0x4b, 0x49,
		0xae, 0x5a, 0x65, 0x92, 0xd5, 0xa2, 0x6d, 0xa5),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I then get the following error in the serial terminal&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Advertising failed to start (err -22)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Where can I look up the error code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279316?ContentTypeID=1</link><pubDate>Tue, 10 Nov 2020 14:52:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab7a4192-2317-447b-91ac-807f3f13a160</guid><dc:creator>Heidi</dc:creator><description>[quote user="JPSvanderWalt"]&lt;p&gt;From what I understand from your last reply, I have to add the device name (&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;BT_DATA_NAME_COMPLETE) in this advertising struct.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;&amp;nbsp;Yes, exactly.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="JPSvanderWalt"]The weird thing is the device name shows up in the nRFConnect app but not in the application.[/quote]
&lt;p&gt;&amp;nbsp;What do you mean by &amp;quot;shows up in the nRF Connect app&amp;quot;?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279267?ContentTypeID=1</link><pubDate>Tue, 10 Nov 2020 13:34:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a67c7cd-3919-476c-a60f-af6d70a358e4</guid><dc:creator>JPSvanderWalt</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Below is my advertising data:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA_BYTES(BT_DATA_UUID128_ALL,
		0xef, 0x41, 0x16, 0xdf, 0x0a, 0x11, 0x4b, 0x49,
		0xae, 0x5a, 0x65, 0x92, 0xd5, 0xa2, 0x6d, 0xa5),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;From what I understand from your last reply, I have to add the device name (&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;BT_DATA_NAME_COMPLETE) in this advertising struct.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static bool eir_found(struct bt_data *data, void *user_data)
{
	bt_addr_le_t *addr = user_data;
	struct bt_uuid *uuid;
	uint16_t u16;
	int err;

	printk(&amp;quot;[AD]: %u data_len %u\n&amp;quot;, data-&amp;gt;type, data-&amp;gt;data_len);
	switch (data-&amp;gt;type) {
	case BT_DATA_UUID128_ALL:
		if (data-&amp;gt;data_len % sizeof(uint16_t) != 0U) {
			printk(&amp;quot;AD malformed\n&amp;quot;);
			return true;
		}&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;I use this EIR function to print the type and length of each EIR packet.&amp;nbsp; The weird thing is the device name shows up in the nRFConnect app but not in the application.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279242?ContentTypeID=1</link><pubDate>Tue, 10 Nov 2020 12:46:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91e63cec-6d5d-49bf-91ee-33503ca17663</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, you should be able to access the device name in the advertising packet,&amp;nbsp;&lt;em&gt;if it is there&lt;/em&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know what setup you are using, but if the advertising device is running with your application, you need to make sure that the device name and type are passed to bt_le_adv_start(), to make sure the device name is actually encoded into the advertising data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;See&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/include/bluetooth/bluetooth.h#L282-L292"&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; bt_data&lt;/span&gt;&lt;/a&gt;,&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/include/bluetooth/bluetooth.h#L295-L309"&gt;&lt;span&gt;BT_DATA&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;_type, _data, _data_len&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/a&gt;, and &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/include/bluetooth/bluetooth.h#L679"&gt;bt_le_adv_start&lt;/a&gt;&lt;span&gt;().&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279120?ContentTypeID=1</link><pubDate>Tue, 10 Nov 2020 05:47:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57351ac4-27b0-4bd9-932e-c2e8851a9d7b</guid><dc:creator>JPSvanderWalt</dc:creator><description>&lt;p&gt;Thank you &lt;a href="https://devzone.nordicsemi.com/members/heidi"&gt;Heidi&lt;/a&gt; for your reply.&amp;nbsp; I will take a look at it.&amp;nbsp; For now, I am filtering by UUID by accessing the advertisement data.&amp;nbsp; I think it should be possible to access the device name as well through the advertisement data.&amp;nbsp; The issue is that the type and data do not show up for the device name.&amp;nbsp; In my case, only type 0x01 and type 0x07 shows up but not type 0x09.&amp;nbsp; My eye caught some privacy/security settings, I guess it might have to do with that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Filtering BLE devices by device name</title><link>https://devzone.nordicsemi.com/thread/279079?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 15:59:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a295c658-91c8-4ff4-9d39-e7b3cf015eea</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, if you use the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/bluetooth/scan.html"&gt;Scanning Module&lt;/a&gt; in advanced mode, you can use a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/bluetooth/scan.html#filter-types"&gt;filter type&lt;/a&gt; that filters the set to a target name.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can add a new filter with this filter type like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/bluetooth/scan.html#c.bt_scan_filter_add"&gt;bt_scan_filter_add&lt;/a&gt;&amp;nbsp;(&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/bluetooth/scan.html#c.bt_scan_filter_type.BT_SCAN_FILTER_TYPE_NAME"&gt;BT_SCAN_FILTER_TYPE_NAME&lt;/a&gt;, data),&lt;/p&gt;
&lt;p&gt;where data is a pointer to the filter data to add, (i.e target names to filter by).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Let me know if you have any more questions!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Heidi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>