Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Address filter not match issue in BLE scanning

Hi Nordic, 

I am working on project with nrf52840 , which is a central to connect other device. we will enter the MAC address to central, and setup the scaning filter.

the central device is development with SoftDevice nRF5_SDK_17.0.0_9d13099.

so far the function is work , but we found a issue now, the address filter cannot return match result. 

following is the code which is initial the scanning and the filter. 

/**@brief Function for initialization scanning and setting filters.
 */
static void scan_init(uint8_t *target_MAC)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;
    uint8_t u8_filter_mode = 0x00;

    memset(&init_scan, 0, sizeof(init_scan));

    init_scan.p_scan_param     = &m_scan_param;
    init_scan.connect_if_match = false;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);


    if(NRF_BLE_SCAN_ADDRESS_CNT >0){
        ble_gap_addr_t st_target_periph_addr ={
            .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
            .addr = {0}
        };

        memcpy(st_target_periph_addr.addr, target_MAC, 6);
        NRF_LOG_HEXDUMP_INFO(st_target_periph_addr.addr,6);

        /// MAC address filter
        err_code = nrf_ble_scan_filter_set(&m_scan,SCAN_ADDR_FILTER,st_target_periph_addr.addr);
        APP_ERROR_CHECK(err_code);

        u8_filter_mode |= NRF_BLE_SCAN_ADDR_FILTER;
    }

    if (NRF_BLE_SCAN_UUID_CNT > 0){
        ble_uuid_t uuid =
        {
            .uuid = TARGET_UUID,
            .type = BLE_UUID_TYPE_BLE,
        };
        
        // UUID filter 
        err_code = nrf_ble_scan_filter_set(&m_scan,SCAN_UUID_FILTER,&uuid);
        APP_ERROR_CHECK(err_code);
    
        u8_filter_mode |= NRF_BLE_SCAN_UUID_FILTER;
    }
    
    err_code = nrf_ble_scan_filters_enable(&m_scan,u8_filter_mode,false);
    APP_ERROR_CHECK(err_code);

}

and I checked the event case "NRF_BLE_SCAN_EVT_NOT_FOUND" content, the central can found the device , just the  MAC address not match. 

do you have any suggestion for how to create a correct scanning filter.

 

Thanks

Parents Reply Children
Related