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 help.
    I know it is a pointer to the data type.
    While I just use BT_SCAN_FILTER_TYPE_NAME not short name.
    You can check the answer by Einar that he directly used the device name here "nRF Connect".
    devzone.nordicsemi.com/.../combined-scan-filtering
    At the same time, I defined the device name like here:

    char device_name[]="FF_11";
    char *name = device_name;

    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, name);

    Still not working.

    Thanks again for your help, if you can share the idea.
    BR,
    Ethan

  • Hello Ethan,

    EthanH said:
    Thanks for your help.

    No problem at all, I am happy to help!

    EthanH said:
    I know it is a pointer to the data type.
    EthanH said:
    You can check the answer by Einar that he directly used the device name here "nRF Connect".

    I did not mean to imply that you did not, I thought it had to be passed the output of a macro or specific struct, like in the case of UUID's for instance, my mistake.
    It does indeed seem like it should just accept the name as a string when filtering on name.
    This should indeed work, and so then should your original code:

    #define DEVICE_NAME "nordic"
    
    ..
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, DEVICE_NAME);
    	if (err){
    		printk("Filters cannot be set (err %d)", err);
    		return err;
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);
        if (err){
            printk("Filters cannot be turned on (err %d)", err);
            return err;
        }
    ..


    Could you show me your entire project config? The error you are getting - Error 12 - means ENOMEM, so perhaps the issue here instead lays with the project configuration, even though it looks alright since you have already set CONFIG_BT_SCAN_NAME_CNT = 1.

    Best regards,
    Karl

Reply
  • Hello Ethan,

    EthanH said:
    Thanks for your help.

    No problem at all, I am happy to help!

    EthanH said:
    I know it is a pointer to the data type.
    EthanH said:
    You can check the answer by Einar that he directly used the device name here "nRF Connect".

    I did not mean to imply that you did not, I thought it had to be passed the output of a macro or specific struct, like in the case of UUID's for instance, my mistake.
    It does indeed seem like it should just accept the name as a string when filtering on name.
    This should indeed work, and so then should your original code:

    #define DEVICE_NAME "nordic"
    
    ..
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, DEVICE_NAME);
    	if (err){
    		printk("Filters cannot be set (err %d)", err);
    		return err;
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);
        if (err){
            printk("Filters cannot be turned on (err %d)", err);
            return err;
        }
    ..


    Could you show me your entire project config? The error you are getting - Error 12 - means ENOMEM, so perhaps the issue here instead lays with the project configuration, even though it looks alright since you have already set CONFIG_BT_SCAN_NAME_CNT = 1.

    Best regards,
    Karl

Children
  • Hello Karl,

    Thanks for your help.

    I still have the question about the filter by two different names, can we achieve that?

    As writing in your code, if I give two names (nordic1 and nordic2) are both required to be scanned by name filter, what should I do for the command of bt_scan_filter_add?

    Here is my trial, while the program seems to be stuck and cannot continue。

    #define DEVICE_NAME1 "nordic1"
    #define DEVICE_NAME2 "nordic2"
    
    ...
        err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, DEVICE_NAME1);
    	if (err){
    		printk("Filter1 cannot be set (err %d)", err);
    		return err;
    	}
    	
        err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, DEVICE_NAME1);
            if (err){
    		printk("Filter2 cannot be set (err %d)", err);
    		return err;
    	}

    Thanks again and please share your suggestion here.

    Best Regards,

    Ethan

Related