[NRF5340] BLE scan filtering by BLE name starting with "ABC~~"

* nrf5340 - nrf connect 2.0.2

The BLE name of our company's product starts with ABC as below and is followed by a number.
(ABC-0000001 ~ ABC-9999999)

The product we need to develop is to find and connect our product that starts with ABC and advertising_data indicates a specific value.


The first method I tried was to modify the device_found part of the observer example.
but, I couldn't find how to get a advertising_data

err = bt_le_scan_start(&scan_param, device_found);

The second method I tried was the central hr coded example.

BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL,scan_connecting_error, scan_connecting);

I tried to get bt_scan_device_info from scan_filter_match for 

adv_data , but I couldn't find a way to filtering the device BLE name that starts with ABC.


err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_NUS_SERVICE);



I would like to ask you how we can implement the method we want.

1.How to get advertising_data in the observer example
2.How to add a filter when BLE NAME starts with ABC- in the central hr coded example

  • The BLE Scan library in nrf/subsys/bluetooth/scan.c does not support filtering on specific portions of an advertisers Complete Local Name, however there is an advertising data type in BT spec called Shortened Local Name.

    If you set your advertisers to use the shortened name "ABC" you can set up a BT_SCAN_FILTER_TYPE_SHORT_NAME and connect to any device with the Shortened Local Name "ABC". 
    After you've connected to a device you can get the Complete Local Name, ie "ABC-xxxxxxxxxx", by by reading the Device Name Characteristic.

    Alternatively you can use shortened names like above and place your "unique device identifier" in the manufacturer specific data. Then you can filter on both BT_SCAN_FILTER_TYPE_SHORT_NAME and BT_SCAN_FILTER_TYPE_MANUFACTURER_DATA. 
    You can call bt_scan_filter_enable(BT_SCAN_SHORT_NAME_FILTER|BT_SCAN_MANUFACTURER_DATA_FILTER, true) to only match if all the enabled filters match, ie. if both the short name = "ABC" and manufacturer specific data = "unique device identifier".

    A third option is to modify the Scan library to support filtering on specific portions of a string, but then you're on your own.

Related