Proof of Concept - how to use custom debian/ubuntu packages with Azure IOT Device Update
- Machine/VM/Device with Ubuntu 18.04 (at least 2GB RAM).
- Azure subscription.
- Azure IOT Hub. Steps
- Enable Device Update for Azure IOT Hub. Steps
- Register an Azure Edge Device in Azure IOT Hub. steps
- Get familiar with Azure IOT Device Update. Docs
- Get familiar with how a sample .NET 7.0. application is packed for Ubuntu 18.04 Ref
- Get familiar with how the custom packages are distributed using a Github Repository. Ref
- Ubuntu 18.04 is used as a base OS for this POC. It is possible to use other OS, but it is not covered in this POC. Higher versions of Ubuntu are not supported by Azure IOT Device Update at the moment of writing this POC.
- In this poc, we will use a custom package that is hosted on a public github repository. It is possible to use a private repository, but it is not covered in this POC.
- The Ubuntu 18.04 machine should have internet access to be able to download packages from the internet.
- The Ubuntu 18.04 machine should have access to Azure IOT Hub to be able to download packages from Azure IOT Device Update.
- The Ubuntu 18.04 used as Operating System is the server version. It is possible to use the desktop version, but it is not covered in this POC.
- Install IoT Edge runtime on device
wget https://packages.microsoft.com/config/ubuntu/18.04/multiarch/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
- Install Container Runtime
sudo apt-get update; \
sudo apt-get install moby-engine
- Use local logging driver
sudo nano /etc/docker/daemon.json
Replace the content with:
{
"registry-mirrors": ["http://localhost:5000"]
}
sudo systemctl restart docker
- Install IoT Edge runtime
sudo apt-get update; \
sudo apt-get install aziot-edge
- Provision the device with its cloud identity
sudo iotedge config mp --connection-string 'PASTE_DEVICE_CONNECTION_STRING_HERE'
sudo iotedge config apply
sudo cat /etc/aziot/config.toml
Follow this steps
To deploy your IoT Edge modules, go to your IoT hub in the Azure portal, then:
- Select Devices from the IoT Hub menu.
- Select your device to open its page.
- Select the Set Modules tab.
- Since we want to deploy the IoT Edge default modules (edgeAgent and edgeHub), we don't need to add any modules to this pane, so select Review + create at the bottom.
- You see the JSON confirmation of your modules. Select Create to deploy the modules.
It will generate a deployment manifest similar to this one:
{
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"schemaVersion": "1.1",
"runtime": {
"type": "docker",
"settings": {}
},
"systemModules": {
"edgeAgent": {
"settings": {
"image": "mcr.microsoft.com/azureiotedge-agent:1.4"
},
"type": "docker"
},
"edgeHub": {
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.4",
"createOptions": "{\"HostConfig\":{\"PortBindings\":{\"443/tcp\":[{\"HostPort\":\"443\"}],\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}]}}}"
},
"status": "running",
"type": "docker"
}
},
"modules": {}
}
},
"$edgeHub": {
"properties.desired": {
"schemaVersion": "1.1",
"storeAndForwardConfiguration": {
"timeToLiveSecs": 7200
},
"routes": {}
}
}
}
}
Note: It might take a few seconds (up to 2 mins) for the portal to reflect the deployments status correctly. Sometimes one of the modules seems to be in status error.
IOT Edge Runtime
sudo iotedge system status
sudo iotedge system logs
sudo iotedge check
Docker containers
docker ps
- Install device update agent
sudo apt-get install deviceupdate-agent
- Configure device update agent
sudo nano /etc/adu/du-config.json
Replace the content with:
{
"schemaVersion": "1.1",
"aduShellTrustedUsers": [
"adu",
"do"
],
"iotHubProtocol": "mqtt",
"manufacturer": "Contoso",
"model": "Video",
"agents": [
{
"name": "corretto-machine-edge-01",
"runas": "adu",
"connectionSource": {
"connectionType": "string",
"connectionData": "PASTE_DEVICE_CONNECTION_STRING_HERE"
},
"manufacturer": "Contoso",
"model": "Video"
}
]
}
- Restart the device update agent
sudo systemctl restart deviceupdate-agent
- Check the status of the device update agent
sudo systemctl status deviceupdate-agent
Follow this steps
- Sign in to the Azure portal and go to the IoT hub.
- On the left pane, under Devices, find your IoT Edge device and go to the Device twin or module twin.
- In the module twin of the Device Update agent module, delete any existing Device Update tag values by setting them to null. If you're using Device identity with Device Update agent, make these changes on the device twin.
- Add a new Device Update tag value.
In our case the tag is:
"tags": {
"ADUGroup": "test-corretto"
},
- Add POC - Custom Package Debian Repository public key to your trusted keys
wget -qO - https://raw.githubusercontent.com/UlisesGascon/poc-custom-package-debian-repository/main/PUBLIC.KEY | sudo apt-key add -
- Add POC - Custom Package Debian Repository repository as source list
echo "deb https://raw.githubusercontent.com/UlisesGascon/poc-custom-package-debian-repository/main/ bionic main" | sudo tee /etc/apt/sources.list.d/ulisesgascon.list
- Update the package list
sudo apt-get update
Note: this step can be automated using ADU
- Download the files to your machine:
-
Import the update Following this steps, but use the files downloaded in the previous step and not the ones mentioned in the example.
-
Check that the group
test-corretto
is listed, and that the update is available. Following this steps -
Deploy the update Following this steps
- Check that
demoapi
is running.
systemctl -l status demoapi.service
- Check that
demoapi
services is responsive.
curl http://localhost:5000/WeatherForecast
The expected response is similar to:
[{"date":"2023-08-04","temperatureC":4,"temperatureF":39,"summary":"Warm"},{"date":"2023-08-05","temperatureC":-14,"temperatureF":7,"summary":"Scorching"},{"date":"2023-08-06","temperatureC":-14,"temperatureF":7,"summary":"Warm"},{"date":"2023-08-07","temperatureC":-4,"temperatureF":25,"summary":"Chilly"},{"date":"2023-08-08","temperatureC":7,"temperatureF":44,"summary":"Cool"}]