Provisioning Azure IoT Edge devices to your Azure IoT Hub

#iotedge #azure #cloud #iot #how-to #microsoft

Before you can start deploying IoT Edge modules onto an IoT Edge device, you will need to provision it to the Azure IoT Hub. The following article will show you how to do it.

Requirements

The following two requirements must be met to be able to register your device to the Azure IoT Hub:

  • A successful installation of the IoT Edge runtime on your device or vm
  • A free or standard tier IoT Hub deployed to your Azure subscription

Registering your device

To register your device, first sign in to the Azure portal, then navigate to your deployed IoT Hub. In the left navigation pane, select "IoT Edge" in the category "Device management". On the right side you will see an overview of all registered devices in the IoT Hub. As this is my first device to be registered, there are currently no devices to display, as you can see in below screenshot:

To register a new device, click "Add IoT Edge device". You will then be redirected to the device creation wizard. As you can see below, you will need to choose a device ID, the authentication type and corresponding settings, whether to connect the device to an IoT hub and the parent device if applicable. For the authentication type we will use auto-generated symmatric keys fow now. 

Remember, symmetric keys are not suited for production use. For production scenarios, X.509 certificates should be used, preferrably signed by a CA for enhanced security. Learn more about authenticating devices to the IoT hub here.

Once you have added the device to  your IoT Hub, it will show up in the list of devices in the Azure portal as you can see below: 

Connecting the IoT Edge device to the IoT Hub

Great! Your device is now registered with the Azure IoT Hub. Now we will need to tell the device how it should connect to the IoT Hub. To do this, we need the connection string for the registered device from the Azure portal. Assuming you still have the device list open, click your newly registered device to open its preferences page. You will see something similar to the screenshot below:

We will need the primary connection string, copy it to your clipboard. Then sign in to your IoT Edge device and execute the following command, with your copied connection string.

sudo iotedge config mp --connection-string '<<YOUR CONNECTION STRING GOES HERE>>'

Now your connection string has been written to the configuration files. To apply the new configuration, run the below command.

sudo iotedge config apply -c '/etc/aziot/config.toml'

After the configuration has been applied, we can check the status of the IoT Edge device with the following commands:

#Check if all services are running
sudo iotedge system status

#Show the logs of the services
sudo iotedge system logs

#Verify configuration and connection status
sudo iotedge check

#Show all modules running
sudo iotedge list

About

Hey, nice to finally meet you! My name is Maximilian, welcome to my blog!