Hi to everyone. I'm starting developing a bluetooth LE application based on the new Nordic SDK using Zephyr.
I currently have two nrf52_pca10040 boards and I'm trying to connect them using advertising scan filtering. I was able to connect them using filter by uuid and filter by name separately. However I don't understand why combined filtering doesn't work.
Here is the relevant code in my scanning init function:
... err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, SERVER_NAME); if (err) { printk("Scanning filters cannot be set\n"); return; } err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, uuid128); if (err) { printk("Scanning filters cannot be set\n"); return; } //match_all parameters set to true it's not working for combined filtering err = bt_scan_filter_enable((BT_SCAN_NAME_FILTER | BT_SCAN_UUID_FILTER), true); if (err) { printk("Filters cannot be turned on\n"); return; } ...
As I have already said, I can connect the two boards using one of the following scan filter enable:
- err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);
- err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
- err = bt_scan_filter_enable((BT_SCAN_NAME_FILTER | BT_SCAN_UUID_FILTER), false);
However if I set the match_all parameter to true, connection can't be established because filters don't match.
This is the definition of the function:
/**@brief Function for enabling filtering. * * @details The filters can be combined with each other. * For example, you can enable one filter or several filters. * For example, (BT_SCAN_NAME_FILTER | BT_SCAN_UUID_FILTER) * enables UUID and name filters. * * @param[in] mode Filter mode: @ref BT_SCAN_FILTER_MODE. * @param[in] match_all If this flag is set, all types of enabled filters * must be matched before generating * @ref BT_SCAN_EVT_FILTER_MATCH to the main * application. Otherwise, it is enough to * match one filter to trigger the filter match event. * * @return 0 If the operation was successful. Otherwise, a (negative) error * code is returned. * */ int bt_scan_filter_enable(u8_t mode, bool match_all);
In my project prj.conf file I am using the following keywords:
CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=1
CONFIG_BT_SCAN_NAME_CNT=1
On the serial output of my client board scanning the advertising information from my server board I am receiving two callbacks on my scan_filter_no_match() function:
Filter not match. Address: fb:fc:06:b3:35:d2 (random) connectable: 1
Filter not match. Address: fb:fc:06:b3:35:d2 (random) connectable: 1
What am I missing?