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.
/ota/device/inform/${YourProductKey}/${YourDeviceName}
2. The device side subscribes to the following Topic to receive the firmware upgrade notification of the IoT platform.
/ota/device/upgrade/${YourProductKey}/${YourDeviceName}
3. The device side reports the firmware upgrade progress through the following Topic.
/ota/device/progress/${YourProductKey}/${YourDeviceName}
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.
appendix
An example of the Payload of the upgrade message pushed by the IoT platform to the device
{ "code":"1000", "data":{ "size":2233916, "extData":{ "info":"Double 11 corpus update" }, "module":"resource", "sign":"5a1a416f357f17bfa89823d2fd49ef8b", "version":"res-1.2.5", "url":"update package downloaded url address", "signMethod":"Md5", "md5":"5a1a416f357f17bfa89823d2fd49ef8b" }, "id":1617773607348, "message":"success" }
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}` client.subscribe(deviceUpgrade) //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 doUpgrade(message) } }) // 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 " } } console.log(payloadJson) return JSON.stringify(payloadJson); } // Device current firmware version function getFirmwareVersion(version) { const payloadJson = { "id": 1, "params": { "version": version } } console.log(payloadJson) return JSON.stringify(payloadJson); }
IoT platform product introduction details: https://www.aliyun.com/product/iot/iot_instc_public_cn
Alibaba Cloud IoT Platform Customer Exchange Group