Azure IoT Edgeをビルドしてみた(Ubuntu 14.04)

Azure IoT Edgeのビルドにトライしました。

OS選び

Azure IoT Edgeは下記サイトに記載があるとおり、LinuxWindowsでテストされています。

Azure IoT Edge Operating system compatibility

モジュールのデバッグを考えるとWindows+VisualStudioが良さそうですが、組込機器で動かすことを考えるとLinuxなのかな?と思い、今回はLinuxで。

ビルドの手順を確認したいだけなので、実機ではなく、Azureの仮想マシンを使うことに。失敗したらすぐに再構築ってことでw

自宅のネット回線が遅いので、イライラを避けるためにAzure仮想マシンの選択は良いです。

Azure仮想マシンと互換リストを見比べること数分。Ubuntu Server 14.04 LTSを使うことにしました。

Ubuntu 14.04

Azureの仮想マシン作成で必要事項を入力して、ポチポチすればOK。

f:id:matsujirushix:20170903224049p:plain

一番小さい「A0 Basic」にしました。

f:id:matsujirushix:20170903224331p:plain

f:id:matsujirushix:20170903224645p:plain

数分で出来上がり。

matsujirushi@edge1:~$ uname -a
Linux edge1 4.4.0-93-generic #116~14.04.1-Ubuntu SMP Mon Aug 14 16:07:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Azure IoT Edgeのインストール

こちらのSet up a Linux development environmentのとおり、必要なパッケージを インストールして、Azure IoT Edgeのgitをクローンします。

matsujirushi@edge1:~$ sudo apt-get update
matsujirushi@edge1:~$ sudo apt-get install curl build-essential libcurl4-openssl-dev git cmake pkg-config libssl-dev uuid-dev valgrind libglib2.0-dev libtool autoconf
matsujirushi@edge1:~$ git clone https://github.com/Azure/iot-edge.git

サンプルをビルド、実行

同封されているサンプルプログラムの、hello_worldモジュールとloggerモジュールを実行してみたいと思います。

こちらのとおり、ビルドして、その後に実行します。

ビルド

matsujirushi@edge1:~$ cd iot-edge
matsujirushi@edge1:~/iot-edge$ tools/build.sh --disable-native-remote-modules

実行

matsujirushi@edge1:~/iot-edge/build$ ./samples/hello_world/hello_world_sample ../samples/hello_world/src/hello_world_lin.json
gateway successfully created from JSON
gateway shall run until ENTER is pressed

表面上、なにも変化ありませんが、、、hello_worldモジュールとloggerモジュールが動いているはずです(汗

loggerモジュールはlog.txtに書き出しているので確認してみます。

matsujirushi@edge1:~/iot-edge/build$ cat log.txt
[{"time":"20","content":"Log started"},
{"time":"20","properties":{"helloWorld":"from Azure IoT Gateway SDK simple sample!"},"content":"aGVsbG8gd29ybGQ="},
{"time":"20","properties":{"helloWorld":"from Azure IoT Gateway SDK simple sample!"},"content":"aGVsbG8gd29ybGQ="},
...

まとめ

  • Azure IoT Edgeは、Azure仮想マシンUbuntu 14.04で動く。(とても簡単)
  • Azure仮想マシンはA0 BasicでOK。
  • ビルド結果はbuildディレクトリ配下に配置される。
  • サンプルの実行は、ビルド結果を実行するが、パラメータのJSONファイルはソース側を指定している。(←ビルド結果を別環境にコピーして実行するときには注意が必要)

モジュールの追加に挑戦したいが、言語はnode.jsかnetcoreを使いたいところ。

次は、どちらかの言語のサンプルをビルドする環境を構築したいと思います。