22: Intel Edison実践編 (2) 〜 EdisonからIoT Analyticsにデータを送る

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

よく訓練されたアップル信者、都元です。昨日のエントリーはこちらです。昨日はIoT AnalyticsにEdisonのデバイス設定を行いました。今回はEdisonからデータを送ってみましょう。

カタログアイテム

まず、Edisonから送るデータの種類(カタログアイテム)を決める必要があります。IoT Analyticsでは「いつ、どのデバイスの、どのアイテムの値が、どうだったのか」を管理します。アイテムというのは要するに温度や明るさ等です。

このアイテムは、デフォルトで3種類用意されています。powerswitchというのはセンサーをコントロールするためのものではないのでここでは扱いません。つまりセンサー項目としてはhumidity(湿度)とtemperature(温度)が用意されています。

この項目カタログはEdison上からiotkit-admin catalogコマンドで確認可能です。

# iotkit-admin catalog
2014-12-22T04:35:30.570Z - info: Staring Catalog Retrieving
2014-12-22T04:35:31.839Z - info: Comp:  humidity.v1.0   humidity   sensor
2014-12-22T04:35:31.843Z - info: Comp:  powerswitch.v1.0   powerswitch   actuator
2014-12-22T04:35:31.844Z - info: Comp:  temperature.v1.0   temperature   sensor
2014-12-22T04:35:31.848Z - info: # of Component @ Catalog :  3
┌──────────────────┬──────────┬─────────────┐
│ id : t           │ kind     │ measure     │
├──────────────────┼──────────┼─────────────┤
│ humidity.v1.0    │ sensor   │ humidity    │
├──────────────────┼──────────┼─────────────┤
│ powerswitch.v1.0 │ actuator │ powerswitch │
├──────────────────┼──────────┼─────────────┤
│ temperature.v1.0 │ sensor   │ temperature │
└──────────────────┴──────────┴─────────────┘

また、IoT Analyticsのダッシュボードからは、AccountメニューのCatalogタブで確認できます。

2014-12-22_1336

ここでは更に、light(明るさ)の項目を追加してみましょう。画面下部の「Add a New Catalog Item」をクリックし、下記のように登録をします。

2014-12-22_1344

コンポーネント

続いて、これらの項目について、Edison側から「値を送るよ」という宣言(=コンポーネントの作成)を行います。それがiotkit-admin registerコマンドです。

# iotkit-admin register temp temperature.v1.0
2014-12-22T04:46:29.702Z - info: Starting registration ...
2014-12-22T04:46:29.826Z - info: Sending attributes...
Attributes sent
2014-12-22T04:46:34.121Z - info: Component registered name=temp, type=temperature.v1.0, cid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

# iotkit-admin register light light.v1.0
2014-12-22T04:46:39.603Z - info: Starting registration ...
2014-12-22T04:46:39.723Z - info: Sending attributes...
Attributes sent
2014-12-22T04:46:43.360Z - info: Component registered name=light, type=light.v1.0, cid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

このように登録したコンポーネントは、iotkit-admin componentsで確認できます。

# iotkit-admin components
2014-12-22T04:48:41.925Z - info: Using data store: /usr/lib/node_modules/iotkit-agent/data/
┌──────────────────┬───────┬──────────────────────────────────────┐
│ id : t           │ Name  │ cID                                  │
├──────────────────┼───────┼──────────────────────────────────────┤
│ temperature.v1.0 │ temp  │ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │
├──────────────────┼───────┼──────────────────────────────────────┤
│ light.v1.0       │ light │ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │
└──────────────────┴───────┴──────────────────────────────────────┘

データの送信

ではデータを送信してみます。送信時はiotkit-admin observationコマンドです。ただしこのコマンドは、あくまでもデータ送信のテスト用に使うものらしいので、本番ではまた別の仕組み(iotkit-agent)を用いますのでご注意下さい。

# iotkit-admin observation temp 35
2014-12-22T04:52:34.014Z - info: Sending attributes...
2014-12-22T04:52:36.052Z - info: Submitting:  n=temp, v=35
2014-12-22T04:52:37.107Z - info: Response received:  response=none detail, status=0
2014-12-22T04:52:37.111Z - info: Observation Sent response=none detail, status=0

# iotkit-admin observation light 10
2014-12-22T04:52:39.274Z - info: Sending attributes...
2014-12-22T04:52:40.951Z - info: Submitting:  n=light, v=10
2014-12-22T04:52:41.993Z - info: Response received:  response=none detail, status=0
2014-12-22T04:52:41.997Z - info: Observation Sent response=none detail, status=0

# sleep 60

# iotkit-admin observation temp 30
2014-12-22T04:53:44.157Z - info: Sending attributes...
2014-12-22T04:53:46.091Z - info: Submitting:  n=temp, v=30
2014-12-22T04:53:48.527Z - info: Response received:  response=none detail, status=0
2014-12-22T04:53:48.531Z - info: Observation Sent response=none detail, status=0

# iotkit-admin observation light 15
2014-12-22T04:53:50.698Z - info: Sending attributes...
2014-12-22T04:53:53.162Z - info: Submitting:  n=light, v=15
2014-12-22T04:53:54.742Z - info: Response received:  response=none detail, status=0
2014-12-22T04:53:54.746Z - info: Observation Sent response=none detail, status=0

その結果、ダッシュボードのChartメニューからは、このような結果が得られました。

2014-12-22_1354

明日のエントリーはこちらです。