Post your best Lua script examples here

User avatar
By IOsens
#79558 Hi
I am completely new to EPS8266 and Lua (but not to programming - my first CPU was an 8080...)
Using a nodemcu HUZZA from adafruit

Anyway I am testing some timer stuff and running into this:

Code: Select alltmr.alarm(0, 500, 1, function()
print("I'm here")
tmr.stop(0)

end)


Without the stop, it keeps printing... so far so good.

But if I want to start the timer again like:

Code: Select alltmr.alarm(0, 500, 1, function()
print("I'm here")
tmr.stop(0)

-- do stuff

tmr.start(0)

end)




I get an error: "PANIC: unprotected error in call to Lua API..."

The documentation says that the tmr is still registered when stop is called.

A call to tmr.state(0) does the same. Only tmr.stop(0) seems to works as expected.

Thanks for your thoughts.
User avatar
By IOsens
#79594 Hi

that must have been a really stupid question, 301 views and no answer.

I still don't know why tmr.stop works, but tmr.start will not afterwards...
The documentation explicitely states that the timer will not be unregistered with a stop.

So I should be able to stop and start it.
User avatar
By RichardS
#79595 I do not do LUA but it looks to me that the tmr object on a stop must get deleted.... seems strange....

is there pause function?? then it might make sense.

RichardS
User avatar
By IOsens
#79610 Nope, no pause.

From the LUA (nodemcu) site:


tmr.stop()

Stops a running timer, but does not unregister it. A stopped timer can be restarted with tmr.start().



This does not seem to the right forum, I will try stackoverflow..

Thanks!