Raspberry Pi 3 Model B
OS: Raspbian Stretch lite March 2018
Raspberry Pi 3 Model BにBluetoothでキーボードを接続する必要に迫られた。すっかり一線から退いていた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
pairコマンドにBD_ADDRを引き渡してペアリングを開始する。 Pairing successfulと表示されればペアリング成功である。ひとたびペアリングがうまくいくと、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を再起動したり暫くキーボードに触れずにいると接続が失われ、再度connectコマンドの実行が必要であった。キー押下だけで再接続を促すには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から抜け出すにはquitコマンドである。
[Bluetooth Keyboard]# quit [DEL] Controller 00:00:5E:00:53:00 raspberrypi [default]

