-->
Page 8 of 17

Re: MQTT for NodeMCU Lua working NOW

PostPosted: Wed Jan 21, 2015 12:53 pm
by quantalume
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.

Re: MQTT for NodeMCU Lua working NOW

PostPosted: Thu Jan 22, 2015 12:39 pm
by iHaveESP
@tuanpm Thanks for all the work on this!

I'm using the bin at the first post.

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.

Anyone seeing this too?

-Thanks

Re: MQTT for NodeMCU Lua working NOW

PostPosted: Thu Jan 22, 2015 2:34 pm
by axelk
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.


I ran into exactly the same problem - using some "poor man's semaphore" for now. It works quite ok. I also tried to implement a real queue, but then I get frequent reboots because out-of-heap.

Code: Select all-- 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)



I guess what we really need here is
1. some kind of queue in C, using less RAM
2. a more peaceful result of mqtt.publish(), e.g. false/true instead of raising a fatal error

Axel.

Re: MQTT for NodeMCU Lua working NOW

PostPosted: Thu Jan 22, 2015 4:18 pm
by ampakinetic
I'm getting a lot of reboots with the latest MQTT/Lua firmware, especially when the device is acting as a web server.

I have tried several server examples on the MQTT build and they all crash when a connection is made by a client (using the prebuild nodemcu_latest from 5 days ago).

If I revert to the standard pre-build the web server code works well and there are no crashes.