Re: MQTT for NodeMCU Lua working NOW
Posted: Wed Jan 21, 2015 12:53 pm
Has anyone else noticed that node.restart() fails under certain conditions? I think the problem only occurs with the MQTT branch of the NodeMCU firmware.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
iHaveESP wrote:I'm publishing dht temperature data every 45 seconds using a timer. I also have a PIR sensor that is interrupt driven to publish as well. At times they attempt to publish at the same time and I get "unprotected error in call to Lua API (pir.lua:34: sending in process)" and the module reboots.
I've added a flag to skip publishing dht data in favor of PIR motion, it helps, but reboot still happens. Seems like there should be a queue or something.
-- publish status
function pub()
sub=nil -- don't need than any more
if inpub then
tmr.alarm(4, 50, 0, pub)
return
end
inpub = true
m:publish("e44/conf/light/table/status", lsoft, 0, 1, function()
m:publish("e44/conf/light/room/status", lhard, 0, 1, function()
m:publish("e44/conf/light/shelf/status", lstudent, 0, 1, function()
m:publish("e44/conf/temp/status", temp, 0, 0, function()
print("PUB OK ", node.heap())
inpub = false
end)
end)
end)
end)
end
-- publish button pressed
function button()
if inpub then
tmr.alarm(3, 60, 0, button)
return
end
inpub = true
m:publish("e44/conf/buttons/0", "1", 0, 0, function()
inpub = false
end)
end
inpub = false
tmr.alarm(0,1000,1,pub)
-- int on GPIO0 down
gpio.mode(3, gpio.INPUT, gpio.PULLUP)
gpio.trig(3, "down", function(level)
button()
end)