Added default arguments for CUBE SSH activation.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from azure.iot.hub import IoTHubRegistryManager
|
||||
from azure.iot.hub.protocol.models import QuerySpecification
|
||||
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
|
||||
@@ -24,36 +25,27 @@ if CONNECTION_STRING == "":
|
||||
|
||||
|
||||
registry_manager = IoTHubRegistryManager.from_connection_string(CONNECTION_STRING)
|
||||
query_spec = QuerySpecification(query="SELECT * FROM devices WHERE IS_DEFINED(tags.site) AND capabilities.iotEdge = true AND tags.site = 'PIERREFONDS'")
|
||||
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:
|
||||
deviceId = str(item.device_id)
|
||||
site = str(item.tags['site'])
|
||||
number = int(item.tags['number'])
|
||||
cloud_version = str(item.tags['version'])
|
||||
devices.append([deviceId, site, number, cloud_version])
|
||||
# currentDevice = iSightDevice(str(item.device_id), str(item.tags['site']), int(item.tags['number']), str(item.tags['version']))
|
||||
devices.append(iSightDevice(str(item.device_id), str(item.tags['site']), int(item.tags['number']), str(item.tags['version'])))
|
||||
|
||||
ordered_devices = sorted(devices, key = lambda x: (x[1], x[2]))
|
||||
devices.sort(key = lambda d: (d.site, d.number))
|
||||
|
||||
for index in range(len(ordered_devices)):
|
||||
current_device_modules = registry_manager.get_modules(ordered_devices[index][0])
|
||||
for device in devices:
|
||||
print(device, end="\t")
|
||||
current_device_modules = registry_manager.get_modules(device.deviceId)
|
||||
for module in current_device_modules:
|
||||
if module.module_id == module_id:
|
||||
thingspro_module = module
|
||||
print(thingspro_module)
|
||||
try:
|
||||
direct_method = CloudToDeviceMethod(method_name=method_name, payload=json.loads(payload))
|
||||
response = registry_manager.invoke_device_module_method(device_id=ordered_devices[index][0], module_id=module_id, direct_method_request=direct_method)
|
||||
# print(str(ordered_devices[index][0]), str(ordered_devices[index][1]), str(ordered_devices[index][2]), response.payload['data']['description'], "device version: " + str(response.payload['data']['firmwareVersion']), "cloud version: " + str(ordered_devices[index][3]), sep=";")
|
||||
device_version = str(response.payload['data']['firmwareVersion'])
|
||||
if device_version != "1.6.0":
|
||||
payload = '{"deleteFileAfterInstallComplete": true, "install": true, "url": "https://files.thingsprocloud.com/package/Upgrade_AIG-301_2.5.0-4404_IMG_1.5_to_1.6.0.yaml"}'
|
||||
direct_method = CloudToDeviceMethod(method_name=method_name, payload=json.loads(payload))
|
||||
except:
|
||||
print(str(ordered_devices[index][0]), str(ordered_devices[index][1]), str(ordered_devices[index][2]), "UNREACHABLE", "device version: UNREACHABLE", "cloud version: " + str(ordered_devices[index][3]), sep=";")
|
||||
else:
|
||||
print("No thingspro-agent available for " + ordered_devices[index][0] + " (" + ordered_devices[index][1] + " " + ordered_devices[index][2] + ")")
|
||||
|
||||
if (module.module_id == "thingspro-agent"):
|
||||
device.setModule(module)
|
||||
try:
|
||||
direct_method = CloudToDeviceMethod(method_name=method_name, payload=json.loads(payload))
|
||||
response = registry_manager.invoke_device_module_method(device_id=device.deviceId, module_id=module_id, direct_method_request=direct_method)
|
||||
device_version = str(response.payload['data']['firmwareVersion'])
|
||||
print(device_version)
|
||||
except:
|
||||
print("ERROR")
|
||||
Reference in New Issue
Block a user