IoT device "firmware upgrade" OTA, "resource package update" best practice - practice class

1. What is firmware upgrade

Firmware upgrade OTA (Over-the-Air Technology), that is, over-the-air download technology, is an essential basic function of the IoT platform. Through the OTA method, we can upgrade the device firmware of IoT devices distributed all over the world without having to send operation and maintenance personnel around. This article takes the firmware upgrade under the MQTT protocol as an example to introduce the OTA firmware upgrade process, topics and data formats used for data transfer.

2. Firmware upgrade OTA process

The firmware upgrade process under the MQTT protocol is shown in the figure below

The topics used in the firmware upgrade process are listed below

1. The device side reports the firmware version to the IoT platform through the following Topic.


2. The device side subscribes to the following Topic to receive the firmware upgrade notification of the IoT platform.


3. The device side reports the firmware upgrade progress through the following Topic.


3. Actual firmware upgrade

3.1 Device version information

In order to realize the firmware upgrade function, the device must first report the current firmware version correctly, which we can check in the device details.

3.2 Firmware version distribution

When each device accurately reports the firmware version, we can check the version release status of all devices on the console.

3.3 Upload new firmware

When we need to upgrade the device firmware, we must first upload the new version of the firmware to the IoT platform and mark the new version number.

3.4 Verifying the firmware

After the new firmware is uploaded, we need to screen the test equipment to verify whether the firmware is normal, so as to prevent the new firmware from causing abnormal business of the equipment.

After the verification is passed, you will see that the batch upgrade function becomes available.

3.5 Batch upgrade

Click the batch upgrade menu to enter the upgrade configuration page. We can filter devices to be upgraded from multiple dimensions and configure upgrade strategies.

3.6 Upgrade process

After starting the firmware upgrade task, we will see an upgrade batch. Click to enter the details, you can see the list of devices to be upgraded.

On the upgrade batch details page, you can view the status of devices in all states, including: pending push, pushed, upgrading, upgrade successful, upgrade failed, and canceled.


An example of the Payload of the upgrade message pushed by the IoT platform to the device

            "info":"Double 11 corpus update"
        "url":"update package downloaded url address",

Device firmware upgrade simulation code

const fs = require('fs');
const path = require('path');
const mqtt = require('aliyun-iot-mqtt');
//Device Identity Triple + Region
const options = {
    productKey: "replace pk",
    deviceName: "replace dn",
    deviceSecret: "replace ds",
    regionId: "cn-shanghai"
//establish connection
const client = mqtt.getAliyunIotMqttClient(options);
//Subscribe to the Topic of ota news
const deviceUpgrade = `/ota/device/upgrade/${options.productKey}/${options.deviceName}`
//After each connection, report the current firmware version
const deviceInform = `/ota/device/inform/${options.productKey}/${options.deviceName}`
client.publish(deviceInform, getFirmwareVersion("1-45-345a"))
//During the OTA process, report the progress
const deviceProgress = `/ota/device/progress/${options.productKey}/${options.deviceName}`
// message processing
client.on('message', function(topic, message) {
    if (topic == deviceUpgrade) {
      //Receive the ota message and start the upgrade process
// local update
function doUpgrade(message) {
    message = JSON.parse(message)
    // 1. Download the firmware package from url, update the download progress...
    client.publish(deviceProgress, getOTAUpgradeData(23))
    // 2. Verify whether the file signature is consistent with the sign value according to signMethod
    // verifyFirmware()
    // 3. Restart the device and upgrade the firmware
    // burn & reboot()
// update progress
function getOTAUpgradeData(step) {
    const payloadJson = {
        "id": 1,
        "params": {
            "step":  step,
            "desc": " xxxxxxxx "
    return JSON.stringify(payloadJson);
// Device current firmware version
function getFirmwareVersion(version) {
    const payloadJson = {
        "id": 1,
        "params": {
            "version": version
    return JSON.stringify(payloadJson);

IoT platform product introduction details:

Alibaba Cloud IoT Platform Customer Exchange Group


Tags: Operation & Maintenance IoT Alibaba Cloud

Posted by Scottiebabes on Fri, 06 Jan 2023 19:37:13 +0530