summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua57
1 files changed, 30 insertions, 27 deletions
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 <ENTER>
+-- 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 <CR> 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")