From 99aba34460ee28e699fc36a2e6aad9326a6aaf62 Mon Sep 17 00:00:00 2001 From: evoluman Date: Sun, 26 Apr 2020 08:58:30 -0400 Subject: [PATCH] =?UTF-8?q?#2954:=20adapt=20LuaOTA=20to=20the=20new=20firm?= =?UTF-8?q?ware=20api=20for=20the=20timer=20and=20some=20other=20sma?= =?UTF-8?q?=E2=80=A6=20(#3016)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #2954: adapt to the new firmware api for the timer and some other small fixes * reduce the error msg in when not response is sent back from esp * cleanup: remove trailing whitespaces Co-authored-by: Adel Tayeb-Cherif --- lua_examples/luaOTA/_doTick.lua | 5 ++--- lua_examples/luaOTA/check.lua | 2 +- lua_examples/luaOTA/luaOTAserver.lua | 6 +++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lua_examples/luaOTA/_doTick.lua b/lua_examples/luaOTA/_doTick.lua index 979cb003..785822af 100644 --- a/lua_examples/luaOTA/_doTick.lua +++ b/lua_examples/luaOTA/_doTick.lua @@ -1,5 +1,4 @@ --- luacheck: globals self -if (self.timer) then self.timer:stop() end--SAFETRIM +--if (self.timer) then self.timer:stop() end--SAFETRIM -- function _doTick(self) -- Upvals @@ -33,7 +32,7 @@ if (self.timer) then self.timer:stop() end--SAFETRIM -- some resources that are no longer needed and set backstop timer for general -- timeout. This also dereferences the previous doTick cb so it can now be GCed. collectgarbage() - self.timer:alarm(0, 30000, tmr.ALARM_SINGLE, self.startApp) + self.timer:alarm(30000, tmr.ALARM_SINGLE, self.startApp) return self:_provision(socket,rec) end diff --git a/lua_examples/luaOTA/check.lua b/lua_examples/luaOTA/check.lua index e869adf3..9c060c49 100644 --- a/lua_examples/luaOTA/check.lua +++ b/lua_examples/luaOTA/check.lua @@ -45,7 +45,7 @@ end function self.startApp(arg) --upval: gc, self, wifi gc();gc() - self.timer.unregister() + self.timer:unregister() self.socket = nil if not self.config.leave then wifi.setmode(wifi.NULLMODE,false) end local appMod = self.config.app or "luaOTA.default" diff --git a/lua_examples/luaOTA/luaOTAserver.lua b/lua_examples/luaOTA/luaOTAserver.lua index 5356e295..846be9e9 100644 --- a/lua_examples/luaOTA/luaOTAserver.lua +++ b/lua_examples/luaOTA/luaOTAserver.lua @@ -23,7 +23,7 @@ local socket = require "socket" local lfs = require "lfs" local md5 = require "md5" local json = require "cjson" -require "etc.strict" -- see http://www.lua.org/extras/5.1/strict.lua +require "std.strict" -- see http://www.lua.org/extras/5.1/strict.lua -- Local functions (implementation see below) ------------------------------------------ @@ -162,6 +162,10 @@ end ---------------------------------------------------------------------- receive_and_parse = function(esp) local line = esp:receive("*l") + if (not line) then + error( "Empty response from ESP, possible cause: file signature failure", 0) + --return nil + end local packed_cmd, sig = line:sub(1,#line-6),line:sub(-6) -- print("reply:", packed_cmd, sig) local status, cmd = pcall(json.decode, packed_cmd)