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,

    Thanks for your reply.

    Following your suggestion "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."

    I gave the code here:

    char device_name1[5]="FF_02";
    char device_name2[5]="FF_09";
    char *name1 = device_name1;
    char *name2 = device_name2;
    
    ...
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name1);
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name2);

    It is actually same as the pervious that  it only filter and connect the first one, while no wok for the second.

    And here is the log info:

    Can you please share your code based on this design?

    In addition, I just use the earphone to illustrate my intention, so my case is to BLE connect the two peripheral device and to receive the data from both. It help understand my project here in the overall design.

    Thanks always

    Best Regards,

    Ethan

Reply
  • Hello Karl,

    Thanks for your reply.

    Following your suggestion "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."

    I gave the code here:

    char device_name1[5]="FF_02";
    char device_name2[5]="FF_09";
    char *name1 = device_name1;
    char *name2 = device_name2;
    
    ...
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name1);
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name2);

    It is actually same as the pervious that  it only filter and connect the first one, while no wok for the second.

    And here is the log info:

    Can you please share your code based on this design?

    In addition, I just use the earphone to illustrate my intention, so my case is to BLE connect the two peripheral device and to receive the data from both. It help understand my project here in the overall design.

    Thanks always

    Best Regards,

    Ethan

Children
  • EthanH said:
    I gave the code here:

    Please make sure to check the returned error codes from the bt_scan_filter_add functions as well - I assume you already do so, and that this snippet is just to illustrate, but I mention it just in case.
    Could you confirm that both these calls, and the call to bt_scan_filter_enable, returns successfully?

    EthanH said:
    And here is the log info:

    Could you show me the entire log for the sequence in which you successfully filter match on the first device name, and then unsuccessfully on the second?
    It looks to me like the issue in the log is that the device fails to send data over the BLE connection - even though there is no mention of a connection being established. Error 128 means that there is no valid connection.
    Could it be that you are attempting to call ble_nus_data_send or similar, without first having confirmed whether you are currently in a connection or not?

    EthanH said:
    In addition, I just use the earphone to illustrate my intention, so my case is to BLE connect the two peripheral device and to receive the data from both. It help understand my project here in the overall design.

    Aha, thank you for clarifying, this helps me understand your use case better. I just though I should mention the LE Audio feature since it will be such a huge improvement on audio streaming over BLE. 

    Best regards,
    Karl

Related