Raspberry Pi 3 Model B
OS: Raspbian Stretch lite March 2018
すっかり一線から退いていたEC TechnologyのBluetoothキーボードに出番がやってきたのである。接続までの大まかな流れはデバイスのスキャン→ペアリング→接続というものであった。まずはbluetoothctlという対話型コマンドを実行する。
$ sudo bluetoothctl [NEW] Controller 00:00:5E:00:53:00 raspberrypi [default]
キーボードのFnキーを押下しつつCキーを押し込むとペアリングモードに移行する。
そうしたらscan onでデバイスのスキャンをおこなう。しばらく待ち構えていると目当てのBluetooth Keyboardが見つかった。このデバイスのBluetooth Device Address(BD_ADDR)である00:00:5E:00:53:FFを控えておく。
[bluetooth]# scan on Discovery started [CHG] Controller 00:00:5E:00:53:00 Discovering: yes [NEW] Device 00:00:5E:00:53:FF Bluetooth Keyboard
控えておいたBD_ADDRで以ってペアリングを開始する。ひとたびペアリングに成功すればRaspberry Piを再起動したとてペアのままであった。それでは都合が悪いという場合はremoveコマンドにBD_ADDRを渡してまったく削除することもできる。
[bluetooth]# pair 00:00:5E:00:53:FF Attempting to pair with 00:00:5E:00:53:FF (snip) [CHG] Device 00:00:5E:00:53:FF Paired: yes Pairing successful [bluetooth]# paired-devices Device 00:00:5E:00:53:FF Bluetooth Keyboard
あとはconnectコマンドで接続を実施すればよい。これでBluetoothキーボードから自在にキー入力がおこなえた。接続していると都合が悪いならdisconnectコマンドにBD_ADDRを渡すことで切断できる。
[bluetooth]# connect 00:00:5E:00:53:FF Attempting to connect to 00:00:5E:00:53:FF [CHG] Device 00:00:5E:00:53:FF Connected: yes Connection successful
しばらくキーボードに触れずにいたりRaspberry Piを再起動するなどして接続が失われてしまっても、何かキーを押すことでひとりでに再度接続を可能にするためにはtrustコマンドでBD_ADDRを登録するのが良いようである。キー押下から入力が可能になるまではおおむね3秒程度を要するようである。なお登録を取り消すならuntrustコマンドであった。
[bluetooth]# trust 00:00:5E:00:53:FF [CHG] Device 00:00:5E:00:53:FF Trusted: yes Changing 00:00:5E:00:53:FF trust succeeded
デバイスの詳らかな様子を確認するときはinfoコマンドである。
[bluetooth]# info 00:00:5E:00:53:FF Device 00:00:5E:00:53:FF Name: Bluetooth Keyboard Alias: Bluetooth Keyboard Class: 0x000540 Icon: input-keyboard Paired: yes Trusted: yes Blocked: no Connected: no LegacyPairing: yes (snip)
bluetoothctlから抜け出すにはこういう具合である。
[Bluetooth Keyboard]# quit [DEL] Controller 00:00:5E:00:53:00 raspberrypi [default]
参考:
2.1 Bluetoothctl
Pairing processes
bluetoothctl – What is a bluetooth agent?