Development practice of OTA firmware upgrade for IoT devices
IoT デバイスの OTA ファームウェアアップグレードの実践
1 はじめに
OTA (Over-the-Air Technology) は無線ダウンロード技術であり、IoT プラットフォームの重要な基本機能です。OTA を使用することで、世界各地に分散する IoT デバイスのデバイスファームウェアを、保守担当者を現地に派遣することなくアップグレードできます。本記事では、MQTT プロトコルでのファームウェアアップグレードを例に、データ転送に使用されるプロセス、トピック、データ形式について紹介します。
2. ファームウェアアップグレードの OTA プロセス
MQTT プロトコルでのファームウェアアップグレードプロセスを以下の図に示します。
ファームウェアアップグレードプロセスで使用されるトピックを以下に示します。
1. デバイス側は以下のトピックを使用して、ファームウェアバージョンを IoT プラットフォームに報告します。
/ota/device/inform/${YourProductKey}/${YourDeviceName}
2. デバイス側は以下のトピックをサブスクライブして、IoT プラットフォームからのファームウェアアップグレード通知を受信します。
/ota/device/upgrade/${YourProductKey}/${YourDeviceName}
3. デバイス側は以下のトピックを使用して、ファームウェアアップグレードの進捗を報告します。
/ota/device/progress/${YourProductKey}/${YourDeviceName}
3. ファームウェアアップグレードの実践
3.1 デバイスのバージョン情報
ファームウェアアップグレード機能を実現するには、まずデバイスが現在のファームウェアバージョンを正しく報告する必要があり、デバイスの詳細で確認できます。
3.2 ファームウェアバージョンの配信状況
各デバイスがファームウェアバージョンを正確に報告すると、コンソールですべてのデバイスのバージョン配信状況を確認できます。
3.3 新しいファームウェアのアップロード
デバイスファームウェアをアップグレードする場合は、まず新しいバージョンのファームウェアを IoT プラットフォームにアップロードし、新しいバージョン番号を指定する必要があります。
3.4 ファームウェアの検証
新しいファームウェアのアップロード後、テストデバイスを選定してファームウェアが正常かどうかを検証する必要があります。これにより、新しいファームウェアがデバイスの正常な業務に影響を与えないようにします。
検証に合格すると、バッチアップグレード機能が使用可能になります。
3.5 バッチアップグレード
バッチアップグレードメニューをクリックして、アップグレード設定ページに入ります。複数のディメンションでアップグレード対象のデバイスを絞り込み、アップグレード戦略を設定できます。
3.6 アップグレードプロセス
ファームウェアアップグレードタスクを開始すると、アップグレードバッチが表示されます。詳細をクリックすると、アップグレード対象のデバイスリストを確認できます。
「アップグレード中」タブには、アップグレード中のデバイスリストとアップグレードの進捗が表示されます。
「アップグレード成功」タブには、ファームウェアアップグレードが完了したデバイスのリストが表示されます。現在のファームウェアバージョン、更新時刻、ステータスが含まれます。
「アップグレード失敗」タブには、アップグレードに失敗したデバイスのリストが表示されます。現在のファームウェアバージョン、更新時刻、失敗理由が含まれます。
付録
IoT プラットフォームからデバイスにプッシュされるアップグレードメッセージのペイロード例
{
"code": "1000",
"data": {
"size":11472299,
"sign":"83254ac96e141affb8aa42cbfec93723",
"version": "2-45-345b",
"signMethod": "Md5",
"md5":"83254ac96e141affb8aa42cbfec93723"
},
"id": 1568864790381,
"message": "success"
}
デバイスファームウェアアップグレードのシミュレーションコード
/**
* node aliyun-iot-device.js
*/
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 the ota message
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 the upgrade progress
function getOTAUpgradeData(step) {
const payloadJson = {
"id": 1,
"params": {
"step": step,
"desc": "xxxxxxxx"
}
}
console.log(payloadJson)
return JSON. stringify(payloadJson);
}
// The current firmware version of the device
function getFirmwareVersion(version) {
const payloadJson = {
"id": 1,
"params": {
"version": version
}
}
console.log(payloadJson)
return JSON. stringify(payloadJson);
}
1 はじめに
OTA (Over-the-Air Technology) は無線ダウンロード技術であり、IoT プラットフォームの重要な基本機能です。OTA を使用することで、世界各地に分散する IoT デバイスのデバイスファームウェアを、保守担当者を現地に派遣することなくアップグレードできます。本記事では、MQTT プロトコルでのファームウェアアップグレードを例に、データ転送に使用されるプロセス、トピック、データ形式について紹介します。
2. ファームウェアアップグレードの OTA プロセス
MQTT プロトコルでのファームウェアアップグレードプロセスを以下の図に示します。
ファームウェアアップグレードプロセスで使用されるトピックを以下に示します。
1. デバイス側は以下のトピックを使用して、ファームウェアバージョンを IoT プラットフォームに報告します。
/ota/device/inform/${YourProductKey}/${YourDeviceName}
2. デバイス側は以下のトピックをサブスクライブして、IoT プラットフォームからのファームウェアアップグレード通知を受信します。
/ota/device/upgrade/${YourProductKey}/${YourDeviceName}
3. デバイス側は以下のトピックを使用して、ファームウェアアップグレードの進捗を報告します。
/ota/device/progress/${YourProductKey}/${YourDeviceName}
3. ファームウェアアップグレードの実践
3.1 デバイスのバージョン情報
ファームウェアアップグレード機能を実現するには、まずデバイスが現在のファームウェアバージョンを正しく報告する必要があり、デバイスの詳細で確認できます。
3.2 ファームウェアバージョンの配信状況
各デバイスがファームウェアバージョンを正確に報告すると、コンソールですべてのデバイスのバージョン配信状況を確認できます。
3.3 新しいファームウェアのアップロード
デバイスファームウェアをアップグレードする場合は、まず新しいバージョンのファームウェアを IoT プラットフォームにアップロードし、新しいバージョン番号を指定する必要があります。
3.4 ファームウェアの検証
新しいファームウェアのアップロード後、テストデバイスを選定してファームウェアが正常かどうかを検証する必要があります。これにより、新しいファームウェアがデバイスの正常な業務に影響を与えないようにします。
検証に合格すると、バッチアップグレード機能が使用可能になります。
3.5 バッチアップグレード
バッチアップグレードメニューをクリックして、アップグレード設定ページに入ります。複数のディメンションでアップグレード対象のデバイスを絞り込み、アップグレード戦略を設定できます。
3.6 アップグレードプロセス
ファームウェアアップグレードタスクを開始すると、アップグレードバッチが表示されます。詳細をクリックすると、アップグレード対象のデバイスリストを確認できます。
「アップグレード中」タブには、アップグレード中のデバイスリストとアップグレードの進捗が表示されます。
「アップグレード成功」タブには、ファームウェアアップグレードが完了したデバイスのリストが表示されます。現在のファームウェアバージョン、更新時刻、ステータスが含まれます。
「アップグレード失敗」タブには、アップグレードに失敗したデバイスのリストが表示されます。現在のファームウェアバージョン、更新時刻、失敗理由が含まれます。
付録
IoT プラットフォームからデバイスにプッシュされるアップグレードメッセージのペイロード例
{
"code": "1000",
"data": {
"size":11472299,
"sign":"83254ac96e141affb8aa42cbfec93723",
"version": "2-45-345b",
"signMethod": "Md5",
"md5":"83254ac96e141affb8aa42cbfec93723"
},
"id": 1568864790381,
"message": "success"
}
デバイスファームウェアアップグレードのシミュレーションコード
/**
* node aliyun-iot-device.js
*/
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 the ota message
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 the upgrade progress
function getOTAUpgradeData(step) {
const payloadJson = {
"id": 1,
"params": {
"step": step,
"desc": "xxxxxxxx"
}
}
console.log(payloadJson)
return JSON. stringify(payloadJson);
}
// The current firmware version of the device
function getFirmwareVersion(version) {
const payloadJson = {
"id": 1,
"params": {
"version": version
}
}
console.log(payloadJson)
return JSON. stringify(payloadJson);
}
Related Articles
-
A detailed explanation of Hadoop core architecture HDFS
Knowledge Base Team
-
What Does IOT Mean
Knowledge Base Team
-
6 Optional Technologies for Data Storage
Knowledge Base Team
-
What Is Blockchain Technology
Knowledge Base Team
Explore More Special Offers
-
Short Message Service(SMS) & Mail Service
50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00
