Secrets & Global Site Configuration

This commit is contained in:
Quentin WEPHRE
2024-11-21 16:07:03 +01:00
parent 1a383c5302
commit 034507434d
7 changed files with 115 additions and 78 deletions

View File

@@ -1,8 +1,12 @@
from azure.iot.hub import IoTHubRegistryManager
from azure.iot.hub.protocol.models import QuerySpecification
from azure.iot.hub.models import CloudToDeviceMethod, CloudToDeviceMethodResult
from dotenv import load_dotenv
import json
import os
load_dotenv()
module_id = "thingspro-agent"
method_name = "thingspro-api-v1"
@@ -12,18 +16,29 @@ payload = '{"method":"GET", "path":"/device/general"}'
# pip install azure-iot-hub
# Authenticate to your Azure account
CONNECTION_STRING = "HostName=IotHub-CUBE-PROD.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=...="
CONNECTION_STRING = str(os.getenv("CONNECTION_STRING_SAFT_PROD"))
# 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 WHERE tags.site = 'MYRTLE' AND tags.number != '0' AND capabilities.iotEdge = true")
query_spec = QuerySpecification(query="SELECT * FROM devices WHERE IS_DEFINED(tags.site) AND capabilities.iotEdge = true")
query_result = registry_manager.query_iot_hub(query_spec)
devices = []
for item in query_result.items:
number = int(-1)
deviceId = "null"
site = "null"
if item.tagss['number']:
number = int(item.tags['number'])
if item.tags['deviceId']:
deviceId = item.tags['deviceId']
if item.tags['site']:
site = item.tags['site']
devices.append([int(item.tags['number']), item.tags['deviceId'], item.tags['site']])
ordered_devices = sorted(devices, key = lambda x: (x[2], x[0]))