有奖:语音产品征文挑战赛火热进行中> HOT

场景简介

针对特定的几款模组,腾讯云物联网开发平台支持定制AT指令集接入,也提供了接入示例,请参考基于腾讯云IoT定制模组接入。但是对于大部分的WiFi/蜂窝模组来说,并没有集成定制的腾讯云AT指令集,但是基本所有的模组都支持AT+TCP的方式联网。本实践旨在帮助开发者完成MCU+AT模组(TCP方式)来连接腾讯云物联网开发平台,完成相关的上云功能开发。

针对市面上MCU和WiFi/蜂窝模组千差万别的情况,本实践使用RT-Thread操作系统来屏蔽MCU的差别,使用AT Device软件包来适配不同的WiFi/蜂窝模组,目前AT Device软件包已经适配了ESP8266、ESP32、M26、MC20、RW007、MW31、SIM800C、W60X 、SIM76XX、A9/A9G、BC26 、AIR720、ME3616、M6315、BC28、EC200X、M5311、L610系列等市面上常见的WiFi/蜂窝模组。


开发环境搭建

示例是基于RT-Thread搭建,RT-Thread 与其他很多 RTOS 如 FreeRTOS、uC/OS 的主要区别之一是,它不仅是一个实时内核,还具备丰富的中间层组件,如下图所示。

RT-Thread 软件框架图


腾讯云物联网开发平台也提供了基于RT-Thread的软件包,请访问这里获取。由上图可见,客户适配了RT-Thread,并且使用了AT Device软件包和腾讯云物联网开发平台软件包,则可以屏蔽掉不同MCU和蜂窝/WiFi模组的差异,可以快速开发应用程序并在不同的硬件设备之间移植。

硬件清单

1. STM32F103ZET6开发板
2. ESP8266 WiFi模组
3. Air780E 4G Cat.1模组
4. USB转串口
5. DAP Link

软件开发环境搭建

完成硬件准备工作后,开始软件适配,关于RT-Thread的相关知识,请访问官网文档
1. 首先根据自己项目需要下载rt-thread,推荐下载长期支持的稳定版本。
git clone -b lts-v4.1.x https://github.com/RT-Thread/rt-thread.git
2. 下载env配置环境。
3. rt-thread提供了很多硬件的板级支持包,根据自己的硬件,选择合适的bsp,并构建rt-thread工程。
1. 打开env开发环境,找到rt-thread bsp目录
$ cd .\\rt-thread\\bsp\\stm32\\stm32f103-atk-warshipv3
2. 使用scons命令来生成rt-thread工程
$ scons --target=mdk5 --dist
3. 将dist目录下的工程拷贝到工作环境中
4. 配置工程,使用腾讯云物联网开发平台软件包。



5. 使用AT Device软件包,我们以手上的Air780E模组为例(Air720的AT指令集和Air780兼容)。



6. 更新软件包,更新工程,通过上面的menuconfig配置后,需要拉取软件包并重新配置工程。
1. 拉取软件包
$ pkgs --update
2. 更新工程
$ scons --target==mdk5
通过以上六步,我们完成了工程的搭建,接下来就以此为基础,来介绍设备如何接入腾讯云物联网开发平台,以及如何OTA。
注意:
RT-Thread的console和AT都需要串口支持,需要开启相关串口并使能串口驱动。本示例USART1是console串口,USART3是AT串口。

设备上云

1. 以Keil开发为例,打开刚才配置好的工程如下,里面包含了rt-thread、AT Device和腾讯云物联网开发平台的c-sdk。



2. 配置rtconfig.h,配置腾讯云物联网开发平台生成的三元组信息。
#define PKG_USING_TENCENT_IOT_EXPLORER_PRODUCT_ID "YOUR_PRODUCT_ID"
#define PKG_USING_TENCENT_IOT_EXPLORER_DEVICE_NAME "YOUR_DEVICE_NAME"
#define PKG_USING_TENCENT_IOT_EXPLORER_DEVICE_SECRET "YOUR_DEVICE_SECRET"
3. 编译工程。



