如何访问 pybluez 中的蓝牙低级功能?
是否有用于较低级别 bt 功能的 pybluez 包装函数?我在文档中找不到任何内容。我需要使用的功能与以下功能相同:
l2ping (single ping)
hcitool cc
hcitool rssi
hcitool lq
hcitool tpl
hcitool dc
有没有办法从 pybluez (或实际上任何其他包装器和/或可编写脚本的语言)访问它?
Are there pybluez wrapper functions for lower level bt functionality? I couldn't find anything in the docs. What I need to use is equivalent functionality to:
l2ping (single ping)
hcitool cc
hcitool rssi
hcitool lq
hcitool tpl
hcitool dc
Is there a way to access that from pybluez (or actually any other wrapper and/or scriptable language)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获得完全相同功能的简单方法是让 python 脚本从命令行调用 hcitool。
但对于自定义解决方案,您可以使用 pybluez 发送其他命令生成的相同 HCI 命令数据包。例如,hcitool rssi 只是将 HCI 读取 RSSI 命令发送到本地 BT 适配器,并解析结果。使用 pybluez,您可以打开 HCI 套接字、构造命令数据包并自行解析结果。如果您无权访问定义命令数据包格式的 BT 规范,您可以查看 hcitool 的源代码以了解它们发送的内容,也可以使用 hcidump。
要使用 hcidump,您可以在终端中运行 hcidump 以嗅探本地 HCI 命令流量,同时使用另一个终端通过 hcitool 执行其他命令。使用 hcidump,您将能够捕获原始数据包事务,您可以将其用作您想要从 pybluez 生成的内容的参考。
此示例 http://code .google.com/p/pybluez/source/browse/trunk/examples/advanced/inquiry-with-rssi.py 展示了如何处理 HCI 套接字以手动形成命令数据包和解析结果。您只需要自定义您想要使用的命令。
The simple way to get the exact same functionality would be to just have python scripts invoke hcitool from the command line.
But for the custom solution, you can use pybluez to send the same HCI command packets that those other commands generate. For example, hcitool rssi just causes an HCI Read RSSI command to be sent to the local BT adapter, and parses the result. With pybluez you can open an HCI socket, construct command packets, and parse results yourself. If you don't have access to the BT spec that defines the command packet formats, you can either look at the source code for hcitool to see what they are sending, or you can use hcidump.
To use hcidump, you can run hcidump in a terminal to sniff the local HCI command traffic while you use another terminal to do your other commands via hcitool. With hcidump you will be able to capture the raw packet transactions that you can use as reference for what you want to generate from pybluez.
This example http://code.google.com/p/pybluez/source/browse/trunk/examples/advanced/inquiry-with-rssi.py shows how to deal with HCI sockets for manually forming command packets and parsing results. You just need to customize for the commands you want to use.