26.08.2022, 10:38
If you don't have a lot of frequent updates you can use event script to publish new values then disconnect.
Add to Common functions and change username/password:
Event script example:
Add to Common functions and change username/password:
Code:
function mqttpublish(topic, data)
local broker = 'mqtt.eniris.be'
local username = 'xxx'
local password = 'xxx'
local port = 1883
local mqtt = require('mosquitto')
local client = mqtt.new()
if type(data) == 'table' then
data = require('json').encode(data)
end
client.ON_CONNECT = function(status, rc, msg)
if status then
log('mqtt cloud connected')
client:publish(topic, data)
else
log('mqtt cloud connect failed ' .. tostring(msg))
client:disconnect()
end
end
client.ON_PUBLISH = function()
log('disconnecting')
client:disconnect()
end
client:login_set(username, password)
local status, rc, msg = client:connect(broker, port)
if status then
client:loop_forever()
else
log('cloud connect failed: ' .. tostring(msg))
end
end
Event script example:
Code:
topic = 'Actual Temp/Hal A/S2'
data = {
time = os.time(),
extraTags = {
subId = 'T19'
},
fields = {
temperature_degC = event.getvalue()
}
}
mqttpublish(topic, data)