This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

mqtt client
#1
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

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()
Reply
#2
Like this, port is optional and defaults to 1883:
Code:
broker = '10.85.0.4'

If you need to set a custom port then pass it as a second parameter to connect:
Code:
client:connect('10.85.0.4', 12345)
Reply


Forum Jump: