As the title says... Chat on...

User avatar
By Mehrius
#9994 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....
User avatar
By quantalume
#10060
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."