from azure.iot.hub import IoTHubRegistryManager from azure.iot.hub.protocol.models import QueryResult, QuerySpecification import json # Install the Azure IoT Hub SDK: # pip install azure-iot-hub # Authenticate to your Azure account CONNECTION_STRING = "HostName=IotHub-CUBE-PROD.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey= ..." 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 WHERE tags.site = 'SASK'") query_result = registry_manager.query_iot_hub(query_spec) ordered_devices = [] for item in query_result.items: ordered_devices.append([int(item.tags['number']), item.tags['deviceId']]) ordered_devices.sort() for i in ordered_devices: print(i)