4. 烧录&运行,如果使用ifconfig命令能查到设备的IP和DNS,则表明入网成功。
\\ | /
- RT - Thread Operating System
/ | \\ 4.1.1 build Dec 25 2023 17:43:26
2006 - 2022 Copyright by RT-Thread team
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/at.clnt] AT client(V1.3.1) on device uart3 initialize success.
[I/at.dev] start initializing the air720 device(air720)
[I/at.dev]
[I/at.dev] AirM2M_780E_V1157_LTE_AUAT
[I/at.dev]
[I/at.dev] air720 device(air720) SIM card detection success.
[I/at.dev] air720 device(air720) GSM network is registered(0,1),
[I/at.dev] air720 device(air720) GPRS network is registered(0,1).
[I/at.dev] air720 device(air720) signal strength: 27,0
[I/at.dev] air720 device(air720) attach GPRS
[I/at.dev] air720 device(air720) IP address: 10.77.23.95
[D/at.dev] air720 device(air720) primary DNS server address: 183.230.126.225
[D/at.dev] air720 device(air720) secondary DNS server address: 183.230.126.224
[I/at.dev] air720 device(air720) network initialize success!
[D/at.dev] the[D/at.dev] start air720 device(?? link status check

rt air720 device(?? link status check
status.
msh />[D/at.dev] air720 device(air720) signal strength: 27,0

msh />
msh />
msh />ifconfig
network interface device: air720 (Default)
MTU: 1500
IMEI: 869020065998831
FLAGS: UP LINK_UP INTERNET_UP DHCP_ENABLE
ip address: 10.77.23.95
gw address: 0.0.0.0
net mask : 0.0.0.0
dns server #0: 183.230.126.225
dns server #1: 183.230.126.224
msh />
5. AT Device软件包支持Socket编程,腾讯云物联网开发平台软件包也做了rt-thread socket的适配,所以可以直接编译运行。
msh />tc_data_template_example start
INF|144|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\utils\\qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.2.2-e6ff3455c4c0219b9c8448b63e0ef4a8e90be740, Product_ID: 5QQL7PE06Z, Device_Name: dev002
INF|144|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\utils\\qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.2.2-e6ff3455c4c0219b9c8448b63e0ef4a8e90be740, Product_ID: 5QQL7PE06Z, Device_Name: dev002
DBG|144|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(68): establish tcp connection with server(host=5QQL7PE06Z.iotcloud.tencentdevices.com port=1883)
msh />DBG|145|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(101): success to establish tcp, fd=3
INF|145|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client.c|IOT_MQTT_Construct(132): mqtt connect with id: 502qv success
DBG|145|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_subscribe.c|qcloud_iot_mqtt_subscribe(147): topicName=$thing/down/property/5QQL7PE06Z/dev002|packet_id=22134
DBG|145|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|_template_mqtt_event_handler(275): template subscribed successfully, packet-id=22134
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|event_handler(176): subscribe success, packet-id=22134
INF|145|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|_template_check_subscribe(314): Sync device data successfully
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|data_template_thread(383): Cloud Device Construct Success
DBG|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|_usr_init(209): add your init code here
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|_register_data_template_property(285): data template property=power_switch registered.
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|_register_data_template_property(285): data template property=color registered.
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|_register_data_template_property(285): data template property=brightness registered.
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|_register_data_template_property(285): data template property=name registered.
INF|145|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|data_template_thread(405): Register data template propertys Success
DBG|145|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(346): publish packetID=0|topicName=$thing/up/property/5QQL7PE06Z/dev002|payload={"method":"report_info", "clientToken":"5QQL7PE06Z-0", "params":{"module_hardinfo":"ESP8266","module_softinfo":"V1.0","fw_ver":"3.2.2-e6ff3455c4c0219b9c8448b63e0ef4a8e90be740","imei":"11-22-33-44","lat":"22.546015","lon":"113.941125", "device_label":{"append_info":"your self define in
DBG|146|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|_reply_ack_cb(194): replyAck=0
DBG|146|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|_reply_ack_cb(197): Received Json Document={"method":"report_info_reply","clientToken":"5QQL7PE06Z-0","code":0,"status":"success"}
DBG|146|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(346): publish packetID=0|topicName=$thing/up/property/5QQL7PE06Z/dev002|payload={"method":"get_status", "clientToken":"5QQL7PE06Z-1"}
DBG|146|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|_get_status_reply_ack_cb(211): replyAck=0
DBG|146|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|_get_status_reply_ack_cb(215): Received Json Document={"method":"get_status_reply","clientToken":"5QQL7PE06Z-1","code":0,"status":"success","data":{}}
DBG|146|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|data_template_thread(438): Get data status success
6. 控制台也可以看到设备已经成功上线。



7. 控制台下发开灯指令。



8. 设备收到并执行相关硬件操作。
INF|368|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|OnControlMsgCallback(259): Property=power_switch changed
DBG|368|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|deal_down_stream_user_logic(296): someting about your own product logic wait to be done
DBG|368|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\data_template\\data_template_client.c|IOT_Template_ControlReply(733): Report Document: {"code":0, "clientToken":"v2528561461qhouo::f22c348f-98e5-4501-a3cd-d58d7f15f4a6"}
DBG|368|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(346): publish packetID=0|topicName=$thing/up/property/5QQL7PE06Z/dev002|payload={"method":"control_reply", "code":0, "clientToken":"v2528561461qhouo::f22c348f-98e5-4501-a3cd-d58d7f15f4a6"}
DBG|368|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|data_template_thread(473): Contol msg reply success
DBG|368|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(346): publish packetID=0|topicName=$thing/up/property/5QQL7PE06Z/dev002|payload={"method":"report", "clientToken":"5QQL7PE06Z-2", "params":{"power_switch":1}}
INF|368|packages\\tencent-iot-sdk-latest\\samples\\data_template\\data_template_sample.c|data_template_thread(490): data template reporte success


设备OTA

以STM32F103ZET6开发板为例,该芯片有512KBytes Flash,Flash的划分如下:
FLASH地址
大小
作用
0x08000000~0x080027ff
10 KBytes
bootloader 区,用于检测是否有固件,以及固件搬运
0x08002800~0x08002fff
2 KBytes
OTA Info 区,存储OTA信息,包括文件大小等
0x08003000~0x080417ff
250 KBytes
APP 区,代码运行区
0x08041800~0x0807ffff
250 KBytes
OTA Data 区,存储云端下载的固件
设备上电后,首先进入Boot loader来判断是否有新固件,如果有新固件则搬移固件到代码区,搬移完成后跳转到APP区执行,如果没有则跳转到APP区执行代码。Boot loader流程如下图所示:



而APP代码则是先接入腾讯云物联网开发平台,然后等待平台推送新固件,如果收到新固件则存到OTA Data区,收完后校验固件的完整性,校验通过则跳转到Bootloader进行升级。流程图如下所示:



说明:
关于Bootloader和APP的Flash划分以及详细的开发请参考本文提供的示例工程。
一个完整的OTA升级流程如下:
1. 首先生成一个版本号是mcu_v1.0.1的固件,通过更改宏即可。
#define FW_RUNNING_MCU_VERSION "mcu_v1.0.1"
2. 将编译生成的bin文件上传到腾讯云物联网开发平台。



3. 更改开发板固件版本为mcu_v1.0.0,编译并运行固件。
1. 设备联网后成功拿到IP和DNS IP
2. 运行ota sample并上报当前固件版本

\\ | /
- RT - Thread Operating System
/ | \\ 4.1.1 build Dec 26 2023 15:15:56
2006 - 2022 Copyright by RT-Thread team
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/at.clnt] AT client(V1.3.1) on device uart3 initialize success.
[I/at.dev] start initializing the air720 device(air720)
[I/at.dev]
[I/at.dev] AirM2M_780E_V1157_LTE_AUAT
[I/at.dev]
[I/at.dev] air720 device(air720) SIM card detection success.
[I/at.dev] air720 device(air720) GSM network is registered(0,1),
[I/at.dev] air720 device(air720) GPRS network is registered(0,1).
[I/at.dev] air720 device(air720) signal strength: 28,0
[I/at.dev] air720 device(air720) attach GPRS
[W/at.clnt] execute command (AT+CIPSHUT) timeout (2000 ticks)!
[I/at.dev] air720 device(air720) initialize retry...
[I/at.dev] start initializing the air720 device(air720)
[I/at.dev]
[I/at.dev] AirM2M_780E_V1157_LTE_AUAT
[I/at.dev]
[I/at.dev] air720 device(air720) SIM card detection success.
[I/at.dev] air720 device(air720) GSM network is registered(0,1),
[I/at.dev] air720 device(air720) GPRS network is registered(0,1).
[I/at.dev] air720 device(air720) signal strength: 22,0
[I/at.dev] air720 device(air720) attach GPRS
[I/at.dev] air720 device(air720) IP address: 10.77.23.95
[D/at.dev] air720 device(air720) primary DNS server address: 183.230.126.225
[D/at.dev] air720 device(air720) secondary DNS server address: 183.230.126.224
[I/at.dev] air720 device(air720) network initialize success!
[D/at.de[D/at.dev] start air720 device(?? link status check

r72the network interface device(air720) set up status.
msh />[D/at.dev] air720 device(air720) signal strength: 22,0

msh />ifconfig
network interface device: air720 (Default)
MTU: 1500
IMEI: 869020065998831
FLAGS: UP LINK_UP INTERNET_UP DHCP_ENABLE
ip address: 10.77.23.95
gw address: 0.0.0.0
net mask : 0.0.0.0
dns server #0: 183.230.126.225
dns server #1: 183.230.126.224
msh />tc_ota
tc_ota_example
msh />tc_ota_example start
INF|28|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|ota_thread_entry(519): erase ota flash...
INF|28|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\utils\\qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.2.2-e6ff3455c4c0219b9c8448b63e0ef4a8e90be740, Product_ID: 5QQL7PE06Z, Device_Name: dev002
DBG|28|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(68): establish tcp connection with server(host=5QQL7PE06Z.iotcloud.tencentdevices.com port=1883)
msh />DBG|28|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(101): success to establish tcp, fd=3
INF|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client.c|IOT_MQTT_Construct(132): mqtt connect with id: O7vZ8 success
INF|29|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|ota_thread_entry(538): Cloud Device Construct Success
DBG|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_subscribe.c|qcloud_iot_mqtt_subscribe(147): topicName=$ota/update/5QQL7PE06Z/dev002|packet_id=3981
INF|29|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(105): subscribe success, packet-id=3981
DBG|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_event_callback(125): OTA topic subscribe success
INF|29|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_get_local_fw_running_version(320): FW running mcu version: mcu_v1.0.0
INF|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_ResetStatus(138): reset OTA state!
DBG|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(339): publish topic seq=3982|topicName=$ota/report/5QQL7PE06Z/dev002|payload={"type": "report_version", "report":{"version":"mcu_v1.0.0", "fw_type":"mcu"}}
INF|29|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_get_local_fw_running_version(323): FW running module version: module_v1.0.0
INF|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_ResetStatus(138): reset OTA state!
DBG|29|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(339): publish topic seq=3983|topicName=$ota/report/5QQL7PE06Z/dev002|payload={"type": "report_version", "report":{"version":"module_v1.0.0", "fw_type":"module"}}
INF|30|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(117): publish success, packet-id=3982
DBG|30|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(111): topic=$ota/update/5QQL7PE06Z/dev002
INF|30|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(112): len=91, topic_msg={"type":"report_version_rsp","version":"mcu_v1.0.0","result_code":0,"result_msg":"success"}
INF|30|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|_ota_callback(104): Report version success!
INF|30|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
INF|31|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(117): publish success, packet-id=3983
DBG|31|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(111): topic=$ota/update/5QQL7PE06Z/dev002
INF|31|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(112): len=94, topic_msg={"type":"report_version_rsp","version":"module_v1.0.0","result_code":0,"result_msg":"success"}
INF|31|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|_ota_callback(104): Report version success!
INF|31|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
INF|32|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
INF|33|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
4. 在控制台创建升级任务。



5. 设备收到升级请求并开始升级。
DBG|135|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(111): topic=$ot[D/at.dev] air720 device(air720) signal strength: 25,0
a/update/5QQL7PE06Z/dev002
INF|135|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(112): len=478, topic_msg={"file_size":213404,"fw_type":"mcu","md5sum":"63aa4d0ce2e4c**********617719bb50","type":"update_firmware","url":"http://ota-1255858890.cos.ap-guangzhou.myqcloud.com/96666666666_5QQL7PE06Z_mcu_v1.0.1?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKIDdO8ldrUa0Uts4H5Gzx6FZ9nfedjpiCd7%26q-sign-time%3D1703578386%3B1703664786%26q-key-time%3D1703578386%3B1703664786%26q-
INF|135|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
DBG|135|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_StartDownload(372): to download FW from offset: 0, size: 213404
DBG|135|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(68): establish tcp connection with server(host=ota-1255858890.cos.ap-guangzhou.myqcloud.com port=80)
DBG|136|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(101): success to establish tcp, fd=4
DBG|136|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\http\\utils_httpc.c|qcloud_http_client_connect(739): http client connect success
DBG|136|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(386): remote fw type : 1 mcu
同时控制台也显示下载进度:



6. 升级完成后,设备重启,运行ota sample,固件版本号已经变为mcu_v1.0.1;同时,控制台也显示升级成功。
DBG|137|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_Ioctl(663): origin=63aa4d0ce2e**************23617719bb50, now=63aa4d0ce2e**********17719bb50
INF|137|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(438): The firmware is valid
DBG|137|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_save_fw_data_to_file(285): write index : 412 write len : 0
DBG|137|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_save_fw_data_to_file(288): save offset [213404] 0 bytes to flash.
DBG|137|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_save_fw_data_to_file(290): save the last to flash 0x08075800 412 bytes
DBG|137|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(339): publish topic seq=41406|topicName=$ota/report/5QQL7PE06Z/dev002|payload={"type": "report_progress", "report":{"progress":{"state":"done", "result_code":"0", "result_msg":""},"fw_type":"mcu", "version":"mcu_v1.0.1"}}
INF|137|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_ResetStatus(138): reset OTA state!
INF|138|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(117): publish success, packet-id=41406
INF|138|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|ota_thread_entry(586): OTA success! jump to bootloader....

enter bootloader ....
get app data. update..........
.
.
try enter app...

\\ | /
- RT - Thread Operating System
/ | \\ 4.1.1 build Dec 26 2023 15:15:56
2006 - 2022 Copyright by RT-Thread team
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/at.clnt] AT client(V1.3.1) on device uart3 initialize success.
[I/at.dev] start initializing the air720 device(air720)
[I/at.dev]
[I/at.dev] AirM2M_780E_V1157_LTE_AUAT
[I/at.dev]
[I/at.dev] air720 device(air720) SIM card detection success.
[I/at.dev] air720 device(air720) GSM network is registered(0,1),
[I/at.dev] air720 device(air720) GPRS network is registered(0,1).
[I/at.dev] air720 device(air720) signal strength: 28,0
[I/at.dev] air720 device(air720) attach GPRS
[W/at.clnt] execute command (AT+CIPSHUT) timeout (2000 ticks)!
[I/at.dev] air720 device(air720) initialize retry...
[I/at.dev] start initializing the air720 device(air720)
[I/at.dev]
[I/at.dev] AirM2M_780E_V1157_LTE_AUAT
[I/at.dev]
[I/at.dev] air720 device(air720) SIM card detection success.
[I/at.dev] air720 device(air720) GSM network is registered(0,1),
[I/at.dev] air720 device(air720) GPRS network is registered(0,1).
[I/at.dev] air720 device(air720) signal strength: 22,0
[I/at.dev] air720 device(air720) attach GPRS
[I/at.dev] air720 device(air720) IP address: 10.77.23.95
[D/at.dev] air720 device(air720) primary DNS server address: 183.230.126.225
[D/at.dev] air720 device(air720) secondary DNS server address: 183.230.126.224
[I/at.dev] air720 device(air720) network initialize success!
[D/at.dev] [D/at.dev] start air720 device(?? link status check

the network interface device(air720) set up status.
msh />[D/at.dev] air720 device(air720) signal strength: 22,0

msh />
msh />
msh />tc_ota
tc_ota_example
msh />tc_ota_example start
INF|23|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|ota_thread_entry(519): erase ota flash...
INF|23|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\utils\\qcloud_iot_device.c|iot_device_info_set(55): SDK_Ver: 3.2.2-e6ff3455c4c0219b9c8448b63e0ef4a8e90be740, Product_ID: 5QQL7PE06Z, Device_Name: dev002
DBG|23|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(68): establish tcp connection with server(host=5QQL7PE06Z.iotcloud.tencentdevices.com port=1883)
msh />DBG|23|packages\\tencent-iot-sdk-latest\\ports\\rtthread\\HAL_TCP_rtthread.c|HAL_TCP_Connect(101): success to establish tcp, fd=3
INF|23|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client.c|IOT_MQTT_Construct(132): mqtt connect with id: 936sj success
INF|23|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|ota_thread_entry(538): Cloud Device Construct Success
DBG|23|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_subscribe.c|qcloud_iot_mqtt_subscribe(147): topicName=$ota/update/5QQL7PE06Z/dev002|packet_id=10675
INF|24|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(105): subscribe success, packet-id=10675
DBG|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_event_callback(125): OTA topic subscribe success
INF|24|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_get_local_fw_running_version(320): FW running mcu version: mcu_v1.0.1
INF|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_ResetStatus(138): reset OTA state!
DBG|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(339): publish topic seq=10676|topicName=$ota/report/5QQL7PE06Z/dev002|payload={"type": "report_version", "report":{"version":"mcu_v1.0.1", "fw_type":"mcu"}}
INF|24|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_get_local_fw_running_version(323): FW running module version: module_v1.0.0
INF|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|IOT_OTA_ResetStatus(138): reset OTA state!
DBG|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\protocol\\mqtt\\mqtt_client_publish.c|qcloud_iot_mqtt_publish(339): publish topic seq=10677|topicName=$ota/report/5QQL7PE06Z/dev002|payload={"type": "report_version", "report":{"version":"module_v1.0.0", "fw_type":"module"}}
INF|24|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(117): publish success, packet-id=10676
DBG|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(111): topic=$ota/update/5QQL7PE06Z/dev002
INF|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(112): len=91, topic_msg={"type":"report_version_rsp","version":"mcu_v1.0.1","result_code":0,"result_msg":"success"}
INF|24|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|_ota_callback(104): Report version success!
INF|25|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
INF|26|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|_event_handler(117): publish success, packet-id=10677
DBG|26|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(111): topic=$ota/update/5QQL7PE06Z/dev002
INF|26|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_mqtt.c|_otamqtt_upgrage_cb(112): len=94, topic_msg={"type":"report_version_rsp","version":"module_v1.0.0","result_code":0,"result_msg":"success"}
INF|26|packages\\tencent-iot-sdk-latest\\qcloud-iot-explorer-sdk-embedded-c\\sdk_src\\services\\ota\\ota_client.c|_ota_callback(104): Report version success!
INF|26|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...
INF|27|packages\\tencent-iot-sdk-latest\\samples\\ota\\ota_mqtt_sample.c|process_ota(357): wait for ota upgrade command...



至此,完成升级。


Q&A

1. 使用RT-Thread的AT Device软件包和腾讯云物联网开发平台软件包对硬件有要求吗?
答:原则上对硬件没有要求,但是由于RT-Thread的组件层导致需要更多的设备Flash空间,请注意选择Flash比较大的芯片。

2. 如果AT Device没有支持我的模组怎么办?
答:AT Device支持了大部分市面上的模组,如果您的硬件不在支持列表里,1) . 找相近的模组,例如本实例中AT Device列表并没有支持Air780E模组,但是支持了Air720,一般情况下同一厂家的模组AT指令集都是相同的,仅有个别差别,2) . 请求RT-Thread官方支持,3) . 自己适配,为开源做贡献。

3. 升级过程中出错怎么办?
答:升级出错可能是模组断开了tcp链路,本示例演示了断点续传功能,如果中间失败会从失败处接着拉取固件,直到升级完成。

4. 固件可以存放到外部flash中吗?
答:可以的,如果有外部flash且适配了文件系统接口,则可以参考腾讯云物联网开发平台c-sdk的ota sample,直接将固件存储到文件系统中。