-->
Page 1 of 2

Timer.Start issue

PostPosted: Thu Dec 13, 2018 7:22 pm
by IOsens
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.

Re: Timer.Start issue

PostPosted: Sun Dec 16, 2018 3:14 pm
by IOsens
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.

Re: Timer.Start issue

PostPosted: Sun Dec 16, 2018 9:33 pm
by RichardS
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

Re: Timer.Start issue

PostPosted: Mon Dec 17, 2018 8:14 pm
by IOsens
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!