bluetooth - 用蓝牙连接两个树莓派时出错
问题描述
我正在做一个项目,其中一个树莓派将成为 BLE GATT 服务器,另一个是客户端。第一步是通过命令行测试正常的蓝牙连接,但它不起作用,我不知道为什么。两者都是树莓派 4 型号 B;第一个有 raspbian buster,Linux raspberrypi 5.10.17-v7l+
而第二个有 Ubuntu 20.04 服务器和Linux ubuntu 5.4.0-1036-raspi
.
bluetoothctl
在我设置的第一个(从属)上使用agent on
discoverable on
,pairable on
而在第二个我使用scan on
. 第二个覆盆子找到另一个 MAC 地址,所以我继续pair DC:A6:32:2C:D4:90
。配对似乎成功,但它甚至不要求输入密码:
从 RPI 输出:
Changing discoverable on succeeded
[CHG] Controller DC:A6:32:2C:D4:90 Discoverable: yes
[NEW] Device DC:A6:32:FD:47:E0 ubuntu
[CHG] Device DC:A6:32:FD:47:E0 Modalias: usb:v1D6Bp0246d0535
[CHG] Device DC:A6:32:FD:47:E0 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:FD:47:E0 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:FD:47:E0 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:FD:47:E0 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:FD:47:E0 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:FD:47:E0 ServicesResolved: yes
[CHG] Device DC:A6:32:FD:47:E0 Paired: yes
[CHG] Device DC:A6:32:FD:47:E0 ServicesResolved: no
[CHG] Device DC:A6:32:FD:47:E0 Connected: no
主 RPI 输出:
Attempting to pair with DC:A6:32:2C:D4:90
[CHG] Device DC:A6:32:2C:D4:90 Connected: yes
[CHG] Device DC:A6:32:2C:D4:90 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:2C:D4:90 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:2C:D4:90 UUIDs: 0000112d-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:2C:D4:90 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:2C:D4:90 ServicesResolved: yes
[CHG] Device DC:A6:32:2C:D4:90 Paired: yes
Pairing successful
[CHG] Device DC:A6:32:2C:D4:90 ServicesResolved: no
[CHG] Device DC:A6:32:2C:D4:90 Connected: no
ubuntu 是另一个 RPI 的名称,它的 MAC 是 DC:A6:32:FD:47:E0,从输出中可以看出。在配对期间,连接会建立几秒钟,然后断开连接。当我尝试connect DC:A6:32:2C:D4:90
从主服务器连接时,基本上会发生同样的情况:
[CHG] Device DC:A6:32:2C:D4:90 Connected: yes
[CHG] Device DC:A6:32:2C:D4:90 ServicesResolved: yes
Failed to connect: org.bluez.Error.NotAvailable
[CHG] Device DC:A6:32:2C:D4:90 ServicesResolved: no
[CHG] Device DC:A6:32:2C:D4:90 Connected: no
使用 bluetoothctl 和 sudo 并信任设备似乎没有帮助。
编辑:通过default-agent
在两个设备上使用,我被要求确认 pin,但连接仍然失败