开发者

How to access Bluetooth low level functions in 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 (开发者_StackOverflowor actually any other wrapper and/or scriptable language)?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