I'm developing firmware for a BLE peripheral using the DA14681 and am having trouble getting the ble_gap_disconnect function to work.
The firmware is a bridge between USB HID and BLE where the device is working as a BLE peripheral.
One of the requirements on the firmware is that it should be possible to disconnect a connected smartphone app.
When I call the ble_gap_disconnect function with the connection index of the current connection, nothing happens. There is no disconnection done.
How can this be?
Device:
Hi Ulf Soderberg,
Can you see the command being send over the air via a sniffer ? Are you able to get one of the messages that declare the completion of the disconnection procedure BLE_EVT_GAP_DISCONNECTED or BLE_EVT_GAP_DISCONNECT_FAILED ?
Thanks MT_dialog
I have not used a sniffer yet.
I don't see the BLE_EVT_GAP_DISCONNECTED being caught by the switch statement, and there is no case for the BLE_EVT_GAP_DISCONNECT_FAILED event.
I added the following lines in the default case and by setting a breakpoint I could see the BLE_EVT_GAP_DISCONNECT_FAILED event arriving.
default:
if (hdr->evt_code == BLE_EVT_GAP_DISCONNECT_FAILED) {
fff = 1; // variable defined above this code snippet. A breakpoint was set on this line
}
ble_handle_event_default(hdr);
break;
So, what's with the BLE_EVT_GAP_DISCONNECT_FAILED then?
我调试后一点found the problem. Turned out that the "reason" parameter was wrong.
By changing
ble_gap_disconnect(peer_conn_idx, BLE_HCI_ERROR_CON_TERM_BY_LOCAL_HOST);
to
ble_gap_disconnect(peer_conn_idx, BLE_HCI_ERROR_REMOTE_USER_TERM_CON);
it know works ok.
Hi Ulf Soderberg,
Thanks for the indication.
Best Regards MT_dialog