You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> [Module identities and module twins](iot-hub-devguide-module-twins.md) are similar to Azure IoT Hub device identity and device twin, but provide finer granularity. While Azure IoT Hub device identity and device twin enable the back-end application to configure a device and provides visibility on the device's conditions, a module identity and module twin provide these capabilities for individual components of a device. On capable devices with multiple components, such as operating system based devices or firmware devices, it allows for isolated configuration and conditions for each component.
18
+
> [Module identities and module twins](iot-hub-devguide-module-twins.md) are similar to Azure IoT Hub device identities and device twins, but provide finer granularity. While Azure IoT Hub device identities and device twins enable a back-end application to configure a device and provide visibility on the device's conditions, module identities and module twins provide these capabilities for individual components of a device. On capable devices with multiple components, such as operating system based devices or firmware devices, they allow for isolated configuration and conditions for each component.
19
19
>
20
20
21
21
At the end of this tutorial, you have three Python apps:
@@ -44,17 +44,23 @@ At the end of this tutorial, you have three Python apps:
44
44
45
45
## Create a device identity and a module identity in IoT Hub
46
46
47
-
In this section, you create a Python app that creates a device identity and a module identity in the identity registry in your IoT hub. A device or module can't connect to IoT hub unless it has an entry in the identity registry. For more information, see the [Identity registry section of the IoT Hub developer guide](iot-hub-devguide-identity-registry.md). When you run this console app, it generates a unique ID and key for both device and module. Your device and module use these values to identify itself when it sends device-to-cloud messages to IoT Hub. The IDs are case-sensitive.
47
+
In this section, you create a Python service app that creates a device identity and a module identity in the identity registry in your IoT hub. A device or module can't connect to IoT hub unless it has an entry in the identity registry. For more information, see [Understand the identity registry in your IoT hub](iot-hub-devguide-identity-registry.md). When you run this console app, it generates a unique ID and key for both device and module. Your device and module use these values to identify itself when it sends device-to-cloud messages to IoT Hub. The IDs are case-sensitive.
48
48
49
49
1. At your command prompt, run the following command to install the **azure-iot-hub** package:
50
50
51
51
```cmd/sh
52
52
pip install azure-iot-hub
53
53
```
54
54
55
+
1. At your command prompt, run the following command to install the **msrest** package. You need this package to catch **HTTPOperationError** exceptions.
56
+
57
+
```cmd/sh
58
+
pip install msrest
59
+
```
60
+
55
61
1. Using a text editor, create a file named **CreateModule.py** in your working directory.
56
62
57
-
1. Add the following code to your Python file:
63
+
1. Add the following code to your Python file. Replace *YourIoTHubConnectionString* with the connection string you copied in [Get the IoT hub connection string](#get-the-iot-hub-connection-string).
58
64
59
65
```python
60
66
import sys
@@ -120,22 +126,22 @@ In this section, you create a Python app that creates a device identity and a mo
120
126
This app creates a device identity with ID **myFirstDevice** and a module identity with ID **myFirstModule** under device **myFirstDevice**. (If the device or module ID already exists in the identity registry, the code simply retrieves the existing device or module information.) The app displays the ID and primary key for each identity.
121
127
122
128
> [!NOTE]
123
-
> The IoT Hub identity registry only stores device and module identities to enable secure access to the IoT hub. The identity registry stores device IDs and keys to use as security credentials. The identity registry also stores an enabled/disabled flag for each device that you can use to disable access for that device. If your application needs to store other device-specific metadata, it should use an application-specific store. There is no enabled/disabled flag for module identities. For more information, see [IoT Hub developer guide](iot-hub-devguide-identity-registry.md).
129
+
> The IoT Hub identity registry only stores device and module identities to enable secure access to the IoT hub. The identity registry stores device IDs and keys to use as security credentials. The identity registry also stores an enabled/disabled flag for each device that you can use to disable access for that device. If your application needs to store other device-specific metadata, it should use an application-specific store. There is no enabled/disabled flag for module identities. For more information, see [Understand the identity registry in your IoT hub](iot-hub-devguide-identity-registry.md).
124
130
>
125
131
126
132
## Update the module twin using Python service SDK
127
133
128
-
In this section, you create a Python app that updates the module twin desired properties.
134
+
In this section, you create a Python service app that updates the module twin desired properties.
129
135
130
-
1. At your command prompt, run the following command to install the **azure-iot-hub** package:
136
+
1. At your command prompt, run the following command to install the **azure-iot-hub** package. You can skip this step if you installed the **azure-iot-hub** package in the previous section.
131
137
132
138
```cmd/sh
133
139
pip install azure-iot-hub
134
140
```
135
141
136
142
1. Using a text editor, create a file named **UpdateModuleTwinDesiredProperties.py** in your working directory.
137
143
138
-
1. Add the following code to your Python file:
144
+
1. Add the following code to your Python file. Replace *YourIoTHubConnectionString* with the connection string you copied in [Get the IoT hub connection string](#get-the-iot-hub-connection-string).
139
145
140
146
```python
141
147
import sys
@@ -173,9 +179,9 @@ In this section, you create a Python app that updates the module twin desired pr
173
179
174
180
## Get updates on the device side
175
181
176
-
In this section, you create a Python app to get the module twin desired properties update on your device.
182
+
In this section, you create a Python device app to get the module twin desired properties update on your device.
177
183
178
-
1. Get your module connection string. In [Azure portal](https://portal.azure.com/), navigate to your IoT Hub and select **IoT devices** on the left pane. Select **myFirstDevice** from the list of devices and open it. Under **Module identities**, select **myFirstModule**. Copy the module connection string. You need it in a following step.
184
+
1. Get your module connection string. In [Azure portal](https://portal.azure.com/), navigate to your IoT Hub and select **IoT devices** in the left pane. Select **myFirstDevice** from the list of devices and open it. Under **Module identities**, select **myFirstModule**. Copy the module connection string. You need it in a following step.
0 commit comments