Complete the code to create an IoT Hub client using the Azure SDK.
from azure.iot.hub import IoTHubRegistryManager connection_string = "HostName=example.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=key" client = IoTHubRegistryManager([1])
The IoTHubRegistryManager requires the connection string to connect to the IoT Hub.
Complete the code to send a message from a device to the IoT Hub.
from azure.iot.device import IoTHubDeviceClient, Message conn_str = "HostName=example.azure-devices.net;DeviceId=device1;SharedAccessKey=key" device_client = IoTHubDeviceClient.create_from_connection_string([1]) message = Message("Hello IoT Hub") device_client.send_message(message)
The device client is created using the device's connection string to authenticate and send messages.
Fix the error in the code to receive a cloud-to-device message.
message = device_client.[1]()The correct method to receive a cloud-to-device message is receive_message().
Fill both blanks to create a device twin patch update.
patch = [1]({'firmwareVersion': '1.0.1'}) device_client.[2](patch)
json.load instead of json.dumps.send_twin_patch which is not a valid method.The patch must be converted to JSON string using json.dumps, then sent with patch_twin_reported_properties.
Fill all three blanks to create a device twin desired properties filter.
desired_props = [1]['desired'] if desired_props.get([2]) [3] '1.0.1': print('Firmware update needed')
The twin dictionary contains the 'desired' properties. We check if 'firmwareVersion' equals '1.0.1'.