Azure CLI for connecting device to cloud

COTASPAR 6 Reputation points
2020-11-27T13:26:31.16+00:00

I'm trying to take the same steps that allowed me to connect a microcontroller to Azure to be able to publish messages through MQTT but instead of doing it through the web UI I'm trying to use the Azure CLI. However, this is not working at the moment as I get the error shown in the picture. 43169-image.png

I think the problem could be related to the “az iot hub device-identity create -n mbedHubTest -d MbedDeviceTest --ee true -g MbedDemoGroupTest --sta enabled” command. As perhaps this should be “az iot hub configuration create -c {config_name} -n {iothub_name} --content device_content.json --target-condition "tags.building=9 and tags.environment='test'" ” however, I can’t find good resources on how to fill in the device_content.json file and how to, for example, set up the routes in this json file.

Any suggestion to what might be going wrong?

As I mentioned I just want to take these same steps but instead through the CLI as shown here.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,157 questions
{count} votes

1 answer

Sort by: Most helpful
  1. QuantumCache 20,261 Reputation points
    2020-12-01T00:21:54.283+00:00

    Hello @COTASPAR ,

    Updated: 12/10/2020
    How to create IoT Device via Azure CLI:

    The below command creates a simple IoTDevice.

    az iot hub device-identity create --device-id myTestDevicename --hub-name myiothubname  
    

    The below command creates an IoTEdge enabled device via CLI.

    az iot hub device-identity create --device-id myEdgeDevice --edge-enabled --hub-name {hub_name}  
    

    Sample image showing the creation of Simple IoT Device via CLI.

    47262-image.png

    Please refer to the documentation on azure CLI(latest) for device-identity operations:

    Please refer to the documentation on az iot device send-d2c-message

    Please refer to the documentation on az iot device c2d-message send

    43740-image.png

    43855-image.png

    Please comment below if you need further help with this query.