Skip to content

Latest commit

 

History

History
executable file
·
50 lines (37 loc) · 4.15 KB

网关子设备固件升级.md

File metadata and controls

executable file
·
50 lines (37 loc) · 4.15 KB

OTA网关子设备固件升级

网关子设备固件升级简介

由于子设备无法直接和云端建立连接,网关设备延用设备OTA升级方式对子设备进行固件升级,支持网关子设备单台升级和批量升级。

如果您还不清楚设备固件升级的使用,请参考 固件升级 文档

运行示例程序体验检查OTA网关子设备固件升级功能

请先按照 网关功能 的步骤,填写好网关设备和子设备对应的设备信息,将网关设备 连接MQTT 进行认证接入。

运行示例程序,在基础功能模块上,点击上报子设备版本按钮,将上报子设备固件版本号检查是否有固件更新。示例代码如下:

mMQTTSample.initOTA();  // 初始化 ota 服务,开始监听平台的推送
mMQTTSample.reportSubDevVersion("0.0"); 

以下是网关设备及子设备成功订阅 OTA 升级的 Topic 主题 和 子设备上报当前版本号 的logcat日志,示例中的版本号version传入的值为0.0。

I/com.tencent.iot.hub.device.java.core.mqtt.TXMqttConnection: Starting subscribe topic: $ota/update/AP9ZLEVFKT/gateway1
I/com.tencent.iot.hub.device.java.core.mqtt.TXMqttConnection: Starting subscribe topic: $ota/update/9RW4A8OOFK/door1
D/TXMQTT: onSubscribeCompleted, status[OK], topics[[$ota/update/AP9ZLEVFKT/gateway1]], userContext[], errMsg[subscribe success]
D/TXMQTT: onSubscribeCompleted, status[OK], topics[[$ota/update/9RW4A8OOFK/door1]], userContext[], errMsg[subscribe success]
I/com.tencent.iot.hub.device.java.core.mqtt.TXMqttConnection: Starting publish topic: $ota/report/9RW4A8OOFK/door1 Message: {"type":"report_version","report":{"version":"0.0"}}
D/TXMQTT: onPublishCompleted, status[OK], topics[[$ota/report/9RW4A8OOFK/door1]],  userContext[], errMsg[publish success]

当在控制台中触发子设备固件升级操作后,再次点击上报子设备版本按钮,设备端会通过订阅的子设备 OTA 升级的 Topic $ota/update/${productID}/${deviceName} 收到固件升级的消息

I/TXMQTT_1.2.3: Received topic: $ota/update/9RW4A8OOFK/door1, id: 0, message: {"file_size":234775,"md5sum":"f2f1b3317d4f1ef7f512bfae5050563b","type":"update_firmware","url":"https://ota-1255858890.cos.ap-guangzhou.myqcloud.com/100012619289_9RW4A8OOFK_0.0.1?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdO8ldrUa0Uts4H5Gzx6FZ9nfedjpiCd7%26q-sign-time%3D1603678277%3B1603764677%26q-key-time%3D1603678277%3B1603764677%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3Dc79061bf0366e368ba5f9582895ee2074a457910%00","version":"0.0.1"}
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: fileLength 234775 bytes
    connect: https://ota-1255858890.cos.ap-guangzhou.myqcloud.com/100012619289_9RW4A8OOFK_0.0.1?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdO8ldrUa0Uts4H5Gzx6FZ9nfedjpiCd7%26q-sign-time%3D1603678277%3B1603764677%26q-key-time%3D1603678277%3B1603764677%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3Dc79061bf0366e368ba5f9582895ee2074a457910%00
I/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: checkServerTrusted OK!!!
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: totalLength 234775 bytes
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: download 7772 bytes. percent:3
...
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: download 234775 bytes. percent:100
I/com.tencent.iot.hub.device.java.core.mqtt.TXMqttConnection: Starting publish topic: $ota/report/9RW4A8OOFK/door1 Message: {"type":"report_progress","report":{"progress":{"state":"done","result_code":"0","result_msg":""},"version":"0.0.1"}}
D/TXMQTT: onPublishCompleted, status[OK], topics[[$ota/report/9RW4A8OOFK/door1]],  userContext[], errMsg[publish success]

以上日志为 子设备收到固件升级的消息 ,下载并显示下载进度,下载新版本固件成功后,上报最新的版本号,此时示例中上报的最新版本号version为0.0.1。