I'm using S112 and SDK 14.2 to target NRF52810, but using the PCA10040 DK for now.
I've been coming back this issue multiple times over the past couple of months, still unable to find any hints online. This intermittent issue seems to happen maybe 1 in 10-15 times when disconnecting from my Android device. My firmware needs to handle all kinds of broken Android Bluetooth implementations on all devices (and iOS) so I'm not worrying about device specifics at the moment, just how to deal with weird situations like this in the firmware.
Normal procedure:
- App searching for NRF device
- Press button on DK to start advertising
- Connection
- Read/write some characteristics
- sd_ble_gap_disconnect() returns 0
- BLE_GAP_EVT_DISCONNECTED event
- All ok
When it breaks:
- App searching for NRF device
- Press button on DK to start advertising
- Connection
- Read/write some characteristics
- sd_ble_gap_disconnect() returns 0
- Seems to hang around still connected (using too much power) for 2-5 seconds
- conn_params_error 8 (NRF_ERROR_INVALID_STATE)
- Hangs around for another ~10 seconds using power
- Finally BLE_GAP_EVT_DISCONNECTED
I know the Bluetooth implementation on some Android devices is awful and my guess was that the phone is hanging onto the connection in the background (this happens too often), but if I turn off the phone's Bluetooth (reliably kills background connections) during step 8, it still takes many seconds before we hit step 9.
It seems the softdevice is failing to disconnect for some reason, the connection params update thinks the device is in an invalid state (probably looks like it is disconnected) but it hasn't really finished disconnecting. Any ideas what could be causing this to happen?
Thanks in advance.