LoginSignup
65
65

More than 5 years have passed since last update.

Linux PCにBluetooth機器を接続する

Last updated at Posted at 2015-12-20

LinuxにおけるBluetoothデバイスの接続方法についてのまとめます。
LinuxでBluetoothデバイスと接続する際には、bluezというプロトコルスタックを用います。
今回はbluetoothctlを使って設定します。bluetoothctlは対話型の設定ツールです。

私の環境

PC: HPのノートPC(ENVY)
OS: Arch Linux

手順

  1. bluezをインストールする
  2. Bluetoothのデーモンを起動する
  3. bluetoothctlでBluetoothデバイスを接続する
  4. OS起動時に自動的に接続するように設定する

bluezをインストールする

pacmanbluezbluez-utilsをインストールします。
bluez-utilsbluetoothctlを含んでいるため、インストールする必要があります。
Arch以外のディストリビューションを使っている場合は、それぞれ対応するパッケージをインストールしてください。

$ sudo pacman -S bluez bluez-utils

Bluetoothのデーモンを起動する

Bluetoothのデーモンを起動します。
これが起動していなければbluetoothctlを起動しても入力を受け付ません。

$ sudo systemctl start bluetooth.service

OS起動時にbluetooth.serviceが起動するようにします。

$ sudo systemctl enable bluetooth.service

bluetoothctlでBluetoothデバイスを接続する

bluetoothctlを起動します。

$ bluetoothctl

ここからはbluetoothctlとの対話です(プロンプトが変わっていることに注意)。
コントローラを起動します。

# power on

ペアリングしたいデバイスのMACアドレスを調べます。

# devices

デバイスが見つからない場合はスキャンをします。

# scan on

ペアリングをします。

# pair MACアドレス

デバイスによっては信用登録する必要があります。

# trust MACアドレス

接続します。

# connect MACアドレス

これで接続できるはずです。

bluetoothctlから抜けるには次のコマンドを実行します。

# exit

OS起動時に自動的に接続するように設定する

udev(デバイスマネージャー)の設定ファイルに次の記述を追記します。設定ファイルがない場合は新たに作ります。

/etc/udev/rules.d/10-local.rules
# Set bluetooth power up
ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"

udevの設定ファイルの書き方について詳しく知りたい場合はこちらが参考になります。
http://www.reactivated.net/writing_udev_rules.html

おしまい

これで再起動後は自動的に接続できるはずです。

参考

65
65
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
65
65