Created
September 13, 2021 15:07
-
-
Save elbruno/963d3edf4094bea22b9bbafe4e42a50f to your computer and use it in GitHub Desktop.
getDeviceAndModule.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code based on | |
# https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-python-twin-getstarted | |
import sys | |
from time import sleep | |
from azure.iot.hub import IoTHubRegistryManager | |
from azure.iot.hub.models import Twin, TwinProperties, QuerySpecification, QueryResult | |
# connect using IoTHub connection string and device id with the module identity name | |
IOTHUB_CONNECTION_STRING = "IOT HUB Connection String" | |
DEVICE_ID = 'Device Id' | |
MODULE_ID = 'DoorController' | |
# create IoTHub Registry Manager | |
iothub_registry_manager = IoTHubRegistryManager(IOTHUB_CONNECTION_STRING) | |
# get twin reference https://docs.microsoft.com/en-us/rest/api/iothub/service/devices/get-twin | |
twin = iothub_registry_manager.get_twin(DEVICE_ID) | |
print(type(twin)) | |
# get modules | |
# https://docs.microsoft.com/en-us/rest/api/iothub/service/modules/get-modules-on-device#module | |
modules = iothub_registry_manager.get_modules(DEVICE_ID) | |
print(type(modules)) | |
# iterate through modules | |
for module in modules: | |
print(type(module)) | |
print(module.module_id) | |
print(module.connection_state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment