0
0
IOT Protocolsdevops~10 mins

Azure IoT Hub overview in IOT Protocols - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an IoT Hub client using the Azure SDK.

IOT Protocols
from azure.iot.hub import IoTHubRegistryManager
connection_string = "HostName=example.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=key"
client = IoTHubRegistryManager([1])
Drag options to blanks, or click blank then click option'
Ahost_name
Bconnection_string
Cdevice_id
Dsas_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using only the host name instead of the full connection string.
2fill in blank
medium

Complete the code to send a message from a device to the IoT Hub.

IOT Protocols
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)
Drag options to blanks, or click blank then click option'
Aconn_str
Bdevice_id
Chost_name
Dsas_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using only the device ID or host name instead of the full connection string.
3fill in blank
hard

Fix the error in the code to receive a cloud-to-device message.

IOT Protocols
message = device_client.[1]()
Drag options to blanks, or click blank then click option'
Areceive_message
Bsend_message
Cget_message
Dlisten_message
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send_message' instead of 'receive_message'.
4fill in blank
hard

Fill both blanks to create a device twin patch update.

IOT Protocols
patch = [1]({'firmwareVersion': '1.0.1'})
device_client.[2](patch)
Drag options to blanks, or click blank then click option'
Ajson.dumps
Bsend_twin_patch
Cpatch_twin_reported_properties
Djson.load
Attempts:
3 left
💡 Hint
Common Mistakes
Using json.load instead of json.dumps.
Using send_twin_patch which is not a valid method.
5fill in blank
hard

Fill all three blanks to create a device twin desired properties filter.

IOT Protocols
desired_props = [1]['desired']
if desired_props.get([2]) [3] '1.0.1':
    print('Firmware update needed')
Drag options to blanks, or click blank then click option'
Atwin
B'firmwareVersion'
C==
Ddevice_client
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'device_client' instead of 'twin'.
Using assignment '=' instead of comparison '=='.