10.2. 使用 bluetoothctl连接蓝牙设备
bluetoothctl 是一个命令行工具,可在不依赖图形用户界面的情况下扫描、对、连接和管理连接。
先决条件
-
bluetooth.service单元已启用。
流程
在
bluetoothctl互动提示中输入:$ bluetoothctl检查系统中的 Bluetooth 状态:
[bluetoothctl]# show Powered: no Discoverable: no DiscoverableTimeout: 0x000000b4 Pairable: no如果
bluetoothctl没有开机,请输入:[bluetoothctl]# power on
将您要在系统范围内的设备设置为对模式,并使您的系统可以发现并可以被对:
[bluetoothctl]# discoverable on[bluetoothctl]# pairable on开始扫描蓝牙设备:
[bluetoothctl]# scan on发现的设备列表显示其 MAC 地址和名称(如果可用)。
当您找到设备时,停止扫描:
[bluetoothctl]# scan off- 请注意您要连接的设备的 MAC 地址。
对设备进行对:
[bluetoothctl]# pair XX:XX:XX:XX:XX:XX系统可能会提示您确认系统上的一对代码。
信任您对的设备:
[bluetoothctl]# trust XX:XX:XX:XX:XX:XX可选 : 如果您希望该设备在以后自动连接,您可以将其设置为默认值:
[bluetoothctl]# default XX:XX:XX:XX:XX:XX完成后退出
bluetoothctl:[bluetoothctl]# quit
验证
验证您连接的设备状态:
[bluetoothctl]# devices Device AA:BB:CC:DD:EE:FF Headphones (Connected: yes) Device 11:22:33:44:55:66 Keyboard (Connected: no)[bluetoothctl]# info AA:BB:CC:DD:EE:FF <device information> Connected: yes