Initial commit
This commit is contained in:
21
Azure/bash_direct_method.sh
Normal file
21
Azure/bash_direct_method.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get all devices from an IoT Hub (iothub_name) that have the given tag (tag_key == tag_value)
|
||||
# Can also filter using tags.number
|
||||
# Execute an Azure command for each of the devices found
|
||||
# Here the command will execute a Direct Method for the ThingsPro module on the devices. This Direct Method enable the Discovery Service.
|
||||
|
||||
iothub_name="IotHub-CUBE-Prod"
|
||||
|
||||
tag_key="site"
|
||||
tag_value="DANISH"
|
||||
|
||||
devices=$(az iot hub query --hub-name $iothub_name --query-command "SELECT * FROM devices WHERE tags.$tag_key = '$tag_value' AND capabilities.iotEdge = true" --output json)
|
||||
|
||||
device_ids=$(echo "$devices" | jq -r '.[].deviceId')
|
||||
|
||||
for device_id in $device_ids
|
||||
do
|
||||
echo "$device_id"
|
||||
az iot hub invoke-module-method --method-name thingspro-api-v1 --method-payload "{\"method\":\"PUT\",\"path\":\"/system/discovery\",\"requestBody\":{\"enable\": true}""}" --device-id $device_id --module-id thingspro-agent --hub-name $iothub_name
|
||||
done
|
||||
Reference in New Issue
Block a user