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

How to achieve passive scanning?

I would like to perform observer role scanning i.e. passive scanning. I am using nRF52832, S132, SDK 15.2.0. I am trying as follows.

NRF_BLE_SCAN_DEF(m_scan); 

static ble_gap_scan_params_t m_scan_param = /**< Scan parameters requested for scanning and connection. */
{
.active = 0,
.interval = 160
.window = 120
.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
.timeout = 0,
.scan_phys = BLE_GAP_PHY_AUTO,
.extended = false,
};

uint32_t BLE_Scan_Init(void)
{
ret_code_t err_code;
nrf_ble_scan_init_t init_scan;

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, BLE_Scan_Evt_Handler);
APP_ERROR_CHECK(err_code);

return err_code;
}

The scanning is only happening (getting advertising report) when I set active = 1 in the m_scan_param. 

What I am doing wrong here?

What is the way to achieve passive scanning? 

  • Hi 

    Can you confirm which SoftDevice version you are using?

    We can't reproduce the issue using SDK v17.0.0 and S132 v7.0.1, your settings work fine, but it might be different in older version of the SoftDevice. 

    Best regards
    Torbjørn

  • Hi Torbjorn,

    Thanks for reply.

    We use S132 v6.1.1 and SDK v15.2.0.

    My thought is to set active = 0 and so the application will get only the non connectable advertising reports.

    But setting active = 0, no advertising is reported whether it is connectable or non-connectable.

    It is just simple settings but not working as expected.

    Best Regards,

    Jebakumar

  • Hi Jebakumar

    Is there any reason you commented out the following line:

    //init_scan.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;

    That will probably cause issues. 

    I was able to modify the blinky_c example with your settings, and it works fine both with the .active flag cleared or not:

    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
        static ble_gap_scan_params_t m_scan_param = /**< Scan parameters requested for scanning and connection. */
        {
        .active = 0,
        .interval = 160,
        .window = 120,
        .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
        .timeout = 0,
        .scan_phys = BLE_GAP_PHY_AUTO,
        .extended = false,
        };
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.p_scan_param = &m_scan_param;
        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);
    
        // Setting filters for scanning.
        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_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
        APP_ERROR_CHECK(err_code);
    }

    Best regards
    Torbjørn

Related