--- 模块功能:远程升级功能测试(使用Luat iot平台). -- 开机后立即执行一次升级功能,仅执行一次,如果升级包下载成功,自动重启 -- @author openLuat -- @module update.testUpdate1 -- @license MIT -- @copyright openLuat -- @release 2018.03.27 module(...,package.seeall) require"nvm" local otaUrl = nvm.get("otaUrl") local otaCheckInterval = nvm.get("otaCheckInterval") --[[ 使用Luat物联云平台的升级服务器时,按照如下步骤操作 1、在main.lua中定义PRODUCT_KEY变量 2、加载update模块 require"update" 3、调用update.request()即可 ]] require"update" local function otaUpdateCb(result) if result then log.info("otaTask.otaUpdateCb","ota update download success, start reboot...") sys.restart("UPDATE_DOWNLOAD_SUCCESS") else log.error("otaTask.otaUpdateCb","ota update download failed!") end end sys.subscribe("device_config_init_result", function ( ) log.info("otaTask.subscribe.device_config_init_result", "otaUrl:", otaUrl, "otaCheckInterval:", otaCheckInterval) if otaUrl and otaCheckInterval and otaCheckInterval > 0 then update.request(otaUpdateCb,otaUrl,otaCheckInterval * 1000) elseif otaUrl and not otaCheckInterval then update.request(otaUpdateCb,otaUrl) elseif not otaUrl and otaCheckInterval and otaCheckInterval > 0 then update.request(otaUpdateCb, nil, otaCheckInterval * 1000) else update.request() end end) sys.subscribe("device_command_ota_start", function ( ) log.info("otaTask.subscribe.device_command_ota_start", "otaUrl:", otaUrl, "otaCheckInterval:", otaCheckInterval) if otaUrl and otaCheckInterval and otaCheckInterval > 0 then update.request(otaUpdateCb,otaUrl,otaCheckInterval * 1000) elseif otaUrl and not otaCheckInterval then update.request(otaUpdateCb,otaUrl) elseif not otaUrl and otaCheckInterval and otaCheckInterval > 0 then update.request(otaUpdateCb, nil, otaCheckInterval * 1000) else update.request() end end) sys.timerLoopStart(log.info,5000,"otaTask.timerLoopStart",rtos.get_version(),_G.VERSION)