一、bluetoothctl 無法disconnect
在bluetoothctl中,當我們想要斷開設備連接或者取消配對時,很多時候我們會發現我們無法成功執行這些操作。這是因為由於bluez5的升級,配對信息在更改時需要保存到磁盤上,而在某些情況下,我們沒有正確地進行這些保存操作,從而導致無法斷開設備連接,或無法取消配對。此時可以嘗試刪除主機上所有藍牙設備的配對信息,然後再重新配對連接即可。
$ bluetoothctl
[bluetooth]# remove
[bluetooth]# remove
[bluetooth]# exit
二、bluetoothctl命令
以下是bluetoothctl中常用的一些命令:
bluetoothctl # 打開藍牙交互式命令行界面
power on # 打開藍牙
power off # 關閉藍牙
agent on # 啟用代理
agent off # 禁用代理
scan on # 搜索設備
scan off # 停止搜索設備
devices # 列出搜索到的設備
pair # 配對設備
trust # 信任設備
untrust # 不信任設備
connect # 連接設備
disconnect # 斷開與設備的連接
exit # 退出藍牙交互式命令行界面
三、bluetoothctl 配對
在bluetoothctl中,我們可以進行手動配對操作。配對時,我們需要提供設備的MAC地址,並且將設備設置為可被發現模式。
$ bluetoothctl
[bluetooth]# power on
[bluetooth]# discoverable on
[bluetooth]# scan on
[bluetooth]# devices
Device 20:13:03:22:66:19 Bose SoundSport Wireless
[bluetooth]# pair 20:13:03:22:66:19
[bluetooth]# trust 20:13:03:22:66:19
[bluetooth]# connect 20:13:03:22:66:19
[bluetooth]# exit
四、bluetoothctl源碼
bluez是基於C語言開發的開源項目,源代碼在其官方網站(https://github.com/bluez/bluez)上提供。
五、bluetoothctl下載
bluez項目提供了bluetoothctl命令行工具,該工具可以通過apt-get工具在Ubuntu上直接下載安裝。
$ sudo apt-get install bluez
六、bluetoothctl安裝
bluetoothctl已經包含在bluez藍牙套件中,只需要通過apt-get安裝即可。
$ sudo apt-get install bluez
七、bluetoothctl最早版本號
bluetoothctl是bluez5版本中新增的交互式命令行工具,因此,bluetoothctl命令的最早版本號應該是bluez5版本。
八、bluetoothctl 啟動參數選取
bluetoothctl可以通過指定啟動參數來改變其行為。以下是bluetoothctl支持的啟動參數及其作用:
-h, --help # 顯示幫助信息並退出
-v, --version # 顯示版本信息並退出
-t, --timeout= # 指定超時時間,默認為60秒
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/288621.html