2
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 3 years have passed since last update.

Raspberry Pi(Python)からAzure IoT Hubへテレメトリーを送信する

Last updated at Posted at 2020-01-30

アーキテクチャ

SendTelemetry.png

事前準備

MacOS

Azure CLI インストール

brew update && brew install python3
brew link --overwrite python3
brew install azure-cli

Azure CLIログインとAzure CLIのIoT拡張インストール

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

Azure IoT Hub 作成

# AzureサブスクリプションID取得
subscriptionID=$(az account show --query id)

# ロケーション設定(Japan East)
location=japaneast

# リソースグループ設定
resourceGroup={ResourceGroupName}

# リソースグループ作成
az group create --name $resourceGroup --location $location

# IoT Hub名設定
iotHubName={AzureIoTHubName}

# IoT Hub作成 (F1無料)
az iot hub create --name $iotHubName --resource-group $resourceGroup --sku F1 --location $location

https://portal.azure.com/#create/Microsoft.IotHub

デバイス登録

az iot hub device-identity create --hub-name {AzureIoTHubName} --device-id {DeviceName}

デバイス接続情報取得

az iot hub device-identity show-connection-string --hub-name {AzureIoTHubName} --device-id {DeviceName} --output table

テレメトリー送信

Raspberry Pi

Pythonパッケージインストール

pip3 install azure-iot-device

サンプルコードのリポジトリクローン

mkdir -p ~/Source/Repos && cd ~/Source/Repos
git clone https://github.com/Azure-Samples/azure-iot-samples-python/
cd ./azure-iot-samples-python/iot-hub/Quickstarts/simulated-device

接続情報更新

vi SimulatedDevice.py
CONNECTION_STRING.png

実行

python3 SimulatedDevice.py

テレメトリー確認

Azureポータル

Azure Cloud Shell

az iot hub monitor-events --hub-name {AzureIoTHubName} --device-id {DeviceName}

https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-python

2
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
2
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?