This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to scan devices based name patterns?

I have nRF52840 as the central and nRF52832 as the devices. I have the device names as TELCO_456, TELCO_457, TELCO_458 in the connectable advertisement packet. I have disabled auto connect in the central and I want a scan interrupt when these peripheral devices are available.

How can I set my scan filter settings in the central ?

I'm using SDK16 and SD suitable for this version.

Parents
  • Do you want to add a scan filter for the names "TELCO_456", "TELCO_457" and "TELCO_458" specifically or do you want to add a scan filter for "TELCO_<anything>".

    If the former is the case, you can achieve this by using the nrf_ble_scan library (nRF5_SDK_16.0.0_98a08e2\components\ble\nrf_ble_scan) and using the function nrf_ble_scan_filter_set() and set NRF_BLE_SCAN_NAME_CNT appropriately in the sdk_config.h file (https://devzone.nordicsemi.com/f/nordic-q-a/40186/scanning-module-scan-for-multiple-device-names). Look at the example nRF5_SDK_16.0.0_98a08e2\examples\ble_central_and_peripheral\experimental\ble_app_multirole_lesc\main.c for guidance how to do this.

    If the latter is the case, the nrf_ble_scan library probably needs to be modified slightly. Please tell me and I will instruct how to do this.

    Best regards,

    Simon

  • Obviously it is the latter. I want to get scan interrupt when a device having a name "TELCO_".

  • Could you modify the function nRF5SDK17009d13099\nRF5_SDK_17.0.0_9d13099\components\ble\common\ble_advdata.c-->ble_advdata_name_find(..) accordingly:

    bool ble_advdata_name_find(uint8_t const * p_encoded_data,
                               uint16_t        data_len,
                               char    const * p_target_name)
    {
        uint16_t        parsed_name_len;
        uint8_t const * p_parsed_name;
        uint16_t        data_offset          = 0;
    
        if (p_target_name == NULL)
        {
            return false;
        }
    
    
        parsed_name_len = ble_advdata_search(p_encoded_data,
                                             data_len,
                                             &data_offset,
                                             BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
    
        p_parsed_name = &p_encoded_data[data_offset];
    
        if (   (data_offset != 0)
            && (parsed_name_len != 0)
            /*&& (strlen(p_target_name) == parsed_name_len)*/ //Comment out
            /*&& (memcmp(p_target_name, p_parsed_name, parsed_name_len) == 0))*/ //Comment out
            && (memcmp(p_target_name, p_parsed_name, strlen(p_target_name)) == 0) //Added
        {
            return true;
        }
    
        return false;
    }

    • Then you add the name "TELCO_" using the function nrf_ble_scan_filter_set()

    I have not tested this, but I think it should work.

    Best regards,

    Simon

  • This works and solved my problem, thanks so much Simon!

Reply Children
Related