Raspberry Pi(Raspbian)とBlend Microの接続メモ
RaspbianでBluetooth(BLE)を扱うときはBluezというモジュールを使うらしい。
インストールモジュールを参照したところデフォルトで入っているものはなかったので、ソースからビルドしていく。
# aptitude install libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline6-dev # wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.32.tar.gz # tar xvf bluez-5.32.tar.gz # cd bluez-5.32 # ./configure --disable-systemd --enable-library # make # make install
hciconfigを実行し、BLEドングルが認識されていることを確認する。
root@raspberrypi:~# hciconfig hci0: Type: BR/EDR Bus: USB BD Address: 00:1B:DC:04:BB:98 ACL MTU: 310:10 SCO MTU: 64:8 DOWN RX bytes:7598 acl:115 sco:0 events:315 errors:0 TX bytes:2464 acl:137 sco:0 commands:63 errors:0
インストール直後はステータスがDOWNになっているはずなので、起動時にUPになるように設定→再起動
# vi /etc/udev/rules.d/10-local.rules ACTION=="add", KERNEL=="hci0", RUN+="/usr/local/bin/hciconfig hci0 up"
BLEの検索にはhcitoolコマンドを使う
root@raspberrypi:~# hcitool lescan LE Scan ... C4:C0:53:AA:0F:65 BlendMicro C4:C0:53:AA:0F:65 BlendMicro C4:C0:53:AA:0F:65 BlendMicro .....
最初にビルドしたときにgatttoolが出来上がっているので、パスが通ってる場所にコピー
root@raspberrypi:~# cp bluez-5.32/attrib/gatttool /usr/local/bin
gatttoolを使い、Blend Microとの接続を試みる
gatttoolを実行する際は"-t random"パラメータが非常に重要。
これをつけてないと、ログイン後にconnectを行っても失敗する。
root@raspberrypi:~# gatttool -b C4:C0:53:AA:0F:65 -I -t random [C4:C0:53:AA:0F:65][LE]> connect Attempting to connect to C4:C0:53:AA:0F:65 Connection successful [C4:C0:53:AA:0F:65][LE]> char-desc handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb handle: 0x0006, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb handle: 0x0008, uuid: 00002800-0000-1000-8000-00805f9b34fb handle: 0x0009, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x000a, uuid: 00002a05-0000-1000-8000-00805f9b34fb handle: 0x000b, uuid: 00002902-0000-1000-8000-00805f9b34fb handle: 0x000c, uuid: 00002800-0000-1000-8000-00805f9b34fb handle: 0x000d, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x000e, uuid: 713d0003-503e-4c75-ba94-3148f18d941e handle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x0010, uuid: 713d0002-503e-4c75-ba94-3148f18d941e handle: 0x0011, uuid: 00002902-0000-1000-8000-00805f9b34fb handle: 0x0012, uuid: 00002800-0000-1000-8000-00805f9b34fb handle: 0x0013, uuid: 00002803-0000-1000-8000-00805f9b34fb handle: 0x0014, uuid: 00002a27-0000-1000-8000-00805f9b34fb
> char-write-cmd 0x000b 010100
と入力することでBlend MicroのLEDが反応するところまでは確認。
あとはAnalog/Digital Pinのステータスを読み取る方法がわかれば・・・だが、方法不明でこの記事はここまで。
参考にさせていただいたサイト
https://lilyhack.wordpress.com/2014/02/03/ble-read-write-arduino-raspberry-pi/
https://blog.adafruit.com/2014/07/28/gatttool-ubuntu-and-adafruits-nrf8001-bluetooth-low-energy-breakout-in-20-minutes/