首页 > 解决方案 > 在非交互模式下使用 gatttool 连接到 BLE 设备

问题描述

我正在尝试从我的体重秤蓝牙低功耗设备中读取数据。测量后,秤会通过蓝牙发布新数据约一分钟。我可以像这样使用 gatttool 阅读它:

gatttool -b MAC_ADDRESS -I
connect

-I 选项以交互模式运行 gatttool。然后,成功连接后,我得到如下数据:

Indication   handle = 0x0012 value: 02 9c 0e e4 07 08 1c 0b 02 0f 
Indication   handle = 0x0012 value: 02 68 0b e4 07 08 1c 0c 03 06 
Indication   handle = 0x0012 value: 02 18 47 e4 07 08 1f 07 11 3a

我可以从中读取值,但我需要在 gatttool 非交互模式下执行此操作,因此我可以在我的 Qt 应用程序中使用 QProcess 类读取它的输出。gatttool -h关于如何与设备连接并没有多说。没有类似的命令: gatttool -b MAC_ADDRESS connect。有读取或写入的命令,但我不需要这个。我只想连接并等待来自设备的即将到来的数据。谁能告诉我如何使用 gatttool 以非交互模式连接?

谢谢。

标签: bluetooth-lowenergygatttool

解决方案


gatttool 是BlueZ 项目已弃用的八个工具之一。

直接在 Qt 中处理 BLE 通知不是更好吗?

例如:https ://doc.qt.io/archives/qt-5.7/qtbluetooth-heartlistener-example.html


推荐阅读