From a615d23b65291307929b2a2542b594a7dc5b8f2d Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Wed, 2 Jun 2021 14:04:11 -0400 Subject: added init with possibility of aborting --- init.lua | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 34c744e..25a33aa 100644 --- a/init.lua +++ b/init.lua @@ -1,30 +1,33 @@ --- Compile server code and remove original .lua files. --- This only happens the first time after the .lua files are uploaded. -local compileAndRemoveIfNeeded = function(f) - if file.open(f) then - file.close() - print('Compiling:', f) - node.compile(f) - file.remove(f) - collectgarbage() - end -end +-- allows to interrupt start up in the first 5 seconds by hitting +-- borrowed from https://bigdanzblog.wordpress.com/2015/04/24/esp8266-nodemcu-interrupting-init-lua-during-boot/ +function abortInit() + -- initailize abort boolean flag + abort = false + print('Press ENTER within 5 seconds to abort startup') + -- if is pressed, call abortTest + uart.on('data', '\r', abortTest, 0) + -- start timer to execute startup function in 5 seconds + tmr.create():alarm(5000,tmr.ALARM_SINGLE,startup) + end + +function abortTest(data) + -- user requested abort + abort = true + -- turns off uart scanning + uart.on('data') + end -local serverFiles = { - 'microwire.lua', - 'lmx2487lib.lua', - 'binaryLib.lua', - 'freq2lmx2487settings.lua' -} ---for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end +function startup() + uart.on('data') + -- if user requested abort, exit + if abort == true then + print('startup aborted') + return + end + -- otherwise, start up + print('in startup') + dofile('main.lua') + end -compileAndRemoveIfNeeded = nil -serverFiles = nil -collectgarbage() +tmr.create():alarm(1000,tmr.ALARM_SINGLE,abortInit) -- call abortInit after 1s - --- some diagnostic -print('chip: ',node.chipid()) -print('heap: ',node.heap()) - -dofile("main.lua") -- cgit v1.2.3