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 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.
19
19
>
20
20
21
21
At the end of this tutorial, you have two Python apps:
@@ -28,7 +28,7 @@ At the end of this tutorial, you have two Python apps:
@@ -42,43 +42,78 @@ At the end of this tutorial, you have two Python apps:
42
42
43
43
## Create a device identity and a module identity in IoT Hub
44
44
45
-
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 cannot 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.
45
+
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 cannot 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.
46
46
47
-
Add the following code to your Python file:
47
+
1. At your command prompt, run the following command to install the **azure-iot-hub** package:
48
48
49
-
```python
50
-
import sys
51
-
import iothub_service_client
52
-
from iothub_service_client import IoTHubRegistryManager, IoTHubRegistryManagerAuthMethod, IoTHubError
"> has primary key = " + new_module.authentication.symmetric_key.primary_key)
105
+
106
+
except Exception as ex:
107
+
print("Unexpected error {0}".format(ex))
108
+
except KeyboardInterrupt:
109
+
print("IoTHubRegistryManager sample stopped")
110
+
```
111
+
112
+
4. At your command prompt, run the following command:
113
+
114
+
```cmd/sh
115
+
python AddModule.py
116
+
```
82
117
83
118
This app creates a device identity with ID **myFirstDevice** and a module identity with ID **myFirstModule** under device **myFirstDevice**. (If that module ID already exists in the identity registry, the code simply retrieves the existing module information.) The app then displays the primary key for that identity. You use this key in the simulated module app to connect to your IoT hub.
0 commit comments