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

About SDK15.3 scan filter condition selection problem

I have a project that needs to scan and filter the advertising name, uuid and mac address from the device. I will set them one by one and enable them one by one. I set them one by one, and then enable them one by one, at this time, the slaves are normally scanned. Then I tried to change the filter to NRF_BLE_SCAN_ALL_FILTER and changed the following parameters to false, they can still be scanned. Once nrf_ble_scan_filters_enable is used to select the filter condition as NRF_BLE_SCAN_ALL_FILTER and the following parameters are changed to true, the slave device can no longer be scanned. And scaning event is NRF_BLE_SCAN_EVT_NOT_FOUND. So how to solve this problem?

/**@brief Function for handling Scanning Module events.
 */
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;
	
    switch(p_scan_evt->scan_evt_id)
    {
         case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:
         {
              err_code = p_scan_evt->params.connecting_err.err_code;
              APP_ERROR_CHECK(err_code);
         } break;

         case NRF_BLE_SCAN_EVT_CONNECTED:
         {
              ble_gap_evt_connected_t const * p_connected =
                               p_scan_evt->params.connected.p_connected;
             // Scan is automatically stopped by the connection.
             NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x",
                      p_connected->peer_addr.addr[0],
                      p_connected->peer_addr.addr[1],
                      p_connected->peer_addr.addr[2],
                      p_connected->peer_addr.addr[3],
                      p_connected->peer_addr.addr[4],
                      p_connected->peer_addr.addr[5]
                      );
         } break;

         case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
         {
             NRF_LOG_INFO("Scan timed out.");
             scan_start();
         } break;
				 
		 case NRF_BLE_SCAN_EVT_NOT_FOUND:
		 {
				 NRF_LOG_INFO("Scan not found.");
		 } break;
				 
         default:
             break;
    }
}


/**@brief Function for initializing the scanning and setting the filters.
 */
static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

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

    init_scan.connect_if_match = true;
    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);
	
	err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
    APP_ERROR_CHECK(err_code);
	
    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
    APP_ERROR_CHECK(err_code);
		
	err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, &m_target_periph_addr.addr);
    APP_ERROR_CHECK(err_code);
	
    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ALL_FILTER, true);
    APP_ERROR_CHECK(err_code);
		
//    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
//    APP_ERROR_CHECK(err_code);
		
//    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
//    APP_ERROR_CHECK(err_code);
	
//    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
//    APP_ERROR_CHECK(err_code);
}

Hope to get a reply.
June6

Parents
  • Hi, 

    Check out the structure m_scan (The first argument of nrf_ble_scan_init(..) before and after the function runs. If it is all zero after the function call and the three conditions are met, I am not sure what the reasons could be. You could to debug your program in the nrf_ble_scan_init(..) function and check out the different structures, step-by-step, to see exactly what is going on. 

    However, this has nothing to do with scan filtering. This is not set through the function nrf_ble_scan_init(..) (If I'm not mistaken), but through the functions nrf_ble_scan_filter_set(..) and nrf_ble_scan_filters_enable(..). Take a look at the example ble_app_uart_c (in main.c) to see how this works.

    You also can check the address format with this post.

    -Amanda H.

Reply
  • Hi, 

    Check out the structure m_scan (The first argument of nrf_ble_scan_init(..) before and after the function runs. If it is all zero after the function call and the three conditions are met, I am not sure what the reasons could be. You could to debug your program in the nrf_ble_scan_init(..) function and check out the different structures, step-by-step, to see exactly what is going on. 

    However, this has nothing to do with scan filtering. This is not set through the function nrf_ble_scan_init(..) (If I'm not mistaken), but through the functions nrf_ble_scan_filter_set(..) and nrf_ble_scan_filters_enable(..). Take a look at the example ble_app_uart_c (in main.c) to see how this works.

    You also can check the address format with this post.

    -Amanda H.

Children
No Data
Related