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

sd_ble_gap_disconnect returns success but BLE_GAP_EVT_DISCONNECTED event doesn't happen until a while later. A conn_params_error happens during this period.

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:

  1. App searching for NRF device
  2. Press button on DK to start advertising
  3. Connection
  4. Read/write some characteristics
  5. sd_ble_gap_disconnect() returns 0
  6. BLE_GAP_EVT_DISCONNECTED event
  7. All ok

When it breaks: 

  1. App searching for NRF device
  2. Press button on DK to start advertising
  3. Connection
  4. Read/write some characteristics
  5. sd_ble_gap_disconnect() returns 0
  6. Seems to hang around still connected (using too much power) for 2-5 seconds
  7. conn_params_error 8 (NRF_ERROR_INVALID_STATE)
  8. Hangs around for another ~10 seconds using power
  9. 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. 

Related