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 Karl,

    Thank you for the help and info firstly.

    Here is my prj.conf file:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Enable the UART driver
    # CONFIG_NRFX_UARTE0=y
    # CONFIG_SERIAL=y
    # CONFIG_CONSOLE=y
    # CONFIG_UART_CONSOLE=y
    
    CONFIG_USB=y
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_PRODUCT="FF"
    CONFIG_USB_UART_CONSOLE=y
    
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
    
    # Enable the BLE stack with GATT Client configuration
    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_GATT_CLIENT=y
    
    # Enable the BLE modules from NCS
    CONFIG_BT_NUS_CLIENT=y
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    CONFIG_BT_SCAN_NAME_CNT=1
    CONFIG_BT_GATT_DM=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    CONFIG_BT_DEBUG_ATT=y
    
    CONFIG_ASSERT=y
    

    Please check it, I think the issue mainly is relevant to the configuration as you were saying.

    Best Regards

    Ethan

  • Hello again, Ethan

    I do not immediately see anything wrong with your prj.conf either, unfortunately - it looks alright to me.
    I went ahead and tried this on my end - starting with the BLE UART central example, and modifying it with the code lines from my previous comment, with a prj.conf similar to yours (with CONFIG_BT_SCAN_NAME_CNT=1), and it works immediately.
    Looking into the source code of the scanning library I see that it is the count for the name filter that is triggering the ENOMEM error. Could you try to increase the CONFIG_BT_SCAN_NAME_CNT = 2, and see if this error persists?
    I ask because I suspect that the name filter might have been set already somewhere else in your code.
    Could it be that you have already attempted to implement the 'filter for two different names' you mention in your later comment, and that this is thus exceeding the CONFIG_BT_SCAN_NAME_CNT=1 configuration?

    If this does not resolve your issue, could you share your entire main.c file with me, so I may take a look?

    EthanH said:

    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?

    Do I understand you correctly that you would like to scan for two different names, and be alerted if either of them is found?
    If so, you will need to set CONFIG_BT_SCAN_NAME_CNT=2, and add and enable the two different name filters like I showed in my previous comment.
    If the scanning module is using the Normal filter mode it will trigger a filter match if any one of the enabled filters are met - unlike multifilter mode, which requires a combination of filters to be met.

    Best regards,
    Karl

Reply
  • Hello again, Ethan

    I do not immediately see anything wrong with your prj.conf either, unfortunately - it looks alright to me.
    I went ahead and tried this on my end - starting with the BLE UART central example, and modifying it with the code lines from my previous comment, with a prj.conf similar to yours (with CONFIG_BT_SCAN_NAME_CNT=1), and it works immediately.
    Looking into the source code of the scanning library I see that it is the count for the name filter that is triggering the ENOMEM error. Could you try to increase the CONFIG_BT_SCAN_NAME_CNT = 2, and see if this error persists?
    I ask because I suspect that the name filter might have been set already somewhere else in your code.
    Could it be that you have already attempted to implement the 'filter for two different names' you mention in your later comment, and that this is thus exceeding the CONFIG_BT_SCAN_NAME_CNT=1 configuration?

    If this does not resolve your issue, could you share your entire main.c file with me, so I may take a look?

    EthanH said:

    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?

    Do I understand you correctly that you would like to scan for two different names, and be alerted if either of them is found?
    If so, you will need to set CONFIG_BT_SCAN_NAME_CNT=2, and add and enable the two different name filters like I showed in my previous comment.
    If the scanning module is using the Normal filter mode it will trigger a filter match if any one of the enabled filters are met - unlike multifilter mode, which requires a combination of filters to be met.

    Best regards,
    Karl

Children
No Data
Related