如何Debian中命令行操控蓝牙?
- By : Will
- Category : Debian-Like

Debian-Like
1 前言
一个问题,一篇文章,一出故事。
笔者最近希望通过命令行控制蓝牙设备,于是整理此章节。
2 最佳实践
2.1 命令的基本使用
2.1.1 进入蓝牙工具CLI界面
bluetoothctl
可见如下显示,
Agent registered [CHG] Controller 2C:33:58:50:C3:77 Pairable: yes [bluetooth]#
2.1.2 获取命令行帮助
[bluetooth]# help
可见如下显示,
Menu main: Available commands: ------------------- advertise Advertise Options Submenu scan Scan Options Submenu gatt Generic Attribute Submenu list List available controllers show [ctrl] Controller information select Select default controller devices List available devices paired-devices List paired devices system-alias Set controller alias reset-alias Reset controller alias power Set controller power pairable Set controller pairable mode discoverable Set controller discoverable mode discoverable-timeout [value] Set discoverable timeout agent Enable/disable agent with given capability default-agent Set agent as the default one advertise Enable/disable advertising with given type set-alias Set device alias scan Scan for devices info [dev] Device information pair [dev] Pair with device cancel-pairing [dev] Cancel pairing with device trust [dev] Trust device untrust [dev] Untrust device block [dev] Block device unblock [dev] Unblock device remove Remove device connect Connect device disconnect [dev] Disconnect device menu Select submenu version Display version quit Quit program exit Quit program help Display help about this program export Print environment variables
2.2 打开蓝牙设备
[bluetooth]# power on
如果需要相反的操作,请执行以下命令,
[bluetooth]# power off
2.3 扫描蓝牙设备
[bluetooth]# scan on
假设发现如下设备,
Discovery started #... [NEW] Device 1C:52:16:7A:52:BD QCY-HT03 #...
如果需要相反的操作,请执行以下命令,
[bluetooth]# scan off
2.4 配对蓝牙设备
[bluetooth]# pair 1C:52:16:7A:52:BD
2.5 连接蓝牙设备
[bluetooth]# onnect 1C:52:16:7A:52:BD
如果没有预先配对,会提示执行配对,你可以使用如下命令列出可用的设备,
[QCY-HT03]# devices
或者也可以使用如下命令显示已配对设备,
[QCY-HT03]# paired-devices
可见如下输出,
Device 1C:52:16:7A:52:BD QCY-HT03
另外,如果需要反向操作,请使用如下命令,
[QCY-HT03]# disconnect 1C:52:16:7A:52:BD
以上只是暂时断开,如果需要删除设备,请使用如下命令,
[QCY-HT03]# remove 1C:52:16:7A:52:BD
参阅文档
=============
https://www.dianjilingqu.com/567521.html
没有评论