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

Initiating more than one scanning instance with SDK15 (s140)?

Hi,

We are developing a new internal engineering tool that mostly does passive scanning on the NRF52840 dongle connected over USB but I'd like to be able to switch to active scanning on demand.

I think what I'd like to do is have multiple scanning instances that have their own callbacks and initialize the active scanning one whenever I need it with a timeout of 30s or so and have the passive scan's callbacks always going on--I'd like them to happen at "the same time" if possible (aka they're both enabled at the same time).  Is something like this possible to do in the current SDK15.3 + S140 6.1.0?  Example below:

static nrf_ble_scan_t m_scan1;                                               /**< Scanning Module instance. */
NRF_SDH_BLE_OBSERVER(m_passive_ble_obs,1,nrf_ble_scan_on_ble_evt,&m_scan1);
ble_gap_scan_params_t scan_params = {0};
scan_params.active = 0x00; /* Active scanning */
scan_params.interval = MSEC_TO_UNITS(5, UNIT_0_625_MS);
scan_params.window = MSEC_TO_UNITS(5, UNIT_0_625_MS);
scan_params.timeout = SCAN_TIMEOUT;
scan_params.scan_phys = BLE_GAP_PHY_1MBPS;


nrf_ble_scan_init_t scan_init;
memset(&scan_init, 0, sizeof(scan_init));

scan_init.p_scan_param = &scan_params;
scan_init.connect_if_match = false;
scan_init.conn_cfg_tag = false;


nrf_ble_scan_init(&m_scan1,&scan_init,passive_scan_evt_handler);
error_code = nrf_ble_scan_start(&m_scan1);


//separate file below
static
nrf_ble_scan_t m_scan2; /**< Scanning Module instance. */
NRF_SDH_BLE_OBSERVER(m_active_ble_obs,2,nrf_ble_scan_on_ble_evt,&m_scan2);

ble_gap_scan_params_t scan_params = {0};
scan_params.active = 0x01; /* Active scanning */
scan_params.interval = MSEC_TO_UNITS(5, UNIT_0_625_MS);
scan_params.window = MSEC_TO_UNITS(5, UNIT_0_625_MS);
scan_params.timeout = SCAN_TIMEOUT;
scan_params.scan_phys = BLE_GAP_PHY_1MBPS;


nrf_ble_scan_init_t scan_init;
memset(&scan_init, 0, sizeof(scan_init));

scan_init.p_scan_param = &scan_params;
scan_init.connect_if_match = false;
scan_init.conn_cfg_tag = false;


nrf_ble_scan_init(&m_scan2,&scan_init,active_scan_evt_handler);
error_code = nrf_ble_scan_start(&m_scan2);


Secondly, if I cannot have two scanning instances at the same time, is there a recommended way to reinitialize the scan without stopping and re-starting?

Thanks,

Manny

  • Hello Manny,

    Is the only difference with your scanning sets the scan_params.active ?

    If so, does it matter that you scan with active = true instead of switching between true or false? The difference will only be whether you send a scan request or not (to get a scan response if the advertiser has a scan response packet).

    You can only scan with one scanning instance at the time. But it shouldn't be a problem to stop and start. Is there a reason why you don't want to do this?

    In addition, I would recommend that you increase your scan interval and window a bit. 5 ms means that you swich scan channel every 5ms. Given that an advertisement takes roughly 0.5ms, you have a relative high chance of getting a half advertising packet, then changing channel. This means that you will miss about 1 in 10 advertising packets. It may not be a problem, but it is something to consider. 

    BR,

    Edvin

Related