Exercise - Deploy an IoT Edge device and manage it from Azure IoT Central
Deploy the IoT Edge runtime to a Linux VM and manage your IoT Edge device from Azure IoT Central.
Recall that to test the solution before deploying it to your stores, you run the IoT Edge modules on a Linux Virtual Machine (VM) in the cloud.
Here, you deploy the IoT Edge runtime to a Linux VM to test the behavior of your modules with your Azure IoT Central application.
Note
This exercise is optional. If you want to complete this exercise, you'll need to create an Azure subscription before you begin. If you don't have an Azure account or you don't want to create one at this time, you can read through the instructions so you understand the information that's being presented.
Configure and deploy the IoT Edge device
In the previous module, you learned that an IoT Edge device needs the connection information from the Azure IoT Central application. Set the following environment variables in your Cloud Shell sandbox:
Generate a strong password to connect to your virtual machine. Your password must be at least 12 characters long and have three of four of the following characters: lowercase characters, uppercase characters, digits, and special characters. Use the command
openssl rand --base64 15
to generate a series of random characters that are suitable for a password:VM_PASSWORD=$(openssl rand --base64 15) echo "Your VM password is: $VM_PASSWORD"
Make a note of the password in case the shell times out and loses the environment variable.
Replace
<IOT_CENTRAL_APP_SCOPE_ID>
with the scope ID you made a note of in the previous exercise:SCOPE_ID="<IOT_CENTRAL_APP_SCOPE_ID>"
Replace
<IOT_CENTRAL_DEVICE_KEY>
with the device primary key you made a note of in the previous exercise:DEVICE_KEY="<IOT_CENTRAL_DEVICE_KEY>"
Run the following command to create a Linux VM, install the IoT Edge runtime, and edit the configuration file. By default, an IoT Edge installation connects directly to an IoT hub. The edits to the configuration file ensure that the IoT Edge device uses the Device Provisioning Service (DPS) to connect to your Azure IoT Central application:
az deployment group create \ --name edgeModuleVM \ --resource-group <rgn>[sandbox resource group name]</rgn> \ --template-uri https://raw.githubusercontent.com/Azure-Samples/iot-central-docs-samples/main/edge-vm-deploy-1-4/edgeModuleVMDeploy.json \ --parameters dnsLabelPrefix="$APP_NAME" \ --parameters adminUsername="AzureUser" \ --parameters adminPassword="$VM_PASSWORD" \ --parameters scopeId="$SCOPE_ID" \ --parameters deviceId="store-001" \ --parameters deviceKey="$DEVICE_KEY"
On the Devices page in your Azure IoT Central application, go to the Environmental Sensor Edge Device devices. If you forgot the URL, run the following command:
echo "You can now navigate to: https://$APP_NAME.azureiotcentral.com/devices"
The Device status changes from Registered to Provisioned when the IoT Edge device connects.
Tip
Expect to wait for several minutes for the status to change to Provisioned.
After the Device status shows Provisioned, select the device name store-001. You can see the available views for the device, including Modules.
Select the Modules view. The status of the three modules changes to Running when the Azure IoT Central application detects that the modules are running. You might need to wait a couple of minutes for the status to update.
Monitor the telemetry
To view the telemetry coming from the IoT Edge device, select View IoT Edge device telemetry. This view is the one you created previously. After a few minutes, you'll see the telemetry on the line chart.
Note
The IoT Edge module is sending some ambient temperature values less than 21°. In the next unit, you'll learn how to filter these low values out at the edge.
Check your work
You now have an IoT Edge device running in an Azure VM, connected to your Azure IoT Central application using DPS, and sending telemetry.
You can also:
- View the raw data coming from the IoT Edge device on the Raw data page.
- Edit the cloud properties you defined on the Store information page.
- Edit the devices writable properties - Send Data and Send Interval - on the Manage page. Azure IoT Central creates this page automatically for IoT Edge devices.