10.2. bluetoothctl で Bluetooth デバイスを接続する
bluetoothctl は、グラフィカルユーザーインターフェイスに依存せずに、接続をスキャン、ペアリング、接続、管理するためのコマンドラインユーティリティーです。
前提条件
-
bluetooth.serviceユニットが有効になっています。
手順
bluetoothctl対話型プロンプトに入力します:$ bluetoothctlシステムの Bluetooth のステータスを確認します。
[bluetoothctl]# show Powered: no Discoverable: no DiscoverableTimeout: 0x000000b4 Pairable: nobluetoothctl が電源オンになっていない場合は、次のように入力します。[bluetoothctl]# power on
システムの範囲内で接続するデバイスをペアリングモードに設定し、システムを検出およびペアリング可能にします。
[bluetoothctl]# discoverable on[bluetoothctl]# pairable onBluetooth デバイスのスキャンを開始します:
[bluetoothctl]# scan on検出されたデバイスのリストが、MAC アドレスと名前 (存在する場合) とともに表示されます。
デバイスが見つかったら、スキャンを停止します。
[bluetoothctl]# scan off- 接続するデバイスの MAC アドレスをメモします。
デバイスをペアリングします:
[bluetoothctl]# pair XX:XX:XX:XX:XX:XXシステム上でペアリングコードの確認を求められる場合があります。
ペアリングしたデバイスを信頼します:
[bluetoothctl]# trust XX:XX:XX:XX:XX:XXオプション: このデバイスを今後自動的に接続したい場合は、デフォルトとして設定できます。
[bluetoothctl]# default XX:XX:XX:XX:XX:XX完了したら、
bluetoothctl を終了します。[bluetoothctl]# quit
検証
接続したデバイスのステータスを確認します。
[bluetoothctl]# devices Device AA:BB:CC:DD:EE:FF Headphones (Connected: yes) Device 11:22:33:44:55:66 Keyboard (Connected: no)[bluetoothctl]# info AA:BB:CC:DD:EE:FF <device information> Connected: yes