Post your best Lua script examples here

User avatar
By IOsens
#79776 So, I finally did some more tests, and I am just not getting it.
(Using nodemcu adafruit feather HUZZA..)
The behavior of "tmr" does not match the documentation.

Start: (works):

Code: Select alldly = 500
ledPin = 4
gpio.mode(ledPin,gpio.OUTPUT)
ledState = 0

tmr.alarm( 0, dly, 1, function()
  ledState = 1 - ledState;
  gpio.write(ledPin, ledState)
print(ledState)
-- tmr.stop(0)

end)


This is the auto timer and it works as expected. If I uncomment tmr.stop(0), it will stop.

What I cannot do is: (Despite of the documentation stating that the timer will not be de-registerd by a stop command.

Code: Select alltmr.stop(0)
tmr.start(0)


-> attempt to call field 'start' (a nil value))

Same happens when I do a tmr.ALARM_SINGLE, but that is expected as this will unregister the timer automatically as expected.


Somebody else suggested tmr.ALARM_SEMI, but that will not work at all for me:

Code: Select alltmr.alarm( 0, dly, 2, function() ....


yields: wrong arg type

Just ODD

I looked into the source code for nodemcu https://nodemcu.readthedocs.io/en/lates ... r/#tmrstop and everything is happily defined...

I also tried this, right out of the documentation:

Code: Select allmytimer = tmr.create()
mytimer:register(5000, tmr.ALARM_SINGLE, function()

print("hey there")

end)

mytimer:start()


-> attempt to call field 'create' (a nil value)

The only thing that seems to works is tmr.alarm( 0, 500 , "0 or 1" , function()

Nobody else had issue with this??
User avatar
By marcelstoer
#79777
IOsens wrote:-> attempt to call field 'create' (a nil value)


At this point I am reasonably certain that you are using an outdated version of the firmware.

Depending on the version you use not even node.info() will give you much useful information. So, I suggest you take a look at https://nodemcu.readthedocs.io/en/latest/#releases and make sure you run a recent version.