
以前 「ラズパイでdockerを試してみました」 ので、今回は Raspberry Pi 3 Model B のコンテナ内からBLEを使ってSensorTagにアクセスしてみたいと思います。
今回使用したOSイメージ
- 2017-04-10-raspbian-jessie-lite
まずは更新しておきます。
1 2
| $ sudo apt-get update $ sudo apt-get upgrade
|
dockerインストール
公式blogに書かれていた通りにDockerをインストールします。
1
| $ curl -sSL https://get.docker.com/ | sh
|
sudoを付けなくても docker
コマンドが実行できるようにするgroup設定
1
| $ sudo usermod -aG docker pi
|
ここで一旦loginしなおします。
resin/rpi-raspbian:jessie
https://hub.docker.com/r/resin/rpi-raspbian/
このコンテナを起動します。
ここでのポイントは --net host
をつけることです。
これをつけないとコンテナ内からHCI socketをOpenできませんでした。
1
| $ docker run -it --net host resin/rpi-raspbian:jessie
|
コンテナが起動したら Bluez をインストール
1 2
| # apt-get update # apt-get install bluez
|
これで準備完了です。
SensorTag へアクセス
SensorTagの電源をONにしておき、スキャンします。
1 2 3 4
| # hcitool lescan LE Scan ... XX:XX:XX:XX:XX:XX (unknown) XX:XX:XX:XX:XX:XX CC2650 SensorTag
|
見つけることができました。
gatttool
をインタラクティブモードで起動
1 2
| # gatttool -b XX:XX:XX:XX:XX:XX --interactive [XX:XX:XX:XX:XX:XX][LE]>
|
connect
します
1 2 3
| [XX:XX:XX:XX:XX:XX][LE]> connect Attempting to connect to XX:XX:XX:XX:XX:XX Connection successful
|
primary
でプライマリサービスを確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [XX:XX:XX:XX:XX:XX][LE]> primary attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb attr handle: 0x0008, end grp handle: 0x0008 uuid: 00001801-0000-1000-8000-00805f9b34fb attr handle: 0x0009, end grp handle: 0x001b uuid: 0000180a-0000-1000-8000-00805f9b34fb attr handle: 0x001c, end grp handle: 0x0021 uuid: 0000180f-0000-1000-8000-00805f9b34fb attr handle: 0x0022, end grp handle: 0x0029 uuid: f000aa00-0451-4000-b000-000000000000 attr handle: 0x002a, end grp handle: 0x0031 uuid: f000aa20-0451-4000-b000-000000000000 attr handle: 0x0032, end grp handle: 0x0039 uuid: f000aa40-0451-4000-b000-000000000000 attr handle: 0x003a, end grp handle: 0x0041 uuid: f000aa80-0451-4000-b000-000000000000 attr handle: 0x0042, end grp handle: 0x0049 uuid: f000aa70-0451-4000-b000-000000000000 attr handle: 0x004a, end grp handle: 0x004e uuid: 0000ffe0-0000-1000-8000-00805f9b34fb attr handle: 0x004f, end grp handle: 0x0053 uuid: f000aa64-0451-4000-b000-000000000000 attr handle: 0x0054, end grp handle: 0x005a uuid: f000ac00-0451-4000-b000-000000000000 attr handle: 0x005b, end grp handle: 0x0062 uuid: f000ccc0-0451-4000-b000-000000000000 attr handle: 0x0063, end grp handle: 0xffff uuid: f000ffc0-0451-4000-b000-000000000000
|
サービス一覧が表示されました。
これらのサービスの中から今回は例として、以前の 「SensorTag のバッテリーレベルをチェック」 と同様にバッテリーレベルをREADしてみます。
バッテリーサービス は Bluetooth SIG で Battery Service
UUID : 180f
と決められていますので、先ほどのサービス一覧の中の
1
| attr handle: 0x001c, end grp handle: 0x0021 uuid: 0000180f-0000-1000-8000-00805f9b34fb
|
この行です。
ハンドルは 0x001c
から 0x0021
が割り当てられていました。
次にこの範囲の characteristics
を確認
1 2
| [XX:XX:XX:XX:XX:XX][LE]> characteristics 0x001c 0x0021 handle: 0x001d, char properties: 0x12, char value handle: 0x001e, uuid: 00002a19-0000-1000-8000-00805f9b34fb
|
こちらも Bluetooth SIG の Battery Level
UUID : 2a19
でした。
ハンドルは 0x001e
ですのでこれをREADします。
1 2
| [XX:XX:XX:XX:XX:XX][LE]> char-read-hnd 0x001e Characteristic value/descriptor: 59
|
読めました。
0x59 = 89 % です。
Dockerコンテナ内からSensorTagにアクセスすることができました。