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

BLE scan filter by device name

Hello there,

It is actually basic for the Bluetooth connection for the nrf52840 using Zephyr, which changed the scan filter by name based on the central UART sample.

As the peripheral device name is assigned "FF_22", and I used the nRF Connect app to connect it.

 

Also edit the prj.conf file below:

CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=1
CONFIG_BT_SCAN_NAME_CNT=1

However, it gave the error:

Can you please tell me where I got missing here to configure name scanning filter?

Many thanks in advance!

Best Regards,

Ethan

    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, "FF_22");
	if (err) {
		LOG_ERR("Scanning filters cannot be set (err %d)", err);
		return err;
	}

	err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);
	if (err) {
		LOG_ERR("Filters cannot be turned on (err %d)", err);
		return err;
	}

Parents
  • Hello Karl,

    Appreciate for your kindly help. It works for the single filter by name, as you suggested.

    Now I just have the additional issue regarding the two peripheral device connection.
    If I need to filter and connect two device by the name, e.g. FF_01 and FF_02, I gave my understanding as below.

    char device_name[2][5]={"FF_01","FF_02"};
    
    char *name = device_name;
    
    ....
    
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name);

    Meanwhile I changed the CONFIG_BT_SCAN_NAME_CNT=2 in the prj.conf.

    The current result is it can filter and connect the first one (FF_01), when I only powered the FF_01.

    While it can't filter and connect the second one (FF_02), when I powered the FF_02 and powered off the FF_01.

    Can you please check which stage is wrong or missing?

    In addition, my final objective is to connect the two devices by the name filter at the same time, transmitting the data directly like the BLE earphone left and right.

    But I should move on step by step to figure out two filter and connection firstly.

    Thanks always for your help!

    Best Regards,

    Ethan

Reply
  • Hello Karl,

    Appreciate for your kindly help. It works for the single filter by name, as you suggested.

    Now I just have the additional issue regarding the two peripheral device connection.
    If I need to filter and connect two device by the name, e.g. FF_01 and FF_02, I gave my understanding as below.

    char device_name[2][5]={"FF_01","FF_02"};
    
    char *name = device_name;
    
    ....
    
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name);

    Meanwhile I changed the CONFIG_BT_SCAN_NAME_CNT=2 in the prj.conf.

    The current result is it can filter and connect the first one (FF_01), when I only powered the FF_01.

    While it can't filter and connect the second one (FF_02), when I powered the FF_02 and powered off the FF_01.

    Can you please check which stage is wrong or missing?

    In addition, my final objective is to connect the two devices by the name filter at the same time, transmitting the data directly like the BLE earphone left and right.

    But I should move on step by step to figure out two filter and connection firstly.

    Thanks always for your help!

    Best Regards,

    Ethan

Children
  • Hello again, Ethan

    EthanH said:
    Thanks always for your help!
    EthanH said:
    Appreciate for your kindly help.

    No problem at all, I am happy to help!

    EthanH said:
    It works for the single filter by name, as you suggested.

    Great! I am glad to hear that it now works for filtering of a single device name, we can then move on to adding the filter for the over device.

    EthanH said:
    Now I just have the additional issue regarding the two peripheral device connection.
    If I need to filter and connect two device by the name, e.g. FF_01 and FF_02, I gave my understanding as below.

    It seems that the bt_scan_filter_add function only reads the first c string of the provided buffer, so you can not provide both names in the same call. Please try to separate the two into two calls to bt_scan_filter_add and see if this makes both devices trigger a filter match.

    EthanH said:
    In addition, my final objective is to connect the two devices by the name filter at the same time, transmitting the data directly like the BLE earphone left and right.

    Are you intending to create an left and right earphone, or are you just using this as an example to illustrate your intentions?
    If you are, have you read anything about the coming LE Audio feature?
    We will soon make our LE Audio software support publicly available, so perhaps this could be interesting for you to have a look at if you are still in the process of evaluating different solutions.
    If you would like to hear more about LE Audio, or discuss the roadmap / future releases, I would have to ask that you reach out to your Regional Sales Manager (RSM) with these questions since we do not discuss future releases here on DevZone. If you do not know who your RSM is, please send me a direct message with your location, so I may provide you with their contact information.

    Best regards,
    Karl

Related