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 Reply
  • Thanks, it looks like this was the issue. When I put both the name and the uuid in the advertising data packet, I am able to match the filter as expected.

    However, this is still not ideal because the uuid bytes take up the majority of the space in the packet, leaving me with space for only two letters for the name. I have tried to use extended packet (i.e. set extended = 1 in scan params and set NRF_BLE_SCAN_BUFFER to 255 in sdk_config) but it does not seem to work. Do you have any advice for this?

Children
Related