24.05.2024, 09:01
"not authorized" error means wrong username and/or password.
This works for me:
This works for me:
Code:
broker = 'mqtt.intingy.com'
port = 1883
username = 'entelechy_gateway'
password = 'wr6NOng8HzFC2KpB5cPoxXXgCSYBHXbGgRG9b3R39ok'
topic = 'entelechy/'
payload = 'mqtt_connection_test'
mqtt = require('mosquitto')
client = mqtt.new()
client.ON_CONNECT = function(status, rc, msg)
if status then
log('mqtt connected')
client:publish(topic, tostring(payload))
else
log('mqtt connect failed ' .. tostring(msg))
client:disconnect()
end
end
client.ON_PUBLISH = function()
log('publish ok')
client:disconnect()
end
client:login_set(username, password)
status, rc, msg = client:connect(broker, port)
if status then
client:loop_forever()
else
log('connect failed: ' .. tostring(msg))
end