<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marcelo Luna</title>
    <description>The latest articles on DEV Community by Marcelo Luna (@marcelo_luna_fa19f220da0b).</description>
    <link>https://dev.to/marcelo_luna_fa19f220da0b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2096562%2Fdabefe4c-edb8-4788-995b-1c6894eefc48.jpg</url>
      <title>DEV Community: Marcelo Luna</title>
      <link>https://dev.to/marcelo_luna_fa19f220da0b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcelo_luna_fa19f220da0b"/>
    <language>en</language>
    <item>
      <title>Simplify IoT Device Updates with Azure Device Update for IoT Hub</title>
      <dc:creator>Marcelo Luna</dc:creator>
      <pubDate>Tue, 17 Dec 2024 00:26:37 +0000</pubDate>
      <link>https://dev.to/marcelo_luna_fa19f220da0b/simplify-iot-device-updates-with-azure-device-update-for-iot-hub-434p</link>
      <guid>https://dev.to/marcelo_luna_fa19f220da0b/simplify-iot-device-updates-with-azure-device-update-for-iot-hub-434p</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Azure account&lt;/li&gt;
&lt;li&gt;Azure Iot Hub&lt;/li&gt;
&lt;li&gt;Have Azure Device Update for IoT Hub active for the target Iot Hub&lt;/li&gt;
&lt;li&gt;Storage account &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Set-up the device
&lt;/h2&gt;

&lt;p&gt;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!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install device update package
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Open the configuration details (&lt;a href="https://learn.microsoft.com/en-us/azure/iot-hub-device-update/device-update-configuration-file" rel="noopener noreferrer"&gt;See how to set up configuration file here&lt;/a&gt; with the command below). Set your information like manufacturer, model and connection string.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/adu/du-config.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "schemaVersion": "1.1",
  "aduShellTrustedUsers": [
    "adu",
    "do"
  ],
  "iotHubProtocol": "mqtt",
  "compatPropertyNames":"manufacturer,model,location,environment" &amp;lt;The property values must be in lower case only&amp;gt;,
  "manufacturer": &amp;lt;Place your device info manufacturer here&amp;gt;,
  "model": &amp;lt;Place your device info model here&amp;gt;,
  "agents": [
    {
      "name": &amp;lt;Place your agent name here&amp;gt;,
      "runas": "adu",
      "connectionSource": {
        "connectionType": "string", //or “AIS”
        "connectionData": &amp;lt;Place your Azure IoT device connection string here&amp;gt;
      },
      "manufacturer": &amp;lt;Place your device property manufacturer here&amp;gt;,
      "model": &amp;lt;Place your device property model here&amp;gt;,
      "additionalDeviceProperties": {
        "location": "usa",
        "environment": "development"
      }
    }
  ]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My test example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "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"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally restart the Device Update Agent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart deviceupdate-agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tag the device.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the left panel, under Devices, find your IoT device and go to the device twin or module twin (when Azure IoT Edge).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;em&gt;device twin&lt;/em&gt;, 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.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add a new Device Update tag value, as shown:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"tags": {
        "ADUGroup": "&amp;lt;CustomTagValue&amp;gt;"
    },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhm8osvf11axgsxiehm06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhm8osvf11axgsxiehm06.png" alt="Image description" width="360" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare the update
&lt;/h2&gt;

&lt;p&gt;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 &lt;a href="https://github.com/cowsay-org/cowsay" rel="noopener noreferrer"&gt;cowsay &lt;/a&gt;, nothing special with cowsay, the purpose is only see this package installed and running in the end of the process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prepare apt update and import manifest files
&lt;/h3&gt;

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

&lt;p&gt;cowsay-apt-manifest.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name": "Install cowsay",
    "version": "1.0.0", 
    "packages": [
        {
            "name": "cowsay",
            "version": "3.03+dfsg2-8"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After create the apt manifest file, we can generate the manifest import file with the az command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Resulting content:&lt;/p&gt;

&lt;p&gt;cowsay-apt.importmanifest.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "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"
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Publish a new update
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload the two files on Azure Storage account;&lt;/li&gt;
&lt;li&gt;Go to Iot Hub, Device Management, Updates, Import a new update and select the manifest files from Storage Account;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9twdjjj2egkhn5ghn5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9twdjjj2egkhn5ghn5g.png" alt="Image description" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the tab Groups and Deployments, select the Group Name "adugrouptest" (it is the value of tag from ADUGroup that we defined before);&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3vja16fnfw4pmt7sy31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3vja16fnfw4pmt7sy31.png" alt="Image description" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A new update is available as you can see, click in Deploy, select Start Immediately and create;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3sj8lvf8nxvpdhsm2mxx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3sj8lvf8nxvpdhsm2mxx.png" alt="Image description" width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F634t1k8xjzgkslf465ti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F634t1k8xjzgkslf465ti.png" alt="Image description" width="800" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next page you can monitoring the update&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4phycjsweyoh31gm95f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4phycjsweyoh31gm95f.png" alt="Image description" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When succeeded pass from 0 to 1, click on "View devices", and select your device:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facedt4hehfasu6ay5dug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facedt4hehfasu6ay5dug.png" alt="Image description" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the process was completed successfully, you should see:&lt;/p&gt;

&lt;p&gt;Result code: 700&lt;/p&gt;

&lt;p&gt;Deployment step results &amp;gt; Result code: 700&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the result on device
&lt;/h2&gt;

&lt;p&gt;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].&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm59rk5cix633nv81kg64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm59rk5cix633nv81kg64.png" alt="Image description" width="341" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Considerations
&lt;/h2&gt;

&lt;p&gt;This was a simple example of what can be achieved with &lt;strong&gt;Azure Device Update for IoT Hub&lt;/strong&gt;. 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 &lt;a href="https://learn.microsoft.com/en-us/azure/iot-hub-device-update/understand-device-update" rel="noopener noreferrer"&gt;official documentation.&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>iotedge</category>
      <category>iothub</category>
      <category>iot</category>
    </item>
  </channel>
</rss>
