Correct technique to shutdown and restart external BLE device?

From the code examples I’ve seen for BLE handling is initiated by dispatching an event queue “forever” after any other necessary start handling. We would like to be able to support shutting down and restarting an external BLE devices and supporting code, specifically to save power when BLE is not needed.

Is there a preferred method to doing this? Are there any existing code examples?

When an application is done with BLE; it can call BLE::shutdown. This function will call the terminate method of the Bluetooth driver; releasing the resources.

To break out of an event queue, the method EventQueue::break_dispatch can be used to break out of the dispatch.

In general it is efficient to let the event queue run at all time. The system will go into deep sleep if there is no events to process and peripherals state allows it. State of Bluetooth can be driven by the application state and events in the system. For example, a press on a ON button can post an event in the queue to initialize the Bluetooth system and drive it while a press on an OFF button can post an event to shut Bluetooth down and prepare the system for deep sleep.

Event queues are used by Bluetooth to process events but the same event queue is generally used by the application too. The event queue being dispatched doesn’t mean the system can’t go into deep sleep as well as it doesn’t mean that Bluetooth must be on.

1 Like