11.07.2019, 08:41
Use standard MQTT example without encryption. Username is device serial number, password value are device credentials.
This resident script will connect to MQTT and subscribe to status topic. See logs tab for output result.
This resident script will connect to MQTT and subscribe to status topic. See logs tab for output result.
Code:
-- product types
DYSON_PURE_COOL_LINK_TOUR = '475'
DYSON_PURE_COOL_LINK_DESK = '469'
DYSON_PURE_HOT_COOL_LINK_TOUR = '455'
DYSON_360_EYE = 'N223'
broker = '192.168.1.1' -- default port is 1883
username = '...' -- device serial
password = '...' -- device credentials
producttype = DYSON_PURE_HOT_COOL_LINK_TOUR
topic = producttype .. '/' .. username .. '/status'
mqtt = require('mosquitto')
client = mqtt.new()
client.ON_CONNECT = function(status, rc, err)
if status then
log('connect ok')
client:subscribe(topic)
else
log('connect error', rc, err)
end
end
client.ON_MESSAGE = function(mid, topic, data)
log('message', topic, data)
end
client:login_set(username, password)
client:connect(broker)
client:loop_forever()