bluetooth - nRF52 DK BLE 无法睡眠
问题描述
我正在使用 Nordic nRF52 DK 来制作一个 BLE 应用程序,该应用程序通过具有读取和通知属性的自定义特征来广播数据。
我目前正在为这个项目使用PlatformIO和Visual Studio Code。
为了测量功耗,我使用了Power Profiler 套件。
功耗始终在2.3mA以上,基于Online Power Profiler For Ble ,这是非常高的。
用于 Ble 的在线电源分析器设置:
{
"chip": "1",
"voltage": "3",
"dcdc": "on",
"lf_clock": "lfrc",
"radio_tx": "-40",
"ble_type": "adv",
"ble_int": "1000",
"tx_size": "20"
}
我的目标是让开发板进入休眠状态,直到建立新的蓝牙连接,然后执行 eventQueue 以进行传感器值更新和其他过程。在断开事件之后,板必须再次进入睡眠状态。
首先,我尝试为具有 BLE 功能BLE_BatteryLevel的 mbed 示例项目实现睡眠。
注意:我从示例代码中删除了闪烁事件。
我在 onDisconnectionComplete 回调函数中添加了 _event_queue,break_dispatch(),以强制 ble 从其函数中退出。我不知道这是否是正确的选择,但我想以某种方式退出 ble 的事件队列并让董事会休眠。
我尝试了以下方法:
- 在代码块中使用 DeepSleepLock 对象,以便在其销毁时执行睡眠
- 使用 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');
}
}
}
- 使用无效睡眠()
int main()
{
BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
BatteryDemo demo(ble, event_queue);
demo.start();
ble.shutdown();
sleep();
}
BLE onDisconection 的 Power Profiler 屏幕截图
- Hal_sleep 函数
int main()
{
BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
BatteryDemo demo(ble, event_queue);
demo.start();
ble.shutdown();
hal_sleep();
}
- 在 main 开始时禁用输入和输出
mbed_file_handle(STDIN_FILENO)->enable_input(false);
mbed_file_handle(STDIN_FILENO)->enable_output(false);
- 添加 rtos::Kernel::attach_idle_hook(&sleep); 在 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();
}
似乎没有什么让板子进入睡眠状态,功耗总是很高。
功率分析器屏幕截图
- BLE 启用状态
- BLE 断开状态(睡眠)
我找不到任何使用 BLE 的功耗和睡眠示例。
解决方案
推荐阅读
- rust - clap 默认值 - 如何使用它
- python - 我想在 Python 中单击 Selenium 中的下载按钮
- swift - 为什么我的表格视图不显示任何内容。它具有正确的行数,但没有文本。数据已填充到不同的视图控制器(xcode
- r - 作为函数参数传递时对 data.table 的更新
- arrays - 在 Mongoose 中的另一个数组的对象中查找数组中的字段
- css - css表单元素对齐问题
- python - 使用侦听器事件在同一个 cog 中调用函数,使用 discord.py
- c# - Chrome Devtools 协议和发布
- java - 如何在 JavaFX 聊天应用程序中同步模型和视图模型
- c# - 'Transform.Rotate(Vector3, Space)' 是一种方法,在给定的上下文中无效