【发布时间】:2020-03-27 13:35:12
【问题描述】:
我正在尝试修复我在网上找到的一段代码。 (是的,我知道....) 但如果你们能帮助我解决这个错误,那就太棒了:
错误:lua: init.lua:15: 尝试调用方法 'alarm'(一个 nil 值)
代码(来自这里:https://github.com/Christoph-D/esp8266-wakelight)
dofile("globals.lc")
wifi.setmode(wifi.STATION)
wifi.sta.config(WIFI_SSID, WIFI_PASSWORD)
wifi.sta.sethostname(MY_HOSTNAME)
if WIFI_STATIC_IP then
wifi.sta.setip({ip = WIFI_STATIC_IP, netmask = WIFI_NETMASK, gateway = WIFI_GATEWAY})
end
wifi.sta.connect()
-- Initialize the LED_PIN to the reset state.
gpio.mode(LED_PIN, gpio.OUTPUT)
gpio.write(LED_PIN, gpio.LOW)
tmr.alarm(
MAIN_TIMER_ID, 2000, tmr.ALARM_AUTO, function ()
if wifi.sta.getip() then
tmr.unregister(MAIN_TIMER_ID)
print("Config done, IP is " .. wifi.sta.getip())
dofile("ledserver.lc")
end
end)
我可以在那里做什么?怎么了?
干杯,谢谢!!!
【问题讨论】:
-
相当肯定你不能像那样调用
alarm,因为它不是tmr中的值。它是计时器对象的元方法。 nodemcu.readthedocs.io/en/master/modules/tmr/#tobjalarm