微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Raspberry Pi 零蓝牙连接无法连接到设备

如何解决Raspberry Pi 零蓝牙连接无法连接到设备

我目前正在尝试创建一个脚本,以使用 CLI 命令将蓝牙打印机连接到我的 raspBerry 设备。 到目前为止,我已尝试使用 bluetoothctl,但每当我尝试连接时它都会冻结/崩溃。 以下是我一直在做的步骤:

首先,我搜索设备的 MAC 地址。

pi@raspBerrypi:~ $ hcitool scan
Scanning ...
    66:22:EA:B3:EA:18   Bluetooth Printer

然后,我打开 bluetoothctl 命令并尝试与设备配对/连接。

pi@raspBerrypi:~ $ sudo bluetoothctl 
[bluetooth]# agent on
Agent is already registered
[bluetooth]# scan on
[...]
[bluetooth]# pair 66:22:EA:B3:EA:18
Attempting to pair with 66:22:EA:B3:EA:18
[CHG] Device 66:22:EA:B3:EA:18 Connected: yes
[CHG] Device 66:22:EA:B3:EA:18 Connected: no
Failed to pair: org.bluez.Error.AlreadyExists # it was paired before,but if I pair them for the first time the device won't be connected.
[bluetooth]# connect 66:22:EA:B3:EA:18
Attempting to connect to 66:22:EA:B3:EA:18
[CHG] Device 66:22:EA:B3:EA:18 Connected: yes
Connection successful
Agent unregistered
[DEL] Controller B8:27:EB:D7:52:CA raspBerrypi [default]
[bluetooth]# 

最后,我收到了这个被冻结的蓝牙空提示。如果我再次输入 bluetoothctl ,我仍然无法输入任何命令。使其响应的唯一方法是重新启动蓝牙服务。

sudo service bluetooth restart

后来编辑,我使用了 journalctl -f -u bluetooth.servicesudo btmon 来读取日志:

pi@raspBerrypi:~ $ sudo btmon
Bluetooth monitor ver 5.50
= Note: Linux version 5.4.79+ (armv6l)                                 0.945328
= Note: Bluetooth subsystem version 2.22                               0.945347
= New Index: B8:27:EB:D7:52:CA (Primary,UART,hci0)              [hci0] 0.945356
= Open Index: B8:27:EB:D7:52:CA                                 [hci0] 0.945362
= Index Info: B8:27:EB:D7:52:CA (broadcom Corporation)          [hci0] 0.945369
@ MGMT Open: bluetoothd (privileged) version 1.14             {0x0001} 0.945377
@ MGMT Open: btmon (privileged) version 1.14                  {0x0002} 0.945534

pi@raspBerrypi:~ $ journalctl -f -u bluetooth.service
-- Logs begin at Thu 2021-01-14 20:17:02 GMT. --
Jan 16 12:52:11 raspBerrypi systemd[1]: Starting Bluetooth service...
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Bluetooth daemon 5.50
Jan 16 12:52:12 raspBerrypi systemd[1]: Started Bluetooth service.
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Starting SDP server
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Bluetooth management interface 1.14 initialized
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Sap driver initialization Failed.
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: sap-server: Operation not permitted (1)
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Failed to set privacy: Rejected (0x0b)
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Endpoint registered: sender=:1.27 path=/MediaEndpoint/A2DPSource
Jan 16 12:52:12 raspBerrypi bluetoothd[7535]: Endpoint registered: sender=:1.27 path=/MediaEndpoint/A2DPSink

如果我通过添加 /etc/systemd/system/bluetooth.target.wants/bluetooth.service文件 --noplugin=sap 修改包含 ExecStart 的行,在重新加载守护程序和蓝牙后,我的树莓将不会扫描任何蓝牙设备。

ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。