Hi,
I got an error BLE_ERROR_INVALID_CONN_HANDLE at the function sd_ble_gap_disconnect. I know that this error has to do with the fact that an invalid connection handle is given.
That's why I first check if there is a link, and if so then disconnect. See my code below:
uint32_t err_code;
ble_conn_state_conn_handle_list_t conn_handles = ble_conn_state_conn_handles();
uint32_t periph_link_cnt = ble_conn_state_peripheral_conn_count();
NRF_LOG_DEBUG("conn handles len: %d", conn_handles.len);
NRF_LOG_DEBUG("periph_link_cnt: %d", periph_link_cnt);
if (periph_link_cnt > 0) {
for (uint8_t i = 0; i < conn_handles.len; i++) {
NRF_LOG_DEBUG("idle connection, disconnect conn_handle %d", conn_handles.conn_handles[i]);
err_code = sd_ble_gap_disconnect(conn_handles.conn_handles[i],
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
}
}
Our app does a manual disconnect, by writing a certain value to a custom char I've written, to invoke disconnect from the device, and also from the android app itself. If we don't do the disconnect from device sometimes Android stack doesn't disconnect and the stack gets corrupted, but that's another topic. Anyway, that's why we always do a manual disconnect from device. Mostly this goes well, but in some situations I think the android disconnect happens after the checking if there is a link_cnt. So it will go into the if loop and there it tries to do a disconnect, but then there are no conn_handles anymore.
So my main question is, can I just skip this error handling of sd_ble_gap_disconnect? Are these errors just for information, or can it corrupt the bluetooth stack in a way and should it be fixed by the application by a reboot? Because I testes a couple times to invoke a manual disconnect without being connected and no error handling, and everything went fine.