This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Filtering BLE devices by device name

How do I filter and connect to BLE devices using the device name in Zephyr?

Parents
  • Hi!

    Yes, if you use the Scanning Module in advanced mode, you can use a filter type that filters the set to a target name.

    You can add a new filter with this filter type like this:

    bt_scan_filter_add ( BT_SCAN_FILTER_TYPE_NAME, data),

    where data is a pointer to the filter data to add, (i.e target names to filter by). 

    Let me know if you have any more questions!

    Best regards,

    Heidi

  • Thank you for your reply.  I will take a look at it.  For now, I am filtering by UUID by accessing the advertisement data.  I think it should be possible to access the device name as well through the advertisement data.  The issue is that the type and data do not show up for the device name.  In my case, only type 0x01 and type 0x07 shows up but not type 0x09.  My eye caught some privacy/security settings, I guess it might have to do with that.

  • Hi!

    Yes, you should be able to access the device name in the advertising packet, if it is there

    I don'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. 

    See struct bt_dataBT_DATA(_type, _data, _data_len), and bt_le_adv_start(). 

  • Hi!

    Below is my advertising data:

    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),
    };

    From what I understand from your last reply, I have to add the device name (

    BT_DATA_NAME_COMPLETE) in this advertising struct.
    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("[AD]: %u data_len %u\n", data->type, data->data_len);
    	switch (data->type) {
    	case BT_DATA_UUID128_ALL:
    		if (data->data_len % sizeof(uint16_t) != 0U) {
    			printk("AD malformed\n");
    			return true;
    		}
    I use this EIR function to print the type and length of each EIR packet.  The weird thing is the device name shows up in the nRFConnect app but not in the application.
Reply
  • Hi!

    Below is my advertising data:

    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),
    };

    From what I understand from your last reply, I have to add the device name (

    BT_DATA_NAME_COMPLETE) in this advertising struct.
    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("[AD]: %u data_len %u\n", data->type, data->data_len);
    	switch (data->type) {
    	case BT_DATA_UUID128_ALL:
    		if (data->data_len % sizeof(uint16_t) != 0U) {
    			printk("AD malformed\n");
    			return true;
    		}
    I use this EIR function to print the type and length of each EIR packet.  The weird thing is the device name shows up in the nRFConnect app but not in the application.
Children
Related