This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Central device, match filter for a substring of the name

Hi, 

I am trying to develop a central device that would scan for devices that start with a prefix XYZ_, for example XYZ_1111, XYZ_1245,...

Is there some way to add a name scan filter for the central device in SDK 15.3 that would trigger an event match filter when it finds a device beginning with a prefix?

Thank you.

  • I would recommend you to take a look at the BLE Heart Rate Collector Example located in <InstallFolder>\examples\ble_central\ble_app_hrs_c. It demonstrates how to perform scan filtering based on advertising name by using the nrf_ble_scan Scanning Module.

    The scan library checks the advertising name in the following manner: nrf_ble_scan_on_ble_evt()--> nrf_ble_scan_on_adv_report()-->adv_name_compare()-->ble_advdata_name_find(). However, it will only return true if the name in the filter matches name in the advertising packet by length and content.

    In order to compare only the x first characters you will have to modify the ble_advdata_name_find() in the following manner:

    Swap these lines:

    if (   (data_offset != 0)
        && (parsed_name_len != 0)
        && (strlen(p_target_name) == parsed_name_len)
        && (memcmp(p_target_name, p_parsed_name, parsed_name_len) == 0))

    With these:

    if (   (data_offset != 0)
        && (parsed_name_len != 0)
        && (parsed_name_len >= strlen(p_target_name))
        && (memcmp(p_target_name, p_parsed_name, strlen(p_target_name)) == 0))

    I have not tested it, but I think it should work. However, this modification will change the library (ble_advdata.c), and might mess up other projects using that library. In order to avoid this you can make a copy of the library or create your own modified function.

    Best regards,

    Simon

Related