Skip to content

Commit a5bd2c8

Browse files
authored
Merge pull request #98947 from kgremban/release-moduleconfig
Add module config info to ADM
2 parents 1ef6c3b + 42ccb0b commit a5bd2c8

File tree

5 files changed

+113
-58
lines changed

5 files changed

+113
-58
lines changed

articles/iot-hub/iot-hub-automatic-device-management-cli.md

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,43 @@ manager: bruz
66
ms.service: iot-hub
77
services: iot-hub
88
ms.topic: conceptual
9-
ms.date: 06/28/2019
9+
ms.date: 12/13/2019
1010
ms.author: chrisgre
1111
---
1212

1313
# Automatic IoT device management at scale using the Azure CLI
1414

1515
[!INCLUDE [iot-edge-how-to-deploy-monitor-selector](../../includes/iot-hub-auto-device-config-selector.md)]
1616

17-
Automatic device management in Azure IoT Hub automates many of the repetitive and complex tasks of managing large device fleets. With automatic device management, you can target a set of devices based on their properties, define a desired configuration, and then let IoT Hub update the devices when they come into scope. This update is done using an _automatic device configuration_, which lets you summarize completion and compliance, handle merging and conflicts, and roll out configurations in a phased approach.
17+
Automatic device management in Azure IoT Hub automates many of the repetitive and complex tasks of managing large device fleets. With automatic device management, you can target a set of devices based on their properties, define a desired configuration, and then let IoT Hub update the devices when they come into scope. This update is done using an _automatic device configuration_ or _automatic module configuration_, which lets you summarize completion and compliance, handle merging and conflicts, and roll out configurations in a phased approach.
1818

1919
[!INCLUDE [iot-hub-basic](../../includes/iot-hub-basic-whole.md)]
2020

21-
Automatic device management works by updating a set of device twins with desired properties and reporting a summary that's based on device twin reported properties. It introduces a new class and JSON document called a *Configuration* that has three parts:
21+
Automatic device management works by updating a set of device twins or module twins with desired properties and reporting a summary that's based on twin reported properties. It introduces a new class and JSON document called a *Configuration* that has three parts:
2222

23-
* The **target condition** defines the scope of device twins to be updated. The target condition is specified as a query on device twin tags and/or reported properties.
23+
* The **target condition** defines the scope of device twins or module twins to be updated. The target condition is specified as a query on device twin tags and/or reported properties.
2424

25-
* The **target content** defines the desired properties to be added or updated in the targeted device twins. The content includes a path to the section of desired properties to be changed.
25+
* The **target content** defines the desired properties to be added or updated in the targeted device twins or module twins. The content includes a path to the section of desired properties to be changed.
2626

27-
* The **metrics** define the summary counts of various configuration states such as **Success**, **In Progress**, and **Error**. Custom metrics are specified as queries on device twin reported properties. System metrics are the default metrics that measure twin update status, such as the number of device twins that are targeted and the number of twins that have been successfully updated.
27+
* The **metrics** define the summary counts of various configuration states such as **Success**, **In Progress**, and **Error**. Custom metrics are specified as queries on twin reported properties. System metrics are the default metrics that measure twin update status, such as the number of twins that are targeted and the number of twins that have been successfully updated.
2828

29-
Automatic device configurations run for the first time shortly after the configuration is created and then at five minute intervals. Metrics queries run each time the automatic device configuration runs.
29+
Automatic configurations run for the first time shortly after the configuration is created and then at five minute intervals. Metrics queries run each time the automatic configuration runs.
3030

3131
## CLI prerequisites
3232

