BLE.begin() -> BLE.end() -> BLE.begin() [again]

Hi guys,

I am wondering if it is possible to turn off BLE when I do not need to send some data, and turn it on again when data is ready to be sent? I am trying to enable that part, but every time when BLE.end() function is called seems that I am not able to start the BLE again after some sleep time. In my case, I want to send the simple message from Arduino to my PC, and it works when BLE is constantly ON, but I want to turn it off in order to keep my device in a sleep state, and in that case, decrease the current consumption. Is this implementation possible with the Arduino BLE library?

P.S.
In my case, the BLE service, characteristics, advertising,... are defined in the setup function. Thanks in advance. Cheers! :slight_smile:

That is not how BLE works and how it is intended to be used. BLE peripherals/server are supposed to advertise their service as long as they are active. Advertisements uses very little energy. BLE peripherals provide a service aka some sensor data and the central/client device decides when it wants to read the data. BLE peripherals do not "send" data. The central devices reads and writes the characteristics.
You can save some energy by detecting whether a central is connected and then disable the sensor.
There were some posts about minimizing power a long time ago. Might be worth searching for them in the forum.

How is your central devices supposed to know when you enable the peripheral? It will need to scan pointlessly all the time just in case your peripheral decides some new data is available.
How do you know whether the client wants to get some data from your sensor when you are sleeping all the time?

I will not use the BLE communication for the full time of my experiment. The idea why I want to turn off BLE is because I want to have the consumption ~350microAmpere (during the sleep state) for most of the time, and when BLE is on the consumption is around 3mA. In my case, each time the Arduino takes a photo (using the Arducam module) I will need to decide whether to continue with local inference (using the tinyML model for person detection) or to send the image to my PC, which will act as a BLE receiver (on PC side I enabled BLE part by using the Bleak library). In case, I execute the local inference, I want to use BLE to send the simple data to PC (0 or 1), just to inform the other side that the person is/is not detected on the image. In my mind, the only way to do that is to begin BLE when it's needed to be used, and immediately after data transfer is done put it off in order to save energy. I know that BLE does not consume too much power, but in my case when the external power source is used (solar panel) everything above 1mA is critical to operating. I tested the communication between the Arduino board and my PC, and it works, I am able to send the data but only if BLE is ON during all time. I do not know if there is any other way to decrease the current (in the magnitude of sleep one) without considering BLE begin/end cycles? I hope that you can understand the point of my research as it's a bit complicated :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.