08.12.2017, 11:33
Hi, anyone got a working example on how to connect to mqtt broker in local network?
How should broker ip,port be set?
I can`t find any examples on how to do this. The broker has been tested and from nodered i can publish to it.
-John
How should broker ip,port be set?
I can`t find any examples on how to do this. The broker has been tested and from nodered i can publish to it.
-John
Code:
mqtt = require("mosquitto")
client = mqtt.new()
client.ON_CONNECT = function()
client:publish("world", "hello")
local qos = 1
local retain = true
local mid = client:publish("lm/test/1", "my payload", qos, retain)
end
client.ON_PUBLISH = function()
client:disconnect()
end
broker = 10.85.0.4:1883
client:login_set("user","password")
client:connect(broker)
client:loop_forever()