Azure IoT Edge Tutorial
Introduction
Azure IoT Edge is a fully managed service built on Azure IoT Hub. It allows you to deploy cloud workloads—such as AI, Azure services, and custom logic—directly to IoT devices, enabling them to act locally on the data they generate. This tutorial will guide you through setting up and using Azure IoT Edge, with detailed explanations and examples.
Prerequisites
Before you start, ensure you have the following:
- An active Azure account
- Basic knowledge of Azure services
- A device running a supported OS (Linux or Windows)
Setting Up Azure IoT Edge
Follow these steps to set up Azure IoT Edge on your device:
Step 1: Install the IoT Edge Runtime
Run the following commands to install the IoT Edge runtime on a Linux device:
For Windows devices, download and install the MSI package from the official website.
Step 2: Configure the IoT Edge Runtime
After installation, configure the runtime with your Azure IoT Hub connection string:
Add the connection string to the provisioning
section:
source: "manual"
device_connection_string: "
Save and close the file, then restart the IoT Edge service:
Deploying Modules
Modules are the building blocks of Azure IoT Edge. They can be Azure services, third-party services, or your own custom code. To deploy a module:
Step 1: Create a Deployment Manifest
Create a JSON file that defines the modules you want to deploy. Here is an example:
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"modules": {
"MyModule": {
"settings": {
"image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0",
"createOptions": ""
},
"type": "docker",
"status": "running",
"restartPolicy": "always"
}
}
}
}
}
}
Step 2: Deploy the Manifest
Use Azure CLI or Azure Portal to deploy the manifest. With Azure CLI, run:
Monitoring and Troubleshooting
Azure IoT Edge provides tools for monitoring and troubleshooting your edge devices and modules:
View Module Logs
To view logs from a specific module, use the following command:
Check Device Status
To check the status of your device and modules, use:
edgeAgent running Up 20 minutes mcr.microsoft.com/azureiotedge-agent:1.1
MyModule running Up 20 minutes mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0
Conclusion
In this tutorial, you have learned how to set up Azure IoT Edge on a device, deploy modules, and monitor their status. Azure IoT Edge is a powerful tool for bringing cloud intelligence to edge devices, enabling real-time data processing and decision-making.