Skip to main content
zhangtinglu
Associate III
October 15, 2019
Solved

How to Actively Disconnect Bluetooth Connection of Mobile Phone?

  • October 15, 2019
  • 4 replies
  • 4447 views

When STM32WB is used as slave device, how to actively disconnect Bluetooth connection of mobile phone?

This topic has been closed for replies.
Best answer by Remi QUINTIN

Not sure I understand what you mean by "actively disconnect" : Either you expect the android application to disconnect automatically the connection each time it is not needed anymore=> This is an decision to be made by the android application (apk) for which the STM32WB has no influence.

Or you expect the STM32WB to inform the mobile that it will stop the connection. In this case you can use the HCI_DISCONNECT command or an higher level command ACI_GAP_TERMINATE that requests the controller to terminate the connection. Then the STM32WB application will wait for the EVT_DISCONN_COMPLETE GAP event.

Please have a look at AN5270 that describe both commands.

4 replies

Remi QUINTIN
Remi QUINTINBest answer
Technical Moderator
October 15, 2019

Not sure I understand what you mean by "actively disconnect" : Either you expect the android application to disconnect automatically the connection each time it is not needed anymore=> This is an decision to be made by the android application (apk) for which the STM32WB has no influence.

Or you expect the STM32WB to inform the mobile that it will stop the connection. In this case you can use the HCI_DISCONNECT command or an higher level command ACI_GAP_TERMINATE that requests the controller to terminate the connection. Then the STM32WB application will wait for the EVT_DISCONN_COMPLETE GAP event.

Please have a look at AN5270 that describe both commands.

zhangtinglu
Associate III
October 17, 2019

Thank you. ACI_GAP_TERMINATE command is what I need.

Remi QUINTIN
Technical Moderator
April 26, 2021

The ACI_HAL_GET_LINK_STATUS command returns the status of the maximum eight Bluetooth Low Energy links possibly managed by the device, returning a array of the 8 connection handles

But the connection_handle is returned once the connection is established in the connection_complete_event with the structure:

typedef PACKED(struct)

{

 uint8_t Status;

 uint16_t Connection_Handle;

 uint8_t Role;

 uint8_t Peer_Address_Type;

 uint8_t Peer_Address[6];

 uint16_t Conn_Interval;

 uint16_t Conn_Latency;

 uint16_t Supervision_Timeout;

 uint8_t Master_Clock_Accuracy;

} hci_le_connection_complete_event_rp0;

TomC
Senior
April 27, 2021

Thank you for your response Remi, I was able to terminate the connection by extracting the Connection Handle via the EVT_LE_CONN_COMPLETE case in the function SVCCTL_App_Notification in appl_ble.c.

Kedar.cognota
Associate II
August 20, 2021

Hi @Community member​ 

can you elaborate more on this topic. I also want to implement the same way.

I want to connect and disconnect BLE server controlled by switch on BLE client.

RPowe.9.306
Associate III
November 11, 2022

I use aci_gap_terminate with the correct connection handle and the reason 0x13 (Remote User Terminated Connection). The connection drops (ST BLE Sensor states: "Error during the connection with the node HRSTM). However I don't get an HCI_DISCONNECTION_COMPLETE_EVENT event. Stepping through, aci_gap_terminate hags on calling hci_send_req!!!

RPowe.9.306
Associate III
November 11, 2022

*hangs