4

仍在询问 BLE 设备和gatttool.

我可以在交互模式下发送一个 char-write-cmd,但我不能在非交互模式下做同样的事情。

这是我在交互模式下发送的:

gatttool -I

[]> connect BTADDR

[BTADDR]> char-write-cmd 0x0040 01

[BTADDR]> exit

通过这种方式,我启动了警报服务,在我的情况下,它会发出蜂鸣器声音。

理论上,非交互模式应该是:

gatttool -b BTADDR --char-write -a 0x0040 -n 01

但这不会向开发板发送请求命令事件,我正在使用开发板进行检查。

4

1 回答 1

4

读取或写入 BLE 外围设备的手动(非交互式)方式:

写入和接收一次回复:(取决于您如何配置 BLE 设备)

sudo gatttool -i hci0 -b xx:xx:xx:xx:xx:xx --char-write-req -a 0x0025 -n ff

无限期地写入和接收回复:(直到您断开与 BLE 设备的连接或停止您的蓝牙客户端)

sudo gatttool -i hci0 -b xx:xx:xx:xx:xx:xx --char-write-req -a 0x0025 -n ff --listen

请注意,我只在最后添加了 --listen 选项。此机制仅在您将 BLE 节点(传感器或执行器)配置为读取和回复时才有效。来源:: 如何使用 gatttool 非交互模式 蓝牙低功耗:在 linux 中侦听通知/指示

尽管如此,我仍然认为控制 BLE 设备或从 BLE 设备获取值不是最好的选择。我的方向是继续前进并使用 API(可能在 python 中)为您完成这项工作。

https://github.com/peplin/pygatt 这个 API 已经被证明可以与 Raspberry Pi Jessie destro 一起使用。

于 2017-03-11T05:42:40.123 回答