Files
ess-moxa-configuration-tools/Python/azure_iot_hub_list_devices.py
2025-09-17 08:26:56 +02:00

29 lines
912 B
Python

from azure.iot.hub import IoTHubRegistryManager
from azure.iot.hub.protocol.models import QuerySpecification, Module
from azure.iot.hub.models import CloudToDeviceMethod, CloudToDeviceMethodResult
from dotenv import load_dotenv
from isight_device import iSightDevice
import json
import os
load_dotenv()
module_id = "thingspro-agent"
method_name = "thingspro-api-v1"
payload = '{"method":"GET", "path":"/device/general"}'
CONNECTION_STRING = str(os.getenv("CONNECTION_STRING_INOX_PROD"))
if CONNECTION_STRING == "":
print("Provide a connection string for the Iot Hub before running the script!")
exit(13)
registry_manager = IoTHubRegistryManager.from_connection_string(CONNECTION_STRING)
query_spec = QuerySpecification(query="SELECT * FROM devices")
query_result = registry_manager.query_iot_hub(query_spec)
devices = []
for item in query_result.items:
print(item)