#2954: adapt LuaOTA to the new firmware api for the timer and some other sma… (#3016)

* #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 <adel@evoluhome.com>
This commit is contained in:
evoluman 2020-04-26 08:58:30 -04:00 committed by Marcel Stör
parent fd26dea949
commit 99aba34460
3 changed files with 8 additions and 5 deletions

View File

@ -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

View File

@ -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"

View File

@ -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)