41 lines
1.1 KiB
Lua
41 lines
1.1 KiB
Lua
local _C = {
|
|
TAG = "【OTA】",
|
|
MSG = {
|
|
_default = "未知状态",
|
|
[0] = "升级包下载成功,重启模块",
|
|
[1] = "连接失败,请检查url拼写或服务器配置(是否为内网)",
|
|
[2] = "url错误,检查url拼写",
|
|
[3] = "服务器断开,检查服务器白名单配置",
|
|
[4] = "接收报文错误,检查模块固件或升级包内文件是否正常",
|
|
[5] = "版本号书写错误,iot平台版本号需要使用xxx.yyy.zzz形式",
|
|
[99] = "OTA失败,继续执行原有逻辑",
|
|
}
|
|
}
|
|
|
|
local libfota2 = require("libfota2")
|
|
|
|
local function libfota_cb(result)
|
|
log.info(COSO, _C.TAG, _C.MSG[result] or _C.MSG._default)
|
|
if result == 0 then
|
|
sys.publish("ota_success")
|
|
else
|
|
log.info(COSO, _C.TAG, _C.MSG[99])
|
|
sys.publish("get_data")
|
|
end
|
|
end
|
|
|
|
local function ota_update()
|
|
sys.waitUntil("ota_update")
|
|
libfota2.request(libfota_cb)
|
|
end
|
|
|
|
local function ota_success()
|
|
sys.waitUntil("ota_success")
|
|
rtos.reboot()
|
|
end
|
|
|
|
sys.taskInit(ota_update)
|
|
sys.taskInit(ota_success)
|
|
|
|
return _C
|