In terms of the node I`ve tried the test and example code posted herehttp://www.esp8266.com/viewtopic.php?f=19&t=1278
-- init mqtt client with keepalive timer 120sec
m = mqtt.Client(wifi.sta.getmac(), 120, Bakery229, electronics229)
-- Broker will publish a message with qos = 0, retain = 0, data = "offline"
-- to topic "/lwt" if client don't send keepalive packet
m:lwt("/lwt", "offline", 0, 0)
print("lwt went through" )
m:on("connect", function(con) print ("connected") end)
print("m:on connect went through" )
m:on("offline", function(con) print ("offline") end)
print("m:on offline went through" )
-- on publish message receive event
m:on("message", function(conn, topic, data)
print(topic .. ":" )
if data ~= nil then
print(data)
end
end)
-- for secure: m:connect("192.168.0.102", 1883, 1)
m:connect("192.168.0.102", 1883, 0, function(conn) print("connected") end)
-- subscribe topic with qos = 0
m:subscribe("/test",0, function(conn) print("subscribe success") end)
-- publish a message with data = hello, QoS = 0, retain = 0
m:publish("/test","hello",0,0, function(conn) print("sent") end)
m:close();
-- you can call m:connect againHere's my output:
> dofile("test270515.lua")
lwt went through
m:on connect went through
m:on offline went through
test270515.lua:21: not connected
> offline
In terms of R.Pi
I'm running two separate terminal windows one running a subscribing mosquittto line, and another publishing
mosquitto_sub -h 192.168.0.102 -p 1883 -t /#
while true; do mosquitto_pub -h 192.168.0.102 -p 1883 -t /test -m Hi; done
I'm getting the message sent through to the other terminal, however nothing for the NodeMCU
Thanks again if you're willing to help