PANIC: unprotected error in call to Lua API (init.lua:116: attempt to call field 'alarm' (a nil value))

I keep getting an error on this line of code, how can I solve this? Thanks in advance

tmr.alarm(0, 250, tmr.ALARM_AUTO, function()

Upvotes: 0

Views: 1022

Answers (1)

Marcel Stör
Marcel Stör

Reputation: 23535

You are obviously using an outdated example snippet from somewhere. There is no tmr.alarm function in the timer module.

See https://nodemcu.readthedocs.io/en/latest/modules/tmr/ for the current API documentation. There is a alarm() function on a timer object i.e. you first need to create a timer object. The below example is straight from the documentation:

if not tmr.create():alarm(5000, tmr.ALARM_SINGLE, function()
  print("hey there")
end)
then
  print("whoopsie")
end

Upvotes: 0

Related Questions