Azure IoT Hub Device Identity and Device Code | Exam AZ-220

Device Identity and Device Code for Azure IoT Hub | AZ-220 Exam

Question

You have just created a device identity in your IoT Hub named , using the following CLI commands:

az extension add --name azure-iot  az iot hub device-identity create   --device-id TempSensor-001   --hub-name {mytemphub-001} 
So that your device can successfully connect to the IoT hub, all you need is the device-id in your device code.

Is this statement true?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B.

Correct Answer: B.

Option A is incorrect because the device id alone is not sufficient for the device to connect.

So that the device can establish connection to the IoT Hub, it needs the device connection string assigned to its identity upon creation in the IoT Hub.

Using Azure CLI, you can get it by a command like this:

<pre class="brush:java;">az iot hub device-identity connection-string show --hub-name mytemphub-001 --device-id TempSensor-001 --output table</pre>Option B is CORRECT because it is the device connection string that the device actually needs to be able to connect to the IoT Hub.

It looks like this:

<pre class="brush:java;">HostName=mytemphub-001.azure-devices.net;DeviceId=TempSensor-001;SharedAccessKey=WCXEysQ1234…...</pre>

Reference:

The statement is true, as the device identity created with the given CLI commands has a unique device ID that is required by the device to connect with the Azure IoT hub.

When a device wants to connect to the Azure IoT hub, it needs to be registered with the hub using a unique device identity. The device identity includes a device ID and other properties that identify the device and its capabilities. The device ID is a unique name that identifies the device in the IoT hub.

In the given scenario, the CLI command "az iot hub device-identity create" is used to create a device identity in the IoT hub with a device ID of "TempSensor-001" and the hub name "{mytemphub-001}". This device ID is unique for the IoT hub and is required by the device code to connect to the IoT hub.

Therefore, the statement is true, and the device ID is required in the device code to establish a connection with the IoT hub.