【发布时间】:2021-04-29 17:40:31
【问题描述】:
Ubuntu 20.04.2 LTS bluetoothctl 版本 5.53
我遇到的问题是蓝牙耳机在双启动机器上的 Ubuntu/Windows 之间切换时无法直接配对而不出错(我相信是由于蓝牙问题/存储公钥的过程)
我正在尝试运行一个简单的脚本来删除特定的蓝牙地址(设备),刷新其信息并重新配对。
我尝试了以下各种迭代:
#!/bin/bash
#remove old connection
echo -e 'power on\ndisconnect 88:88:E1:21:52:BE\nremove 88:88:E1:21:52:BE\nquit' | bluetoothctl
sudo systemctl restart bluetooth
sleep 1
echo -e 'power on' | bluetoothctl
echo -e 'default-agent' | bluetoothctl
echo -e 'discoverable on\ndiscoverable-timeout 100\nscan on' | bluetoothctl
sleep 10
echo -e 'pairable on' | bluetoothctl
# Re-Add our device
echo -e 'trust 88:88:E1:21:52:BE\npair 88:88:E1:21:52:BE' | bluetoothctl
sleep 4
echo -e 'connect 88:88:E1:21:52:BE' | bluetoothctl
echo -e 'discoverable off' | bluetoothctl
echo -e 'quit' | bluetoothctl
输出如下:
Agent registered
[bluetooth]# power on
[bluetooth]# disconnect 88:88:E1:21:52:BE
Attempting to disconnect from 88:88:E1:21:52:BE
[bluetooth]# remove 88:88:E1:21:52:BE
[bluetooth]# quit
Agent registered
[bluetooth]# power on
Agent registered
[bluetooth]# default-agent
Agent registered
[bluetooth]# discoverable on
[bluetooth]# discoverable-timeout 100
[bluetooth]# scan on
Agent registered
[bluetooth]# pairable on
Agent registered
[bluetooth]# trust 88:88:E1:21:52:BE
Device 88:88:E1:21:52:BE not available
[bluetooth]# pair 88:88:E1:21:52:BE
Device 88:88:E1:21:52:BE not available
Agent registered
[bluetooth]# connect 88:88:E1:21:52:BE
Device 88:88:E1:21:52:BE not available
Agent registered
[bluetooth]# discoverable off
Agent registered
[bluetooth]# quit
但是,在单独的窗口中关注 bluetoothctl 命令输出时
[CHG] Controller C8:58:C0:C4:41:F8 Name: [ControllerID]
[CHG] Controller C8:58:C0:C4:41:F8 Alias: BlueZ 5.53
[CHG] Controller C8:58:C0:C4:41:F8 Alias: [ControllerID]
**[CHG] Controller C8:58:C0:C4:41:F8 Discovering: no**
[CHG] Controller C8:58:C0:C4:41:F8 Discoverable: yes
Scan on 命令没有达到预期的效果。蓝牙控制器未发现并且未发现任何设备,因此无法与所述设备建立连接。
当直接进入 bluetoothctl 命令行时,scan on 命令具有预期效果,控制器开始扫描。为什么 ubuntu 终端/bash 脚本中的 scan ON 命令没有达到预期的效果?
【问题讨论】:
-
SO 仅用于编程问题,因此操作系统支持为off-topic。请改用Ask Ubuntu 询问。
-
` | bluetoothctl` 你正在调用这么多 bluetoothctl 进程。只需调用它一次,而不是多次。研究 shell 重定向和
exec文件描述符生成与进程替换和研究 bash 中的 coproc。