WIFI network (ESP8266) upgrade STM32: STM32 download files using http, ping-pong upgrade, rollback support, support MQTT communication control (WIFI module AT, TCP pass-through mode)

 

 

 

 

 

Realize the function summary

 

BootLoader program:

    If you do not update the flag, then attempts to load the user program.

    If an update flag, STM32 control WIFI module to connect TCP Web server, and then send Get protocol to obtain the program file, written in Flash after the restart!

    Each write switch Flash Flash writing position, and updating the state detection added, failed update a version of the program is running (rollback)

APP user program:

    MQTT processing data received, if the received update instruction, the update flag is set, restart

 

MQTT communications upgrades specified in the agreement:

WIFI设备订阅的主题
"user/设备MAC地址"      列如:  "user/dc:4f:22:11:5d:33"
WIFI设备发布的主题
"device/设备MAC地址"    列如:  "device/dc:4f:22:11:5d:33"


一,上位机通过MQTT发送获取设备信息指令
{"data":"updata","cmd":"DeviceInfo"}

//设备回复
{"data":"updata","model":"STM32_AT8266","version":"1.0.2"}//假设现在的型号是STM32_AT8266,当前设备硬件版本是1.0.2


二,上位机根据型号使用http访问云端存放的记录更新信息的文件
                                      "型号"
列如:"http://47.92.31.46/hardware/"+STM32_AT8266+"/"+"updatainfo.txt"

假设updatainfo.txt文件信息是  {"version":"1.0.4","details":"1,优化了部分BUG;2,测试升级;3,支持升级STM32程序;4,修改XXXBUG"}
注:版本号最大设置为20字节

三,上位机对比版本号,如果不一致,则发送以下指令     注:测试时可直接发送此指令
{"data":"updata","cmd":"start"} 


设备回复
{"data":"updata","status":"start"}

四,设备连接上MQTT发送的第一条消息为
"{\"data\":\"status\",\"status\":\"online\",\"UpdataStatus\":\"UpdataSuccess\",\"DeviceVersion\":\"1.0.4\"}"

UpdataSuccess               更新成功
RunAppErr                   上次更新的程序没有运行起来
NoUpdata                    没有更新
DataAddressError            更新的数据有错误
DataOverflow                数据溢出
DataDownloadTimeout         下载超时
MainTimeout                 更新超时
FlashWriteErr               写Flash失败
FlashEraseErr               擦除Flash失败
VersionLenErr               版本号长度 等于0 或者大于20
VersionAlike                版本号一致,是最新程序,无需更新




五,控制指令,查询继电器状态
{"data":"switch","bit":"1","status":"-1"}

设备回复  {"data":"switch","bit":"1","status":"1"}  或者  {"data":"switch","bit":"1","status":"0"}


六,控制指令,控制继电器吸合
{"data":"switch","bit":"1","status":"1"}  设备回复 {"data":"switch","bit":"1","status":"1"}



七,控制指令,控制继电器断开
{"data":"switch","bit":"1","status":"0"}  设备回复 {"data":"switch","bit":"1","status":"0"}

 

 

Flash配置:

 

测试------把程序bin文件,和记录更新信息的文件放在云端

 

 

1.记录更新信息的文件

 

 

 

2.用户程序1   bin文件位置

\

 

 

3.用户程序2   bin文件位置

 

4. 网站根目录下的 hardware文件夹 -> STM32_AT8266文件夹

 

 

 

测试------下载 BootLoader 程序

 

 

 

Guess you like

Origin www.cnblogs.com/yangfengwu/p/11741698.html