Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Linux

グラフィカルな Bluetooth マネージャーがある場合は、それを使ってコンピューターを Bluetooth モジュールとペアリングし、これらの手順の大半を省略できます。ただし、おそらく this step は引き続き必要です。

電源をオンにする

まず、コンピューターの Bluetooth トランシーバーが OFF になっている可能性があります。hciconfig で状態を確認し、必要に応じて ON にしてください。

$ hciconfig
hci0:   Type: Primary  Bus: USB
        BD Address: 68:17:29:XX:XX:XX  ACL MTU: 310:10  SCO MTU: 64:8
        DOWN  <--
        RX bytes:580 acl:0 sco:0 events:31 errors:0
        TX bytes:368 acl:0 sco:0 commands:30 errors:0

$ sudo hciconfig hci0 up

$ hciconfig
hci0:   Type: Primary  Bus: USB
        BD Address: 68:17:29:XX:XX:XX  ACL MTU: 310:10  SCO MTU: 64:8
        UP RUNNING  <--
        RX bytes:1190 acl:0 sco:0 events:67 errors:0
        TX bytes:1072 acl:0 sco:0 commands:66 errors:0

次に、BlueZ(Bluetooth)デーモンを起動する必要があります。

  • systemd ベースの Linux ディストリビューションでは、次を使用します。
$ sudo systemctl start bluetooth
  • Ubuntu(または upstart ベースの Linux ディストリビューション)では、次を使用します。
$ sudo /etc/init.d/bluetooth start

また、rfkill list の結果によっては、Bluetooth のブロックを解除する必要がある場合もあります。

$ rfkill list
9: hci0: Bluetooth
        Soft blocked: yes # <--
        Hard blocked: no

$ sudo rfkill unblock bluetooth

$ rfkill list
9: hci0: Bluetooth
        Soft blocked: no  # <--
        Hard blocked: no

スキャン

$ hcitool scan
Scanning ...
        20:16:05:XX:XX:XX       Ferris
$ #                             ^^^^^^

ペアリング

$ bluetoothctl
[bluetooth]# scan on
[bluetooth]# agent on
[bluetooth]# pair 20:16:05:XX:XX:XX
Attempting to pair with 20:16:05:XX:XX:XX
[CHG] Device 20:16:05:XX:XX:XX Connected: yes
Request PIN code
[agent] Enter PIN code: 1234

rfcomm device

Bluetooth モジュール用のデバイスファイルを /dev に作成します。これにより、/dev/ttyUSB0 を使ったときと同じように使用できるようになります。

$ sudo rfcomm bind 0 20:16:05:XX:XX:XX

bind の引数として 0 を使用したため、/dev/rfcomm0 が Bluetooth モジュールに割り当てられるデバイスファイルになります。

デバイスファイルは、次のコマンドでいつでも解放(削除)できます。

$ # 今はこのコマンドを実際には実行しないでください!
$ sudo rfcomm release 0