Skip to content

Latest commit

 

History

History
executable file
·
45 lines (33 loc) · 3.84 KB

固件升级.md

File metadata and controls

executable file
·
45 lines (33 loc) · 3.84 KB

OTA设备固件升级

固件升级简介

设备固件升级又称 OTA,是物联网通信服务的重要组成部分。当物联设备有新功能或者需要修复漏洞时,设备可以通过 OTA 服务快速进行固件升级。请参考官网文档 控制台使用手册 固件升级

体验固件升级需要在控制台中添加新的固件,请参考官网文档 开发者手册 设备固件升级

运行示例程序体验检查固件更新功能

请先按照 基于TCP的MQTT设备接入 的步骤,将设备 连接MQTT 进行认证接入。

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

mMQTTSample.checkFirmware(); //检查固件更新

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

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

当在控制台中触发固件升级操作后,设备端会通过订阅的 OTA 升级的 Topic $ota/update/${productID}/${deviceName} 收到固件升级的消息

I/TXMQTT_1.2.3: Received topic: $ota/update/AP9ZLEVFKT/gateway1, id: 0, message: {"file_size":11821,"md5sum":"1d40bfcfc9d7d21ca16b5515c0f6a340","type":"update_firmware","url":"https://ota-1255858890.cos.ap-guangzhou.myqcloud.com/100012619289_AP9ZLEVFKT_0.0.2?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdO8ldrUa0Uts4H5Gzx6FZ9nfedjpiCd7%26q-sign-time%3D1603246098%3B1603332498%26q-key-time%3D1603246098%3B1603332498%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3Df960bd07ea5fd16b1bbef33689b9647a5eccbea9","version":"0.0.2"}
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: fileLength 11821 bytes
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: connect: https://ota-1255858890.cos.ap-guangzhou.myqcloud.com/100012619289_AP9ZLEVFKT_0.0.2?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdO8ldrUa0Uts4H5Gzx6FZ9nfedjpiCd7%26q-sign-time%3D1603246098%3B1603332498%26q-key-time%3D1603246098%3B1603332498%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3Df960bd07ea5fd16b1bbef33689b9647a5eccbea9
I/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: checkServerTrusted OK!!!
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: totalLength 11821 bytes
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: download 7771 bytes. percent:65
D/com.tencent.iot.hub.device.java.core.mqtt.TXOTAImpl: download 11821 bytes. percent:100
I/com.tencent.iot.hub.device.java.core.mqtt.TXMqttConnection: Starting publish topic: $ota/report/AP9ZLEVFKT/gateway1 Message: {"type":"report_progress","report":{"progress":{"state":"done","result_code":"0","result_msg":"OK"},"version":"0.0.2"}}
D/TXMQTT: onPublishCompleted, status[OK], topics[[$ota/report/AP9ZLEVFKT/gateway1]],  userContext[], errMsg[publish success]

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