Linux上bluezbtmgmt工具的简单python包装器
btmgmt的Python项目详细描述
btmgmt:BlueZ管理API的Python包装器
有关如何使用API的详细信息,请参见https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/mgmt-api.txt:
测试时间:
- 树莓皮3B+
- 树莓皮4
Python2是用Python3.7构建的,尚未经过测试。这个包可以用bdistwheels构建,但是作为源代码分发,这意味着在运行pip install
时,C包装器是在本地编译的。这会稍微慢一点,但会使库更具可移植性。在
依赖项:
- libbluetooth dev:此扩展的头和源代码全部包含在内 在这个repo中,但是python模块是动态链接的 lbluetooth公司在Linux机器上。在
- libreadline dev:这个lreadline.so共享库通常默认安装,但是 从源代码构建此模块需要C头文件。在
安装过程:
$ sudo apt-get install libbluetooth-dev libreadline-dev
$ sudo pip3 install btmgmt
# most of the BTMGMT commands require root privileges, so the library should be
# installed to the root python environment.
用法:
^{pr2}$权限:
如果不想以root用户身份运行,只需将进程(在本例中是Python)的功能设置为具有CAP_NET_ADMIN
。在
sudo setcap cap_net_admin+eip $(readlink -f $(which python3))
您可以通过运行上面带有verify标志的命令来验证这是OK
:
sudo setcap -v cap_net_admin+eip $(readlink -f $(which python3))
可用命令:
select <index> Select a different index
version Get the MGMT Version
commands List supported commands
config Show configuration info
info Show controller info
extinfo Show extended controller info
auto-power Power all available features
power <on/off> Toggle powered state
discov <yes/no/limited> [timeout] Toggle discoverable state
connectable <on/off> Toggle connectable state
fast-conn <on/off> Toggle fast connectable state
bondable <on/off> Toggle bondable state
linksec <on/off> Toggle link level security
ssp <on/off> Toggle SSP mode
sc <on/off/only> Toogle SC support
hs <on/off> Toggle HS support
le <on/off> Toggle LE support
advertising <on/off> Toggle LE advertising
bredr <on/off> Toggle BR/EDR support
privacy <on/off> Toggle privacy support
class <major> <minor> Set device major/minor class
disconnect [-t type] <remote address> Disconnect device
con List connections
find [-l|-b] [-L] Discover nearby devices
find-service [-u UUID] [-r RSSI_Threshold] [-l|-b] Discover nearby service
stop-find [-l|-b] Stop discovery
name <name> [shortname] Set local name
pair [-c cap] [-t type] <remote address> Pair with a remote device
cancelpair [-t type] <remote address> Cancel pairing
unpair [-t type] <remote address> Unpair device
keys Load Link Keys
ltks Load Long Term Keys
irks [--local <index>] [--file <file path>] Load Identity Resolving Keys
block [-t type] <remote address> Block Device
unblock [-t type] <remote address> Unblock Device
add-uuid <UUID> <service class hint> Add UUID
rm-uuid <UUID> Remove UUID
clr-uuids Clear UUIDs
local-oob Local OOB data
remote-oob [-t <addr_type>] [-r <rand192>] [-h <hash192>] [-R <rand256>] [-H <hash256>] <addr> Remote OOB data
did <source>:<vendor>:<product>:<version> Set Device ID
static-addr <address> Set static address
public-addr <address> Set public address
ext-config <on/off> External configuration
debug-keys <on/off> Toogle debug keys
conn-info [-t type] <remote address> Get connection information
io-cap <cap> Set IO Capability
scan-params <interval> <window> Set Scan Parameters
get-clock [address] Get Clock Information
add-device [-a action] [-t type] <address> Add Device
del-device [-t type] <address> Remove Device
clr-devices Clear Devices
bredr-oob Local OOB data (BR/EDR)
le-oob Local OOB data (LE)
advinfo Show advertising features
advsize [options] <instance_id> Show advertising size info
add-adv [options] <instance_id> Add advertising instance
rm-adv <instance_id> Remove advertising instance
clr-adv Clear advertising instances
appearance <appearance> Set appearance
version Display version
quit Quit program
exit Quit program
help Display help about this program
export Print evironment variables
- 项目
标签: