def update_twin(iteration_id, download_uri, rtsp):
    """Update twin"""
    if iot is None:
        return

    if iteration_id in iteration_ids:
        logger.info("This iteration already deployed on the Edge")
        return

    try:
        module = iot.get_module(DEVICE_ID, MODULE_ID)
    except:
        logger.error("Module does not exist. Device ID: %s, Module ID: %s",
                     DEVICE_ID, MODULE_ID)
        return

    twin = Twin()
    twin.properties = TwinProperties(
        desired={
            "inference_files_zip_url": download_uri,
            "cam_type": "rtsp_stream",
            "cam_source": rtsp,
        })

    iot.update_module_twin(DEVICE_ID, MODULE_ID, twin, module.etag)

    logger.info(
        "Updated IoT Module Twin with uri and rtsp. Download URI: %s RSTP: %s",
        download_uri,
        rtsp,
    )

    iteration_ids.add(iteration_id)
Ejemplo n.º 2
0
def update_twin(iteration_id, download_uri, rtsp):

    if iot is None: return

    if iteration_id in iteration_ids:
        print('[INFO] This iteration already deployed in the Edge')
        return

    try:
        module = iot.get_module(DEVICE_ID, MODULE_ID)
    except:
        print('[ERROR] module does not exist', DEVICE_ID, MODULE_ID)
        return

    twin = Twin()
    twin.properties = TwinProperties(
        desired={
            'inference_files_zip_url': download_uri,
            'cam_type': 'rtsp_stream',
            'cam_source': rtsp
        })

    iot.update_module_twin(DEVICE_ID, MODULE_ID, twin, module.etag)

    print('[INFO] Updated IoT Module Twin with uri and rtsp', download_uri,
          rtsp)

    iteration_ids.add(iteration_id)
    print_device_info("update_device", device_updated)

    # Get device twin
    twin = iothub_registry_manager.get_twin(device_id)
    print(twin)
    print("")

    additional_props = twin.additional_properties
    if "modelId" in additional_props:
        print("Model id for digital twin is")
        print("ModelId:" + additional_props["modelId"])

    # # Replace twin
    new_twin = Twin()
    new_twin = twin
    new_twin.properties = TwinProperties(desired={"telemetryInterval": 9000})
    print(new_twin)
    print("")

    replaced_twin = iothub_registry_manager.replace_twin(device_id, new_twin)
    print(replaced_twin)
    print("")

    # Update twin
    twin_patch = Twin()
    twin_patch.properties = TwinProperties(desired={"telemetryInterval": 3000})
    updated_twin = iothub_registry_manager.update_twin(device_id, twin_patch,
                                                       twin.etag)
    print(updated_twin)
    print("The twin patch has been successfully applied")
    print("The device twin is: ")
    print("")
    print(twin)
    print("")

    # Print the device's model ID
    additional_props = twin.additional_properties
    if "modelId" in additional_props:
        print("The Model ID for this device is:")
        print(additional_props["modelId"])
        print("")

    # Update twin
    twin_patch = Twin()
    twin_patch.properties = TwinProperties(
        desired={"targetTemperature":
                 42})  # this is relevant for the thermostat device sample
    updated_twin = iothub_registry_manager.update_twin(device_id, twin_patch,
                                                       twin.etag)
    print("The twin patch has been successfully applied")
    print("")

    # invoke device method
    device_method = CloudToDeviceMethod(method_name=method_name,
                                        payload=method_payload)
    iothub_registry_manager.invoke_device_method(device_id, device_method)
    print("The device method has been successfully invoked")
    print("")

    # Set registry manager object to `None` so all open files get closed
    iothub_registry_manager = None
Ejemplo n.º 5
0
        "3. 20 seconds \n"
        "4. Input your Value \n"
        ))
        if defined_telemetry_value == 1: telemetry_interval_value = 5
        if defined_telemetry_value == 2: telemetry_interval_value = 10
        if defined_telemetry_value == 3: telemetry_interval_value = 20
        if defined_telemetry_value == 4: telemetry_interval_value = defined_device_option       
        try:
            # Create IoTHubRegistryManager
            iothub_registry_manager = IoTHubRegistryManager(connection_str)
            twin = iothub_registry_manager.get_twin(device_id)

            # Update twin
            twin_patch = Twin()
            twin_patch = twin
            twin_patch.properties = TwinProperties(desired={"Telemetry_Interval": telemetry_interval_value})
            updated_twin = iothub_registry_manager.update_twin(device_id, twin_patch, twin.etag)
            print("Set Telemetry Interval to: " + str(telemetry_interval_value) + "\n", updated_twin)
            print("")
        
        except Exception as ex:
            print("Unexpected error {0}".format(ex))
        except KeyboardInterrupt:
            print("iothub_registry_manager_sample stopped")
            
    if defined_device_option == 4: # Set Send_Data Switch  
        defined_Send_Data_value = int(input(
        "1. Set Send_Data ON \n"
        "2. Set Send Data OFF \n"
        ))