3333
* An [IoT hub](../iot-hub/iot-hub-create-using-cli.md) in your Azure subscription.
3434
* [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) in your environment. At a minimum, your Azure CLI version must be 2.0.24 or above. Use `az –-version` to validate. This version supports az extension commands and introduces the Knack command framework.
3535
* The [IoT extension for Azure CLI](https://github.com/Azure/azure-iot-cli-extension).
3636

37-
## Implement device twins to configure devices
37+
## Implement twins
3838

39-
Automatic device configurations require the use of device twins to synchronize state between the cloud and devices. Refer to [Understand and use device twins in IoT Hub](iot-hub-devguide-device-twins.md) for guidance on using device twins.
39+
Automatic device configurations require the use of device twins to synchronize state between the cloud and devices. For more information, see [Understand and use device twins in IoT Hub](iot-hub-devguide-device-twins.md).
4040

41-
## Identify devices using tags
41+
Automatic module configurations require the use of module twins to synchronize state between the cloud and modules. For more information, see [Understand and use module twins in IoT Hub](iot-hub-devguide-module-twins.md).
4242

43-
Before you create a configuration, you must specify which devices you want to affect. Azure IoT Hub identifies devices using tags in the device twin. Each device can have multiple tags, and you can define them any way that makes sense for your solution. For example, if you manage devices in different locations, add the following tags to a device twin:
43+
## Use tags to target twins
44+
45+
Before you create a configuration, you must specify which devices or modules you want to affect. Azure IoT Hub identifies devices and using tags in the device twin, and identifies modules using tags in the module twin. Each device or modules can have multiple tags, and you can define them any way that makes sense for your solution. For example, if you manage devices in different locations, add the following tags to a device twin:
4446

4547
```json
4648
"tags": {
@@ -53,9 +55,9 @@ Before you create a configuration, you must specify which devices you want to af
5355

5456
## Define the target content and metrics
5557

56-
The target content and metric queries are specified as JSON documents that describe the device twin desired properties to set and reported properties to measure. To create an automatic device configuration using Azure CLI, save the target content and metrics locally as .txt files. You use the file paths in a later section when you run the command to apply the configuration to your device.
58+
The target content and metric queries are specified as JSON documents that describe the device twin or module twin desired properties to set and reported properties to measure. To create an automatic configuration using Azure CLI, save the target content and metrics locally as .txt files. You use the file paths in a later section when you run the command to apply the configuration to your device.
5759

58-
Here's a basic target content sample:
60+
Here's a basic target content sample for an automatic device configuration:
5961

6062
```json
6163
{
@@ -69,14 +71,38 @@ Here's a basic target content sample:
6971
}
7072
```
7173

74+
Automatic module configurations behave very similarly, but you target `moduleContent` instead of `deviceContent`.
75+
76+
```json
77+
{
78+
"content": {
79+
"moduleContent": {
80+
"properties.desired.chillerWaterSettings": {
81+
"temperature": 38,
82+
"pressure": 78
83+
}
84+
}
85+
}
86+
```
87+
7288
Here are examples of metric queries:
7389

7490
```json
7591
{
7692
"queries": {
77-
"Compliant": "select deviceId from devices where configurations.[[chillersettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='current'",
78-
"Error": "select deviceId from devices where configurations.[[chillersettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='error'",
79-
"Pending": "select deviceId from devices where configurations.[[chillersettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='pending'"
93+
"Compliant": "select deviceId from devices where configurations.[[chillerdevicesettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='current'",
94+
"Error": "select deviceId from devices where configurations.[[chillerdevicesettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='error'",
95+
"Pending": "select deviceId from devices where configurations.[[chillerdevicesettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='pending'"
96+
}
97+
}
98+
```
99+
100+
Metric queries for modules are also similar to queries for devices, but you select for `moduleId` from `devices.modules`. For example:
101+
102+
```json
103+
{
104+
"queries": {
105+
"Compliant": "select deviceId, moduleId from devices.module where configurations.[[chillermodulesettingswashington]].status = 'Applied' AND properties.reported.chillerWaterSettings.status='current'"
80106
}
81107
}
82108
```
@@ -102,11 +128,11 @@ Use the following command to create a configuration:
102128

103129
* --**hub-name** - Name of the IoT hub in which the configuration will be created. The hub must be in the current subscription. Switch to the desired subscription with the command `az account set -s [subscription name]`
104130

105-
* --**target-condition** - Enter a target condition to determine which devices will be targeted with this configuration. The condition is based on device twin tags or device twin desired properties and should match the expression format. For example, `tags.environment='test'` or `properties.desired.devicemodel='4000x'`. 
131+
* --**target-condition** - Enter a target condition to determine which devices or modules will be targeted with this configuration. For automatic device configuration, the condition is based on device twin tags or device twin desired properties and should match the expression format. For example, `tags.environment='test'` or `properties.desired.devicemodel='4000x'`. For automatic module configuration, the condition is based on module twin tags or module twin desired properties.. For example, `from devices.modules where tags.environment='test'` or `from devices.modules where properties.reported.chillerProperties.model='4000x'`.
106132

107-
* --**priority** - A positive integer. In the event that two or more configurations are targeted at the same device, the configuration with the highest numerical value for Priority will apply.
133+
* --**priority** - A positive integer. In the event that two or more configurations are targeted at the same device or module, the configuration with the highest numerical value for Priority will apply.
108134

109-
* --**metrics** - Filepath to the metric queries. Metrics provide summary counts of the various states that a device may report back after applying configuration content. For example, you may create a metric for pending settings changes, a metric for errors, and a metric for successful settings changes.
135+
* --**metrics** - Filepath to the metric queries. Metrics provide summary counts of the various states that a device or module may report back after applying configuration content. For example, you may create a metric for pending settings changes, a metric for errors, and a metric for successful settings changes.
110136

111137
## Monitor a configuration
112138

@@ -123,13 +149,13 @@ az iot hub configuration show --config-id [configuration id] \
123149

124150
Inspect the configuration in the command window. The **metrics** property lists a count for each metric that is evaluated by each hub:
125151

126-
* **targetedCount** - A system metric that specifies the number of device twins in IoT Hub that match the targeting condition.
152+
* **targetedCount** - A system metric that specifies the number of device twins or module twins in IoT Hub that match the targeting condition.
127153

128-
* **appliedCount** - A system metric specifies the number of devices that have had the target content applied.
154+
* **appliedCount** - A system metric specifies the number of devices or modules that have had the target content applied.
129155

130156
* **Your custom metric** - Any metrics you've defined are user metrics.
131157

132-
You can show a list of device IDs or objects for each of the metrics by using the following command:
158+
You can show a list of device IDs, module IDs, or objects for each of the metrics by using the following command:
133159

134160
```cli
135161
az iot hub configuration show-metric --config-id [configuration id] \
@@ -138,7 +164,7 @@ az iot hub configuration show-metric --config-id [configuration id] \
138164

139165
* --**config-id** - The name of the deployment that exists in the IoT hub.
140166

141-
* --**metric-id** - The name of the metric for which you want to see the list of device IDs, for example `appliedCount`.
167+
* --**metric-id** - The name of the metric for which you want to see the list of device IDs or module IDs, for example `appliedCount`.
142168

143169
* --**hub-name** - Name of the IoT hub in which the deployment exists. The hub must be in the current subscription. Switch to the desired subscription with the command `az account set -s [subscription name]`.
144170

@@ -150,11 +176,11 @@ When you modify a configuration, the changes immediately replicate to all target
150176

151177
If you update the target condition, the following updates occur:
152178

153-
* If a device twin didn't meet the old target condition, but meets the new target condition and this configuration is the highest priority for that device twin, then this configuration is applied to the device twin.
179+
* If a twin didn't meet the old target condition, but meets the new target condition and this configuration is the highest priority for that twin, then this configuration is applied.
154180

155-
* If a device twin no longer meets the target condition, the settings from the configuration will be removed and the device twin will be modified by the next highest priority configuration.
181+
* If a twin currently running this configuration no longer meets the target condition, the settings from the configuration will be removed and the twin will be modified by the next highest priority configuration.
156182

157-
* If a device twin currently running this configuration no longer meets the target condition and doesn't meet the target condition of any other configurations, then the settings from the configuration will be removed and no other changes will be made on the twin.
183+
* If a twin currently running this configuration no longer meets the target condition and doesn't meet the target condition of any other configurations, then the settings from the configuration will be removed and no other changes will be made on the twin.
158184

159185
Use the following command to update a configuration:
160186

@@ -177,7 +203,7 @@ az iot hub configuration update --config-id [configuration id] \
177203

178204
## Delete a configuration
179205

180-
When you delete a configuration, any device twins take on their next highest priority configuration. If device twins don't meet the target condition of any other configuration, then no other settings are applied.
206+
When you delete a configuration, any device twins or module twins take on their next highest priority configuration. If twins don't meet the target condition of any other configuration, then no other settings are applied.
181207

182208
Use the following command to delete a configuration:
183209

0 commit comments

Comments
 (0)