Hi,
Is there any nordic softdevice API to know whether scanning is going on or it is stopped.
Thanks
Hi,
Is there any nordic softdevice API to know whether scanning is going on or it is stopped.
Thanks
Hi,
A quick and dirty solution is to call sd_ble_gap_scan_start()
this function will return NRF_ERROR_INVALID_STATE
if scanning is already in progress or a connection is in the process of being established.
A different solution is to start scanning with sd_ble_gap_scan_start()
(naturally you should be able to have control over this) and set a flag like is_scanning
, or something like that, to indicate that you are scanning. Then you can wait for a BLE_GAP_EVT_TIMEOUT
event and check the source of the error like this:
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
....
....
....
case BLE_GAP_EVT_TIMEOUT:
if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
printf("SCANNING TIMED OUT\r\n");
err_code = sd_ble_gap_scan_stop();
APP_ERROR_CHECK(err_code);
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
}
break;
....
....
So now you know when scanning starts and stops.
Hi,
A quick and dirty solution is to call sd_ble_gap_scan_start()
this function will return NRF_ERROR_INVALID_STATE
if scanning is already in progress or a connection is in the process of being established.
A different solution is to start scanning with sd_ble_gap_scan_start()
(naturally you should be able to have control over this) and set a flag like is_scanning
, or something like that, to indicate that you are scanning. Then you can wait for a BLE_GAP_EVT_TIMEOUT
event and check the source of the error like this:
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
....
....
....
case BLE_GAP_EVT_TIMEOUT:
if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
printf("SCANNING TIMED OUT\r\n");
err_code = sd_ble_gap_scan_stop();
APP_ERROR_CHECK(err_code);
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
}
break;
....
....
So now you know when scanning starts and stops.
Thanks Martin!!
If I go for second solution, BLE_GAP_EVT_TIMEOUT event occurs only when sd_ble_gap_scan_start() api is called with timeout. I have implemented scan without timeout. I do set a flag that keeps the track of scan status. But I have observed sometimes when there are few connect disconnect, flag is set but I wont receive any BLE_GAP_EVT_ADV_REPORT event. I assume it is because scan is stopped. I also have a flag to check that scanning and connection process wont happen at same time.
In how many cases BLE_GAP_TIMEOUT_SRC_SCAN is received?