• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Simplify IoT Device Updates with Azure Device Update for IoT Hub

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
14,205
Баллы
155
Sooner or later, while working with IoT devices, we come across the need to update the software installed on them. These devices might have intermittent connections, be spread around the world, and be hard to access.

In the last project I worked on, one of the challenges we faced was updating the OS and software packages on devices without accessing them through SSH. To solve this, we leveraged Azure Device Update for IoT Hub, enabling us to automate updates and remotely install Linux packages or execute scripts seamlessly—from Azure to the edge—without direct interaction with the devices.

In this post, I’ll show you how to set up a device to communicate and receive updates from Azure IoT Hub.

Pre-requisites

  • Azure account
  • Azure Iot Hub
  • Have Azure Device Update for IoT Hub active for the target Iot Hub
  • Storage account
Set-up the device


First of all, to start working with Azure Device Update, we need to install and configure it. For this tutorial, I’ll be using Ubuntu 22.04. So, let’s get started!

  • Install device update package


wget

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

-O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install deviceupdate-agent

sudo nano /etc/adu/du-config.json

{
"schemaVersion": "1.1",
"aduShellTrustedUsers": [
"adu",
"do"
],
"iotHubProtocol": "mqtt",
"compatPropertyNames":"manufacturer,model,location,environment" <The property values must be in lower case only>,
"manufacturer": <Place your device info manufacturer here>,
"model": <Place your device info model here>,
"agents": [
{
"name": <Place your agent name here>,
"runas": "adu",
"connectionSource": {
"connectionType": "string", //or “AIS”
"connectionData": <Place your Azure IoT device connection string here>
},
"manufacturer": <Place your device property manufacturer here>,
"model": <Place your device property model here>,
"additionalDeviceProperties": {
"location": "usa",
"environment": "development"
}
}
]
}

My test example:


{
"schemaVersion": "1.1",
"aduShellTrustedUsers": [
"adu",
"do"
],
"iotHubProtocol": "mqtt",
"manufacturer": "amazingdevice",
"model": "xyz",
"agents": [
{
"name": "main",
"runas": "adu",
"connectionSource": {
"connectionType": "string",
"connectionData": "your iot hub connection string"
},
"manufacturer": "amazingdevice",
"model": "xyz"
}
]
}

Finally restart the Device Update Agent:


sudo systemctl restart deviceupdate-agent

  • Tag the device.


  • On the left panel, under Devices, find your IoT device and go to the device twin or module twin (when Azure IoT Edge).


  • In the device twin, 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 module twin of the Device Update agent module.


  • Add a new Device Update tag value, as shown:

"tags": {
"ADUGroup": "<CustomTagValue>"
},


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Prepare the update


After prepare our device to communicates with Device Update for IoT Hub, we can finally start work on that. We will install a package called

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

, nothing special with cowsay, the purpose is only see this package installed and running in the end of the process.

Prepare apt update and import manifest files


We need to prepare two files to install cowsay from Azure IoT, the apt manifest file that has information such as name, version and etc. And manifest import file. The last one should be generate with Azure Cli. Example:

cowsay-apt-manifest.json


{
"name": "Install cowsay",
"version": "1.0.0",
"packages": [
{
"name": "cowsay",
"version": "3.03+dfsg2-8"
}
]
}

After create the apt manifest file, we can generate the manifest import file with the az command:


az iot du update init v5 --update-provider me --update-name aptcowsay --update-version 1.0.0 --compat manufacturer=amazingdevice model=xyz --step handler=microsoft/apt:1 --file path=C:/Projects/adu/apt/cowsay-apt-manifest.json

Resulting content:

cowsay-apt.importmanifest.json


{
"compatibility": [
{
"manufacturer": "amazingdevice",
"model": "xyz"
}
],
"createdDateTime": "2024-12-16T22:59:40Z",
"files": [
{
"filename": "cowsay-apt-manifest.json",
"hashes": {
"sha256": "JNYocz3l4Ofwd94l14HT+2GvyHLtmWNMd+KbyYLcRBk="
},
"sizeInBytes": 179
}
],
"instructions": {
"steps": [
{
"files": [
"cowsay-apt-manifest.json"
],
"handler": "microsoft/apt:1",
"handlerProperties": {
"installedCriteria": "1.0"
},
"type": "inline"
}
]
},
"manifestVersion": "5.0",
"updateId": {
"name": "aptcowsay",
"provider": "me",
"version": "1.0.0"
}
}
Publish a new update


With the two required files created for preparing an update in the Azure portal, the next step is to upload them to an Azure Storage Account, configure the update, and publish it.

  • Upload the two files on Azure Storage account;
  • Go to Iot Hub, Device Management, Updates, Import a new update and select the manifest files from Storage Account;


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



  • Select the tab Groups and Deployments, select the Group Name "adugrouptest" (it is the value of tag from ADUGroup that we defined before);


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



  • A new update is available as you can see, click in Deploy, select Start Immediately and create;


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.




Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



  • Next page you can monitoring the update


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



  • When succeeded pass from 0 to 1, click on "View devices", and select your device:


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



If the process was completed successfully, you should see:

Result code: 700

Deployment step results > Result code: 700

Check the result on device


Now it’s time to verify if the "cowsay" package is indeed installed on our device. To do this, connect to the device and type: cowsay [some text].


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Considerations


This was a simple example of what can be achieved with Azure Device Update for IoT Hub. In the scenario demonstrated, we showcased a package-based update, but it’s also possible to manage image-based and script-based updates, handle larger groups of devices, and explore many other features. For more details, refer to the

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу