アーキテクチャ
 
事前準備
 
上記の赤色については別の投稿を参照してください。
Raspberry Pi(Python)からAzure IoT Hubへテレメトリーを送信する
Azure IoT Hubのメッセージルーティング
情報定義
resourceGroupName={ResourceGroupName}
iotHubName={IoTHubName}
ioteviceName={IoTDeviceName}
storageAccountName={StorageAccountName}
containerName={ContainerName}
endpointName={EndpointName}
endpointType={EndpointType}
routeName={RouteName}
情報取得
subscriptionID=$(az account show --query id)
Storage Account作成
az storage account create \
 --name $storageAccountName \
 --resource-group $resourceGroup \
 --location $location \
 --sku Standard_LRS
Storage Accountキー取得
storageAccountKey=$(az storage account keys list \
 --resource-group $resourceGroup \
 --account-name $storageAccountName \
 --query "[0].value" | tr -d '"')
Storage Accountコンテナー作成
az storage container create --name $containerName \
 --account-name $storageAccountName \
 --account-key $storageAccountKey \
 --public-access off
Storage Accountの接続情報取得
storageConnectionString=$(az storage account show-connection-string \
 --name $storageAccountName \
 --query connectionString \
 -o tsv)
IoT Hubのエンドポイント作成
az iot hub routing-endpoint create \
 --connection-string $storageConnectionString \
 --endpoint-name $endpointName \
 --endpoint-resource-group $resourceGroup \
 --endpoint-subscription-id $subscriptionID \
 --endpoint-type $endpointType \
 --hub-name $iotHubName \
 --container $containerName \
 --resource-group $resourceGroup \
 --encoding json
IoT Hubのメッセージルーティング作成
az iot hub route create \
 --name $routeName \
 --hub-name $iotHubName \
 --source devicemessages \
 --resource-group $resourceGroup \
 --endpoint-name $endpointName \
 --enabled
https://docs.microsoft.com/en-us/azure/iot-hub/tutorial-routing