I’m using Nordic nRF52 DK in order to make a BLE application that broadcasts data through a custom characteristic with Read and Notify properties.
I’m currently working with PlatformIO and Visual Studio Code for this project.
To measure the power consumption I am using the Power Profiler kit.
The power consumption is always above 2.3mA which is extremely high based on Online Power Profiler For Ble.
Online Power Profiler For Ble settings:
{
"chip": "1",
"voltage": "3",
"dcdc": "on",
"lf_clock": "lfrc",
"radio_tx": "-40",
"ble_type": "adv",
"ble_int": "1000",
"tx_size": "20"
}
My goal is to put the board to sleep until a new Bluetooth connection is established and then execute the eventQueue for the sensor value update and other processes. After the disconnection event the board must be put to sleep again.
First, I tried to implement sleep for an mbed sample project with BLE features BLE_BatteryLevel.
Note: I removed the blink event from the sample code.
I have added _event_queue,break_dispatch() inside onDisconnectionComplete callback function, in order to force the ble to exit from its functions.
I do not know if it is the right choice but I wanted somehow to exit ble’s event queue and let the board sleep.
I have tried the following:
- Use a DeepSleepLock object in a block of code in order to execute sleep on its destruction
- Using ThisThread::sleep(5s)
int main()
{
while (true)
{
ThisThread::sleep_for('5s');
{
DeepSleepLock dp;
BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
BatteryDemo demo(ble, event_queue);
demo.start();
ThisThread::sleep_for('5s');
}
}
}
- Using void sleep()
int main()
{
BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
BatteryDemo demo(ble, event_queue);
demo.start();
ble.shutdown();
sleep();
}
Power Profiler Screenshot from BLE onDisconection
- Hal_sleep functions
int main()
{
BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
BatteryDemo demo(ble, event_queue);
demo.start();
ble.shutdown();
hal_sleep();
}
- Disable input and output using at the start of main
mbed_file_handle(STDIN_FILENO)->enable_input(false);
mbed_file_handle(STDIN_FILENO)->enable_output(false);
- Adding rtos::Kernel::attach_idle_hook(&sleep); at the start of main()
int main()
{
rtos::Kernel::attach_idle_hook(&sleep);
BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
BatteryDemo demo(ble, event_queue);
demo.start();
}
Nothing seems to put the board on sleep, the power consumption is always high.
Power Profiler Screenshots
- BLE Enabled State
- BLE Disconnected state (sleep)
I couldn’t find any example for power consumption and sleep using BLE.