- Fri Apr 17, 2015 5:31 pm
#14870
The short answer is:
1) Yes init.lua is like setup(). It runs once when it "boots".
2) You shouldn't have loop() or long (1 second or more) tmr.delay() in your code. Remember "blink without delay()"? If not you should look it up in the Arduino world. It's kinda like that.
The structure of the code you posted does not loop nor expect to be "loop"ed, it's setting up functions to be called when things happen.
AND, you shouldn't have any of those tmr.delay(18000000) in there. It grinds things to a halt. Instead you should set up an alarm( 1, 18000000, 0, someFunction). If you don't understand then see #2 above.
One more nuance is that if your code is messed up in "init.lua", you may not be able to proceed without re-flashing because whenever it boots it immediately runs your errant code. To get around this the recommended structure is to have two files-- one is "init.lua" and the other is say called "yourcode.lua". The code in "init.lua" pauses 10 seconds and then calls "yourcode.lua". that gives you 10 seconds to intervene if necessary by *removing* "init.lua" before the 10 seconds is up.
file "init.lua":
Code: Select all-- wait 10000 msec then call yourfile.lua
tmr.alarm(1, 10000, 0, function() dofile("yourfile.lua") end )
file "yourcode.lua":
Code: Select all-- this is the code that you had before in init.lua
wifi.setmode(wifi.STATION)
wifi.sta.config("ARDUINO123","ARDUINO123")
exec = 3
status = 4
current = ""
gpio.mode(exec, gpio.OUTPUT)
gpio.mode(status, gpio.OUTPUT)
gpio.write(exec, gpio.LOW)
etc, etc, etc
Hope this helps!
John