-->
Page 2 of 5

Re: MQTT broken in NodeMCU 0.9.5 build 20150213??

PostPosted: Mon Feb 16, 2015 2:28 pm
by tgmaxx
Yes, NodeMCU 0.9.5 build 20150213 MQTT is broken.

Re: MQTT broken in NodeMCU 0.9.5 build 20150213??

PostPosted: Mon Feb 16, 2015 5:38 pm
by kayakpete
That code does not work on build 20150213 but does work on 20150217.

Re: MQTT broken in NodeMCU 0.9.5 build 20150213??

PostPosted: Tue Feb 17, 2015 3:27 am
by Mehrius
I had the same problem. The problem is that, if loaded after boot through init.lua, the process is too fast and the chip is not connected to wifi when the script tries to publish or subscribe.

I fixed it by delaying the dofile in init.lua until the wifi.sta.status is 5. This is what my init.lua looks like and it works quite well.

Code: Select allif wifi.sta.status() ~= 5 then tmr.alarm(6, 10000,0, function(d) dofile('init.lua') end) return end
if wifi.sta.status() == 5 then dofile('mqtt.lua') return end


Hope this works for you....

Re: MQTT broken in NodeMCU 0.9.5 build 20150213??

PostPosted: Tue Feb 17, 2015 5:10 pm
by quantalume
Mehrius wrote:I had the same problem. The problem is that, if loaded after boot through init.lua, the process is too fast and the chip is not connected to wifi when the script tries to publish or subscribe.

I fixed it by delaying the dofile in init.lua until the wifi.sta.status is 5. This is what my init.lua looks like and it works quite well.

Code: Select allif wifi.sta.status() ~= 5 then tmr.alarm(6, 10000,0, function(d) dofile('init.lua') end) return end
if wifi.sta.status() == 5 then dofile('mqtt.lua') return end


Hope this works for you....


I'm just trying to connect manually by sending commands in a terminal. It all works fine with 20150127:
Code: Select allNodeMCU 0.9.5 build 20150127  powered by Lua 5.1.4
lua: cannot open init.lua
> print(wifi.sta.getip())
192.168.0.47   255.255.255.0   192.168.0.1
> m = mqtt.Client('garage_sens', 120) --, "user", "password")
> m:connect("192.168.1.100", 1883, 0, function(conn) print("connected") end)
> connected


Then I flash 20150212 and try again:
Code: Select allNodeMCU 0.9.5 build 20150212  powered by Lua 5.1.4
lua: cannot open init.lua
> print(wifi.sta.getip())
192.168.0.47   255.255.255.0   192.168.0.1
> m = mqtt.Client('garage_sens', 120) --, "user", "password")
> m:connect("192.168.1.100", 1883, 0, function(conn) print("connected") end)
>


It never returns "connected."