ichou1のブログ

主に音声認識、時々、データ分析のことを書く

Bluetoothメモ(BlueZパッケージ、bluetoothctlコマンド)

Bluetoothキーボードを使おうとしてハマったのでメモ。

サイトを見ると、接続するためのコマンドはいくつかある。

  • bluez-simple-agent
  • gatttool
  • bluetoothctl

使い方が悪いのか、「bluez-simple-agent」コマンドと「gatttool」コマンドでは接続できなかった。

gatttoolコマンド(失敗)
gatttool -i hci0 -b "ペアリングさせたい機器のMACアドレス" -t random -I
[   ]["ペアリングさせたい機器のMACアドレス"][LE]> connect
Connecting... connect error: Transport endpoint is not connected (107)

「bluetoothctl」コマンドを試してみようとしたところ、入っていない。

BlueZパッケージのバージョンを確認してみると、「4」。

ii  bluez                         4.101-0ubuntu13.3             i386  Bluetooth tools and daemons

BlueZの開発元を確認すると、
http://www.bluez.org/download/

「BlueZ 4」は非推奨らしい。

The 2.x , 3.x and 4.x series of libraries and packages are deprecated and not supported anymore by BlueZ developers.

「BlueZ 5」を使おうとしたが、Ubuntuの公式としては「15.10」からのサポートらしい。
(現在、「14.04」を使っている)

launchpad.net

PPAからダウンロードする。
いくつかあるが、更新日で見ると一番上のリポジトリが一番新しいので、これを使う。

  • vidplace7/bluez5
  • timchen119/bluez5-trusty
  • tigerite/bluez5
sudo add-apt-repository ppa:vidplace7/bluez5
sudo apt-get update
sudo apt-get install bluez

これで「BlueZ 5」が入り、

ri  bluez	5.35.0+upstream-201701161031~rev18921~pkg9~ubuntu14.04.1 i386	Bluetooth tools and daemons

「bluetoothctl」コマンドが使えるようになった。

他にも、「hciconfig」や「hcitool」が入っている。

% dpkg -L bluez | grep /bin
/usr/bin/bccmd
/usr/bin/rctest
/usr/bin/hciattach
/usr/bin/btmon
/usr/bin/hcitool
/usr/bin/sdptool
/usr/bin/rfcomm
/usr/bin/l2ping
/usr/bin/ciptool
/usr/bin/hciconfig
/usr/bin/bluetoothctl
/usr/bin/l2test