原文链接:https://www.cnblogs.com/god-of-death/p/18297744
查看支持的命令
bluetoothctl -h
进入 bluetooth 环境后输命令不需再加bluetoothctl
查看是否有蓝牙设备
bluetoothctl list // 相当于 hciconfig -a
启动蓝牙设备
bluetoothctl power on // 相当于 hciconfig hci0 up
不启动直接调用 glib 接口会出现:
error(StartDiscovery): GDBus.Error:org.bluez.Error.NotReady: Resource Not Ready
查看控制器信息
bluetoothctl show
可查看 MAC 地址、是否广播、广播的设备名、是否扫描设备等
扫描附近广播的蓝牙设备
bluetoothctl scan on
设置蓝牙可被发现
bluetoothctl discoverable on
设置蓝牙可被配对
bluetoothctl pairable on
查看bluetoothd守护进程打印的错误 log
cat /var/log/messages
tail -n 50 /var/log/messages
和设备配对(不知道什么时候需要发这个指令)
配对前需要先 scan
bluetoothctl pair A4:C1:38:10:09:2C
连接设备
配对前需要先 scan,确保要连接的设备出现在 devices 下,不需要 pair,直接 connect
连接成功可在目录 /var/lib/bluetooth/本机MAC/远端MAC 查看远端蓝牙设备提供的各种服务
设备连接前状态
设备连接后状态