通过thingsboard-gateway升级设备

文章介绍了如何通过ThingsboardIoT平台进行设备的OTA升级,特别是当设备通过网关连接时,网关作为设备的角色下载升级包并分发给其他设备。过程中涉及的关键步骤包括关注特定主题、设备报告当前固件版本、平台推送升级信息、网关查询和接收升级包、以及升级状态的同步。此外,文章详细阐述了不同阶段的状态标识和通信协议细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

thingsboard iot平台已经支持设备ota,官方提供的demo都是设备直连的情况。提供的网关python程序不能直接升级设备。研究了下,网关其实也是设备,可以将升级包下载到网关,由网关对设备进行升级。前提是这个网关程序是自己写的,或者更改官方的python程序。

1 网关先关注以下主题

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

2 上电后设备先发送以下信息,告知iot平台固件版本号

v1/devices/me/telemetry

{
    "current_fw_title": "Initial",
    "current_fw_version": "v1.1"
}

3 平台点击网关选择升级包时,此topic会收到如下信息

v1/devices/me/attributes

{"fw_title":"otatest","fw_version":"v1.2","fw_tag":"otatest v1.2","fw_size":457965,"fw_checksum_algorithm":"SHA256","fw_checksum":"72448ed632fc5956ff3f76ab23a3d026cbe5f4dca22658c32922fcffe23673d5"}

4 网关也可以发送消息主动查询升级信息

v1/devices/me/attributes/request/${requestId}

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

平台应答
v1/devices/me/attributes/response/+
{"shared":{"fw_checksum":"72448ed632fc5956ff3f76ab23a3d026cbe5f4dca22658c32922fcffe23673d5","fw_checksum_algorithm":"SHA256","fw_size":457965,"fw_title":"otatest","fw_version":"v1.2"}}

${requestId}从1开始,每次递增

5 网关升级过程中需要同步以下信息到iot平台

v1/devices/me/telemetry 

{
    "current_fw_title": "Initial",
    "current_fw_version": "v1.1",
    "fw_state": "DOWNLOADING"
}

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

6 获取升级包,从以下topic发送信息

v2/fw/request/${requestId}/chunk/${chunkNum}
发送内容:1024

其中 
${requestId}- 请求id从1开始,每次递增
${chunkNum}- 请求块号,必须从0开始,每次递增1。发送内容为每次接收的字节数,该值不能超过65535

平台应答:
平台应答请求包数据,长度为1024,最后一包一般少于这个数

网关取到完整升级包后就可以升级不同设备,并将升级状态同步到iot平台,如果升级失败也要发送状态。

### ThingsBoard Gateway RTU Configuration and Usage #### Overview of ThingsBoard Gateway with RTU Support The ThingsBoard Gateway is designed to facilitate communication between IoT devices that use protocols such as Modbus RTU (Remote Terminal Unit) and the ThingsBoard server. This setup allows for efficient data collection from industrial equipment or sensors connected via serial interfaces. For increasing the rate at which groups of interfaces operate when using an RTU license, specific configurations are necessary[^1]. The configuration process involves setting up both hardware connections and software parameters within the ThingsBoard environment. #### Hardware Setup Requirements To connect devices supporting Modbus RTU protocol to the ThingsBoard platform through the gateway: - Ensure physical connection between the gateway device and target RTUs over RS485/RS232. - Verify correct wiring according to manufacturer specifications. #### Software Installation Steps on Gateway Device Install Python packages required by the ThingsBoard Gateway project including `pymodbus` library which handles low-level details of communicating with Modbus slaves. ```bash pip install thingsboard-gateway pymodbus ``` Configure the ThingsBoard Gateway service file (`thingsboard-gateway.conf`) located typically under `/etc/thingsboard/gateway`. Add entries corresponding to each RTU device specifying its address, baudrate, parity settings among others. Example snippet showing how one might configure multiple RTU devices in JSON format inside this configuration file: ```json { "server": { ... }, "devices": [ { "deviceName": "Temperature Sensor", "deviceType": "modbus", "extensionConfiguration": "./conf/modbus.json" } ] } ``` In addition, create a separate JSON file named `modbus.json`, where detailed attributes like register addresses used during polling can be defined per individual sensor type. #### Running the Gateway Service After completing all setups mentioned above, start the ThingsBoard Gateway daemon ensuring it runs continuously collecting telemetry from configured RTU nodes. ```bash sudo systemctl enable --now thingsboard-gateway ``` Verify operation status checking logs produced either directly accessing them or utilizing journalctl command depending upon Linux distribution specifics. #### Security Considerations When configuring access points exposed publicly ensure proper firewall rules limit exposure only allowing trusted networks while blocking unauthorized attempts targeting default ports associated with services involved here especially considering potential vulnerabilities related to older versions listed elsewhere[^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值