cancel
Showing results for 
Search instead for 
Did you mean: 

How to Actively Disconnect Bluetooth Connection of Mobile Phone?

zhangtinglu
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
Remi QUINTIN
ST Employee

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.

View solution in original post

11 REPLIES 11
Remi QUINTIN
ST Employee

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.

Thank you. ACI_GAP_TERMINATE command is what I need.

These command codes are all in the file ble_hci_le.c. I just need to call it. so easy.

Hi Remi I was wondering what the best way to determine the connection handle for a BLE connection is as the ACI_GAP_TERMINATE function requires a Connection handle as its first parameter. Thank you

Yes the first parameter is a connection handle.

Please have a look at AN5270 that describes all functions and their parameters.

Hi Remi, apologies, please let me clarify. I am aware that the first parameter ACI_GAP_TERMINATE is the connection handle however I am not sure how best to access the value of the connection handle once I have made a connection.

Remi QUINTIN
ST Employee

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;

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.

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.