SSHでの接続時など、コマンドラインでのアクセスする際に、Bluetooth機器に接続する備忘録です。
環境
- Raspberry Pi 3 B+
- MicroSDカード
- MacBook Pro(Catalina)
作業手順
1.bluetoot起動
# bluetooth off
% sudo hciconfig hci0 down
# bluetooth on
% sudo hciconfig hci0 up
2.bluetooth設定ツールの起動
以下のAgentは以下、種類があるようです。
詳細はhelp等でご確認を。
・DisplayOnly
・DisplayYesNo
・KeyboardDisplay
・KeyboardOnly
・NoInputNoOutput
# bluetooth設定を起動
% bluetoothctl
Agent registered
# Agentを設定する(Pinコードを要求されないようする)
[bluetooth]# agent DisplayYesNo
# 上記Agent設定をデフォルトにする
[bluetooth]# default-agent
# bluetooth機器をスキャンする
[bluetooth]# scan on
Discovery started
[CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
[NEW] Device YY:YY:YY:YY:YY:YY blurtoothDevice01 12345
[NEW] Device ZZ:ZZ:ZZ:ZZ:ZZ:ZZ 00-00-00-00-00-00
...
# デバイスのスキャンを停止
[bluetooth]# scan off
3.bluetooth機器に接続する
# ペアリング
[bluetooth]# pair YY:YY:YY:YY:YY:YY
Attempting to pair with YY:YY:YY:YY:YY:YY
[CHG] Device YY:YY:YY:YY:YY:YY Connected: yes
[CHG] Device YY:YY:YY:YY:YY:YY UUIDs: 00001124-0000-1000-8000-00801r9p68fb
[CHG] Device YY:YY:YY:YY:YY:YY UUIDs: 00001200-0000-1000-8000-00801r9p68fb
[CHG] Device YY:YY:YY:YY:YY:YY ServicesResolved: yes
[CHG] Device YY:YY:YY:YY:YY:YY Paired: yes
Pairing successful
# コネクトする
[bluetooth]# connect YY:YY:YY:YY:YY:YY
Attempting to connect to YY:YY:YY:YY:YY:YY
[CHG] Device YY:YY:YY:YY:YY:YY Connected: yes
Connection successful
# 自動接続のためにtrustする
[bluetooth]# trust YY:YY:YY:YY:YY:YY
[CHG] Device YY:YY:YY:YY:YY:YY Trusted: yes
Changing YY:YY:YY:YY:YY:YY trust succeeded
その他のコントローラのコマンド####
select<ctrl>
:コントローラ選択
discoverable<on/off>
:onで発見可能にする
devices
:デバイスを表示する
pairable<on/off>
: ペア機能のスイッチ
paired-devices
:ペアリング済デバイスを表示
その他のデバイスのコマンド
remove[dev]
:ペアリングの削除
disconnect[dev]
:デバイス切断
info[dev]
:デバイスの状態