--- 模块功能:远程升级 -- @module ntp -- @author 朱天华 -- @license MIT -- @copyright openLuat -- @release 2017.11.14 require "misc" require "utils" require "socket" require "log" local sbyte, ssub = string.byte, string.sub module(..., package.seeall) -- 重试次数 local RETRY = 3 -- 升级包保存路径 local UPD_PATH = "/luazip/update.bin" --- 自动连接服务器,检查升级,下载升级包s -- @return 无 -- @usage update.run() uptate_ok = 0 function run() sys.taskInit(function() local cnt = 1 for cnt = 1, RETRY do while not socket.isReady() do sys.waitUntil('IP_READY_IND') end local url = "/update/firmware_upgrade?imei=" .. misc.getimei() .. "&device_key=" .. misc.getsn() .. "&firmware_name=" .. _G.PROJECT .. "_" .. rtos.get_version() .. "&version=" .. _G.VERSION -- local code, head, body = http.request("GET", "http://www.yfzhwlw.com" .. url, 5000) local code, head, body = http.request("GET", "http://120.27.222.26" .. url, 5000) log.error("####################update http code is:",code) if code == "200" then io.writefile(UPD_PATH, body) uptate_ok = code break else uptate_ok = code break end end log.error("file_exists:",file_exists(UPD_PATH)) log.error("length_of_file:",length_of_file(UPD_PATH)) end) end -- 获得文件长度 -- 代码如下: function length_of_file(filename) local fh = assert(io.open(filename, "rb")) local len = assert(fh:seek("end")) fh:close() return len end -- 判断文件是否存在 -- 复制代码 代码如下: function file_exists(path) local file = io.open(path, "rb") if file then file:close() end return file ~= nil end