cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a simple way to turn BLE off and on?

AClif
Associate III

I would like to be able to turn BLE off (e.g. with a timer) even if it is currently connected. I know I can stop it advertising, but this doesn't seem to kill the connection. Basically, after a timeout, I would like the BEL to shutdown and stop using power.

I would then like to turn it back on with an external interrupt (hall effect trigger from a magnet). If I stop the BLE, do i need to reinitialise it, or something similar?

I have used the p2pServer example to find the "stop advertising" code, but it doesn't fully stop the BLE if you are connected to it.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Scott Löhr
Senior II

For the 'Reason' argument, I use BLE_PEER_DEVICE_TERM_POWER_OFF

/**

 * @brief The @ref hci_disconnect is used to terminate an existing connection. The

Connection_Handle command parameter indicates which connection is to be

disconnected. The Reason command parameter indicates the reason for ending

the connection. The remote Controller will receive the Reason command

parameter in the @ref hci_disconnection_complete_event event. All synchronous connections

on a physical link should be disconnected before the ACL connection on the

same physical connection is disconnected.

(See Bluetooth Specification v.5.0, Vol. 2, Part E, 7.1.6)

It is important to leave an 100 ms blank window before sending any new command (including system hardware reset),

since immediately after @ref hci_disconnection_complete_event event, system could save important information in non volatile memory.

 * @param Connection_Handle Connection handle for which the command is given.

 * Values:

 - 0x0000 ... 0x0EFF

 * @param Reason The reason for ending the connection.

 * Values:

 - 0x05: Authentication Failure

 - 0x13: Remote User Terminated Connection

 - 0x14: Remote Device Terminated Connection due to Low Resources

 - 0x15: Remote Device Terminated Connection due to Power Off

 - 0x1A: Unsupported Remote Feature

 - 0x3B: Unacceptable Connection Parameters

 * @retval Value indicating success or error code.

*/

tBleStatus hci_disconnect(uint16_t Connection_Handle, uint8_t Reason);

View solution in original post

2 REPLIES 2
Scott Löhr
Senior II

For the 'Reason' argument, I use BLE_PEER_DEVICE_TERM_POWER_OFF

/**

 * @brief The @ref hci_disconnect is used to terminate an existing connection. The

Connection_Handle command parameter indicates which connection is to be

disconnected. The Reason command parameter indicates the reason for ending

the connection. The remote Controller will receive the Reason command

parameter in the @ref hci_disconnection_complete_event event. All synchronous connections

on a physical link should be disconnected before the ACL connection on the

same physical connection is disconnected.

(See Bluetooth Specification v.5.0, Vol. 2, Part E, 7.1.6)

It is important to leave an 100 ms blank window before sending any new command (including system hardware reset),

since immediately after @ref hci_disconnection_complete_event event, system could save important information in non volatile memory.

 * @param Connection_Handle Connection handle for which the command is given.

 * Values:

 - 0x0000 ... 0x0EFF

 * @param Reason The reason for ending the connection.

 * Values:

 - 0x05: Authentication Failure

 - 0x13: Remote User Terminated Connection

 - 0x14: Remote Device Terminated Connection due to Low Resources

 - 0x15: Remote Device Terminated Connection due to Power Off

 - 0x1A: Unsupported Remote Feature

 - 0x3B: Unacceptable Connection Parameters

 * @retval Value indicating success or error code.

*/

tBleStatus hci_disconnect(uint16_t Connection_Handle, uint8_t Reason);

Thank you, that looks perfect!