Raspberry Pi(Python)からAzure IoT Hubへテレメトリーを送信する
5556 ワード
アーキテクチャ
事前準備
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
デバイス登録
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
実行
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
brew update && brew install python3
brew link --overwrite python3
brew install azure-cli
az login
az extension add --name azure-cli-iot-ext
# 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
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
実行
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
az iot hub monitor-events --hub-name {AzureIoTHubName} --device-id {DeviceName}
https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-python
Author And Source
この問題について(Raspberry Pi(Python)からAzure IoT Hubへテレメトリーを送信する), 我々は、より多くの情報をここで見つけました https://qiita.com/motoJinC25/items/69545d1cba22793ccf95著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .