Introduction to the Azure IoT Edge Runtime
The Azure IoT Edge runtime is a collection of programs that turns a device into an IoT Edge device. It allows you to deploy and manage cloud workloads, such as Azure services and custom business logic, to your edge devices. This runtime is crucial for enabling powerful edge intelligence capabilities, data processing, and machine learning directly on your devices, reducing latency and bandwidth costs.
The runtime comprises of the following key components:
- IoT Edge Agent: A module that runs on every IoT Edge device. It's responsible for provisioning the device, starting and monitoring workloads (modules) on the device, and reporting the status of those workloads back to IoT Hub.
- IoT Edge Hub: A module that acts as a local proxy for IoT Hub. It handles communication between modules, between the device and IoT Hub, and between the device and local clients. It supports automatic module deployment and direct communication with IoT Hub.
- Container Runtime: IoT Edge requires a container runtime, like the industry-standard Docker, to manage the lifecycle of modules. Modules are deployed as containers.
Key Concepts and Functionality
Modules
Modules are the fundamental building blocks of your IoT Edge solution. They are typically Docker containers that encapsulate specific functionalities, such as:
- Azure services: Like Azure Stream Analytics, Azure Functions, Machine Learning services.
- Custom business logic: Your own applications written in any language.
- Device logic: Modules that interface with specific hardware.
Module Twin
Similar to device twins in IoT Hub, each module has a corresponding module twin. This twin is a JSON document that represents the state of a module. It contains:
- Desired Properties: Updated by the cloud application and read by the module.
- Reported Properties: Updated by the module and read by the cloud application.
- Tags: Metadata that can be used for querying and targeting deployments.
Communication Patterns
The IoT Edge runtime facilitates robust communication patterns:
- Module-to-Module: Modules can communicate directly with each other using MQTT or AMQP.
- Module-to-Cloud: Modules can send telemetry and C2D messages to IoT Hub.
- Cloud-to-Module: IoT Hub can send direct commands or C2D messages to modules.
Deployment Manifests
You use deployment manifests (JSON files) to define the modules to run on an IoT Edge device, their configurations, routes for message exchange, and desired module twin properties. This manifest is sent from IoT Hub to the IoT Edge device.
Getting Started with the Runtime
To begin developing with the Azure IoT Edge runtime, you'll typically follow these steps:
- Set up your development environment: Install Docker, the Azure IoT Edge SDKs, and Visual Studio Code with the Azure IoT Edge extension.
- Create an IoT Hub and register your edge device: This establishes the connection between your cloud and edge.
- Develop your module(s): Write your application logic and package it as a container.
- Create a deployment manifest: Define your modules, routes, and desired properties.
- Deploy to your edge device: Use IoT Hub to push the deployment to your device.
Here's a simplified example of a deployment manifest snippet:
{
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"schemaVersion": "1.0",
"runtime": {
"type": "docker",
"settings": {
"minDockerVersion": "v1.25"
}
},
"systemModules": {
"edgeAgent": {
"type": "docker",
"env": {},
"image": "mcr.microsoft.com/azureiotedge-agent:1.4",
"status": "running",
"restartPolicy": "always"
},
"edgeHub": {
"type": "docker",
"env": {
"experimentalFeatures": {
"routingStatus": "enabled"
}
},
"image": "mcr.microsoft.com/azureiotedge-hub:1.4",
"status": "running",
"restartPolicy": "always",
"routes": {
"upstream": "input4ToOutput1"
}
}
},
"modules": {
"myCustomModule": {
"version": "1.0.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"image": "your-docker-registry/mycustommodule:latest",
"createOptions": {}
}
}
}
},
"$edgeHub": {
"properties.desired": {
"schemaVersion": "1.0",
"routes": {
"routeFromEdgeHubToIoTHub": "FROM /messages/* INTO $upstream"
},
"storeAndForward": {
"timeToLiveSecs": 7200
}
}
}
}
}
Resources and Further Learning
For more in-depth information, tutorials, and code samples, please refer to the following official Microsoft resources:
- Azure IoT Edge Documentation
- Develop a custom module for Azure IoT Edge
- Azure IoT Edge Samples on GitHub
- Azure IoT Blog
Join the Azure IoT Community to ask questions, share your knowledge, and connect with other developers.