22. bluetooth

本章配套视频介绍:

../../../_images/video.png

《15-无线网卡连接WiFi和蓝牙》

https://www.bilibili.com/video/BV1Y24y1A7xH/

如果需要具有蓝牙的能力,可以通过插入USB免驱蓝牙, 或者同时支持蓝牙和wifi的USB或mini-pcie无线网卡,以下是同时支持WiFi和蓝牙的网卡

USB接口:

  • RTL8821CU

mini-pcie接口:

  • AX210

  • RTL8822CE

  • RTL8852BE

  • Intel7265

  • Intel8260

如果遇到其他网卡,插入后无法识别或使用,需要修改内核或者移植驱动。

22.1. 桌面系统配置蓝牙

默认蓝牙是打开的状态,点击右上角选项找到蓝牙设置

未找到图片08|

在打开的界面中,找到需要连接的蓝牙设备,然后双击点击即可连接。

未找到图片08|

如果连接的设备需要配对,则会弹出PIN码确认窗口,需要板卡和连接的设备都进行确认,确认后即可连接。

未找到图片08|

22.2. 命令行配置蓝牙

使用命令行配置蓝牙,我们需要使用工具—-bluetoothctl

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 进入bluetoothctl命令行
bluetoothctl
# 进入bluetoothctl命令行后,类似:[bluetooth]#
# Controller代表arm板上的蓝牙设备,Device代表蓝牙耳机
# 按如下步骤初始化蓝牙设备,并连接蓝牙耳机
# 查看帮组
help

power on
agent on
default-agent
# 启动扫描
scan on
# 假如蓝牙耳机地址为:04:8C:9A:F2:54:4B
trust 04:8C:9A:F2:54:4B
# 配对
pair 04:8C:9A:F2:54:4B
# 连接
connect 04:8C:9A:F2:54:4B

# 查看蓝牙耳机信息
info 04:8C:9A:F2:54:4B

# 断开连接
disconnect 04:8C:9A:F2:54:4B
# 不想自动连接上蓝牙耳机,可以删除配对信息
remove 04:8C:9A:F2:54:4B

更多关于命令行蓝牙连接,可参考 https://blog.csdn.net/chenjk10/article/details/90317028

22.3. 关闭蓝牙验证

默认开启蓝牙连接验证,如果需要关闭验证可以操作以下步骤:

安装工具包:

1
2
sudo apt update
sudo apt install bluez util-linux

新建/usr/lib/systemd/system/bt-agent.service 写入以下内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit]
Description=Bluetooth Auth Agent
After=bluetooth.service
PartOf=bluetooth.service

[Service]
Type=simple
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
User=root

[Install]
WantedBy=bluetooth.target

最后启动服务,添加到系统自启动服务中

1
2
sudo systemctl start bt-agent
sudo systemctl enable bt-agent