I'm doing this:
1. Start a scan, with these parameters:
#define SCAN_INTERVAL 0x00A0 /**< Determines scan interval in units of 0.625 millisecond. */
#define SCAN_WINDOW 0x0050 /**< Determines scan window in units of 0.625 millisecond. */
#define SCAN_TIMEOUT 0x0002 /**< Timout when scanning. 0x0000 disables timeout. */
.active = 0,
.scan_phys = BLE_GAP_PHY_AUTO,
.interval = SCAN_INTERVAL,
.window = SCAN_WINDOW,
.timeout = SCAN_TIMEOUT,
.scan_phys = BLE_GAP_PHY_1MBPS,
.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
2. Looking for a suitable peripheral in BLE_GAP_EVT_ADV_REPORT using the COMPLETE_LOCAL_NAME and MANUFACTURER_SPECIFIC_DATA fields.
3. Calling sd_ble_gap_connect a suitable peripherical is found
Sometimes for some reason the connection process witll timeout and I will get a BLE_GAP_EVT_TIMEOUT event with timeout.src set to BLE_GAP_TIMEOUT_SRC_CONN. As far as I understand this means the connection process timed out. I try to restart scanning in that case. But from that point onward the scanning will be pretty erratic and will most likely not find the pheriperical, even when I can see it advertising in my cell phone using NRF Connect with a ~23ms interval.
It behaves as if the connection was somehow still using resources, even when the calls to sd_ble_gap_scan_start() do not fail and they timeout appropriately without finding anything.
I had this problem using the old s140_nrf52840_5.0.0-2.alpha soft device and I migrated to SDK 15 in hopes this will go away, but I'm still seeing the problem with s140 6.0 SD.
Any ideas?