Central_multilink and scanning filter

Hello. 

I try to add scanning filter to central_multilink example from Zephyr examples. Filter is set to short_name, I added filter settings just before start scanner.

static void start_scan(void)
{
	struct bt_le_scan_param scan_param = {
		.type       = BT_HCI_LE_SCAN_PASSIVE,
		.options    = BT_LE_SCAN_OPT_NONE,
		.interval   = SCAN_INTERVAL,
		.window     = SCAN_WINDOW,
	};
	int err;

	struct bt_scan_short_name myname;

	myname.name="DEVX";
	myname.min_len=7;
	
	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_SHORT_NAME, &myname);
	if (err) 
	{
		printk("\nScanning filters cannot be set (err %d)\n", err);
	}

	err = bt_scan_filter_enable(BT_SCAN_SHORT_NAME_FILTER, false);
	if (err) 
	{
		printk("\nFilters cannot be turned on (err %d)\n", err);
	}

	err = bt_le_scan_start(&scan_param, device_found);
	if (err) 
	{
		printk("Scanning failed to start (err %d)\n", err);
		return;
	}

	printk("Scanning successfully started\n");
}
 

 Unfortunatelly it doesn't work. If I set in prj.conf: 

CONFIG_BT_SCAN_SHORT_NAME_CNT=1
application return: Scanning filters cannot be set (err -12)
I try to set:
CONFIG_BT_SCAN_SHORT_NAME_CNT=2
but scanner connect to every device.
I increased heap and stack but it doeasn't help.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=4096
My questions:
1. Can I use NCS lib in example from Zephyr? (which I did)
2. What memory is te problem in err -12 ?
Best regards
PW
 

Parents Reply Children
  • Thanks for the answer. Filter acceptance list is connected with bonding in exercise 2. Is it suitable for project where bonding doesn't exist? And second more general question. May I use some Zephyr bluetooth example and add some lib from NCS? Is it good way?

    PW

  • Hi,

    PW said:
    Filter acceptance list is connected with bonding in exercise 2. Is it suitable for project where bonding doesn't exist?

    You may use a filter acceptance list in setups where the devices for instance shares a connection and/or bonding/pairing, so bonding is not a mandatory requirement.

    PW said:
    And second more general question. May I use some Zephyr bluetooth example and add some lib from NCS? Is it good way?

    In nRF Connect SDK (NCS) we have Zephyr as one of the repositories that forms our SDK. This means that the Zephyr samples, including the Zephyr bluetooth samples are a part of NCS and you can add libraries from NCS to the Zephyr samples

    In your NCS installation you will for instance find BLE samples in both <ncs install location>/<ncs version>/nrf/samples/bluetooth and inside of <ncs install location>/<ncs version>/zephyr/samples/bluetooth. 

    Do note that the Zephyr fork in NCS is not up to date with the main Zephyr repository, so if you wish to use some bleeding edge features and samples straight from Zephyr SDK/Zephyr main fork, then you might run into compatability issues

    See https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/introduction.html and  https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/ to learn more about how NCS is put together

    Let me know if this answers your question! 

    Kind regards,
    Andreas

  • Hi PW. Have you successfully enable the scan filter in central_multlink code? I have the similar problem as you describe even enable and add scan filter it will still connect to every nearby devices.

  • Hi ropz. 

    I decided to use UUID filter and it works very good.

    static int scan_init(void)
    {
    	int err;
    	struct bt_scan_init_param scan_init = {
    		.connect_if_match = 0,
    		.scan_param = BT_LE_SCAN_PARAM(
    					  BT_HCI_LE_SCAN_PASSIVE,
    					  BT_LE_SCAN_OPT_NONE,
    					  SCAN_INTERVAL,
    					  SCAN_WINDOW)
    	};
    
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_MY_UUID_SERVICE);
    	if (err) 
    	{
    		LOG_ERR("Scanning filters cannot be set (err %d)", err);
    		return err;
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
    	if (err) 
    	{
    		LOG_ERR("Filters cannot be enabled (err %d)", err);
    		return err;
    	}
    
    	LOG_INF("Scan init OK");
    	return err;
    }

    Best regards

    PW

Related