3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Azure IoT Edge モジュールをLinuxデバイスに展開する

3
Last updated at Posted at 2019-03-19

Azure IoT Edge のクイックスタート

クイック スタート: Linux デバイスへのコードのデプロイ
https://docs.microsoft.com/ja-jp/azure/iot-edge/quickstart-linux

どこかでハマると思いメモしましたが、マイクロソフトのドキュメントとしては珍しく最後までスムーズに試すことが出来てしまいました。

Azure Cloud Shell の開始

Azure Portal からCloud Shell を実行しサブスクリプションを確認します。
通常は IsDefault が True のサブスクリプションで実行されています。

az account list --output table

show コマンドで確認できます。

az account show

Azure IoT の拡張機能を Cloud Shell インスタンスに追加します。

az extension add --name azure-cli-iot-ext

list コマンドで拡張機能を確認できます。

az extension list

クイック スタートで使用するリソース グループを作成します。

az group create --name IoTEdgeResources --location westus

Azure IoT Hub のデプロイ

IoT Hub を作成します。
サブスクリプションに無料の IoT Hub が既にある場合は、SKU を S1 に変更します。

az iot hub create --resource-group IoTEdgeResources --name "hub_name" --sku F1

myEdgeDevice という名前のデバイスをハブに作成します。

az iot hub device-identity create --device-id myEdgeDevice --hub-name "hub_name" --edge-enabled

デバイスの接続文字列を取得します。

az iot hub device-identity show-connection-string --device-id myEdgeDevice --hub-name "hub_name"

IoT Edge デバイス (Azure VM) のデプロイ

【初回のみ】プログラムによるデプロイの構成を有効化する

  1. Virtual Machine の追加から[プログラムによるデプロイについて]を選択
  2. 使用中のサブスクリプションを[有効化] し [保存]

プログラムによるデプロイを有効化していない場合、Cloud Shell から VM をデプロイする際「Azure Error: MarketplacePurchaseEligibilityFailed」エラーが発生します。

Linux 仮想マシンをデプロイする

create コマンドの出力内容に含まれる publicIpAddress を書き留めておきます。

az vm create --resource-group IoTEdgeResources --name EdgeVM --image microsoft_iot_edge:iot_edge_vm_ubuntu:ubuntu_1604_edgeruntimeonly:latest --admin-username azureuser --generate-ssh-keys --size Standard_DS1_v2

IoT Edge デバイスに接続文字列を設定する

az vm run-command invoke -g IoTEdgeResources -n EdgeVM --command-id RunShellScript --script '/etc/iotedge/configedge.sh "{device_connection_string}"'

IoT Edge ランタイムの状態を確認する

IoT Edge デバイスに接続する

ssh azureuser@{publicIpAddress}

Edge セキュリティ デーモンがシステム サービスとして実行されていることを確認します

active (running) を確認します。

sudo systemctl status iotedge

デバイスで実行されているモジュールを表示します

sudo iotedge list

モジュールの展開

  1. Azure portal で「Simulated Temperature Sensor」で検索し、Marketplace の結果を開きます。
  2. サブスクリプション、IoT Hub名、デバイス名を入力し作成します。
  3. IoT Hub のページからモジュールの状態を確認できます。

データの確認

IoT Edge デバイスで、クラウドからデプロイされたモジュールが実行されていることを確認します。

sudo iotedge list

温度センサー モジュールから送信されているメッセージを確認します。

sudo iotedge logs SimulatedTemperatureSensor -f
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?