Hi!
I have a question regarding the scan timeout. The situation is the following:
On a nRF52840, I repeatedly perform scans every 120s (which is controlled by a CC Interrupt on the RTC). The scan should time out after 17s, which works well for a little less than 2 hours but then all of a sudden I will never again get a timeout event. If I try to manually stop scanning using sd_ble_gap_scan_stop(), I get NRF_ERROR_INVALID_STATE. Same goes for restarting using sd_ble_gap_scan_start(&scan_param, &m_scan_buffer). After going back and forth for a while, the system resets (this is due to my watchdog, which is fed by radio notifications). Afterwards, we can play this whole game again.
Here is my startup sequence:
#define SCAN_INTERVAL MSEC_TO_UNITS(10005, UNIT_0_625_MS)
#define SCAN_WINDOW MSEC_TO_UNITS(150, UNIT_0_625_MS)
#define SCAN_DURATION_MSEC 17000
static ble_gap_scan_params_t scan_param;
static uint8_t memory_access_in_progress = false;
static uint8_t m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; // Buffer where advertising reports will be stored by the SoftDevice
static system_state_t *system_state;
// Buffer where advertising reports will be stored by the SoftDevice
ble_data_t m_scan_buffer =
{
m_scan_buffer_data,
BLE_GAP_SCAN_BUFFER_MIN
};
// Set scanning parameters
scan_param.active = 0;
scan_param.interval = SCAN_INTERVAL;
scan_param.window = SCAN_WINDOW;
scan_param.timeout = MSEC_TO_UNITS(SCAN_DURATION_MSEC, UNIT_10_MS);
scan_param.scan_phys = BLE_GAP_PHY_1MBPS;
scan_param.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
scan_param.channel_mask[4] = 0x0;
uint32_t ret;
if (nrf_fstorage_is_busy(NULL))
{
memory_access_in_progress = true;
return NRF_ERROR_INTERNAL;
}
ret = sd_ble_gap_scan_start(&scan_param, &m_scan_buffer);
if(ret == NRF_ERROR_INVALID_STATE) {
NRF_LOG_INFO("SCAN: Scanning had already started.");
ret = NRF_SUCCESS;
}
APP_ERROR_CHECK(ret);
Can you figure out a reason why this is happening?