OTA upgrade of thingsboard version 3.4

background

When connecting the device side to the thingsboard platform, it took a lot of time to study the device side docking platform. Before that, I did not find relevant documents, so I wrote this article to reduce the time for everyone to research. Blog, I hope everyone can like it and collect it.

Note: The OTA function is only supported from version 3.3.
insert image description here

Reference English document address:
https://thingsboard.io/docs/user-guide/ota-updates/

1. The device subscribes to these topics in advance

v1/devices/me/attributes
v1/devices/me/attributes/response/+
v1/devices/me/rpc/request/+
v1/devices/me/rpc/response/+
v2/fw/response/+/chunk/+

2. The status of the update process changes, and telemetry data needs to be uploaded to the platform

DOWNLOADING 收到关于新固件/软件更新的通知,设备开始下载更新包
DOWNLOADED  设备已完成更新包的下载
VERIFIED 设备已验证下载包的校验和。
UPDATING  设备已启动固件/软件更新。通常在设备重新启动或服务重新启动之前发送
UPDATED 固件已成功更新到下一版本
FAILED -未验证校验和,或设备更新失败。

topic:

v1/devices/me/telemetry

Sending message format:
//Receive the software upgrade notification and send this format

{
    
    
	"current_fw_title": "Initial", //设备当前标题
	"current_fw_version": "v0",//设备当前版本号
	"fw_state": "DOWNLOADING" //固件升级状态,一共刘总,参考上述说明
}

//Use this format to send the software upgrade notification, so that the current version number of the device can be seen on the platform.

{
    
    
	"current_fw_title": "Initial", //设备当前标题
	"current_fw_version": "v0",//设备当前版本号
}

3. The device actively checks for updates

Obtain the device version information set by the platform (for example, if you click to modify a single device and select a version to upgrade, the shared attributes in the device will be updated), the device can actively obtain the shared attribute information set by the platform, if the version information is found to be inconsistent after obtaining the information , can be updated, the method is as follows:
topic:

v1/devices/me/attributes/request/${requestId}
${requestId} - 请求id,从1开始递增

Send message format:

{
    
    
	"sharedKeys": "fw_version,fw_checksum_algorithm,fw_checksum,fw_size,fw_title,fw_version"
}

return message topic

v1/devices/me/attributes/response/1

Example return message:

{
    
    "shared":{
    
    "fw_checksum":"17ae291d08837890026d562e5b666f88d6389fe71d1183d6ed7eeee7505cc209","fw_size":421320,"fw_title":"f","fw_checksum_algorithm":"SHA256","fw_version":"1.2"}}

property key description

fw_checksum	校验和
fw_size	文件大小,以字节为单位
fw_title	标题
fw_checksum_algorithm	校验和算法,默认SHA256
fw_version	版本

4. Batch update devices on the platform

An upgrade message will be sent to all devices configured with this device, and individual devices will not be upgraded if their versions are set individually.
insert image description here

The platform will actively push the current latest version information to the device, and the device can be judged from the current version, and if it is different, it will be updated.

Note: The device needs to push the current version information of the device to the platform first, and then the platform will modify the version information and send a notification version upgrade information to the device. After receiving the version information, the device must process it, and finally upload the version success or failure message The platform will send the next version upgrade message to the device, which means that a device can only enter the next upgrade after the upgrade is completed.

Receive message topic:

v1/devices/me/attributes

Receive message format:

{
    
    
	"fw_title": "f",
	"fw_version": "1.0",
	"fw_tag": "f 1.0",
	"fw_size": 128537,
	"fw_checksum_algorithm": "SHA256",
	"fw_checksum": "67f3b40ba0cbb7d289a9cf6f3f75e6c319f12bdc82d5c35ecc2f51515a13e5cc"
}
属性key	描述
fw_checksum	校验和
fw_size	文件大小,以字节为单位
fw_title	标题
fw_checksum_algorithm	校验和算法,默认SHA256
fw_version	版本

5. The device requests to obtain the installation package file

Only the installation package file of the target version set by the platform can be obtained. The method of request and acquisition is as follows:
the device sends a message topic:

v2/fw/request/${requestId}/chunk/${chunkNum}

Send message content example:

1230

${requestId}- The request id starts from 1
${chunkNum}- The request block number, which must start from 0 and increment by 1 each time. The sending content is the number of bytes received each time, and the value cannot exceed 65535. The number of block number increments = the total number of bytes in the file/the number of bytes received each time and then rounded up to ensure that the installation package file can be taken completely.

The installation package file data returns topic:

v2/fw/response/${requestId}/chunk/${chunkNum}

The return content of the installation package file:
the byte data of the file, 1230 bytes of data are returned each time, and the last time is generally less than 1230 bytes of data, which can be used as the end mark of file reception. After receiving the entire file, use sha256 to verify the file. If the checksum is equal to the checksum in step 4, the data is considered complete.

Guess you like

Origin blog.csdn.net/qq_40351360/article/details/127659776