Re: MQTT broken in NodeMCU 0.9.5 build 20150213??
Posted: Mon Feb 16, 2015 2:28 pm
Yes, NodeMCU 0.9.5 build 20150213 MQTT is broken.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
if 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
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....
NodeMCU 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
NodeMCU 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)
>