26.08.2022, 10:58
(26.08.2022, 10:38)admin Wrote: 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:
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)
Hello Admin,
Thank you for the quick reply.
Unfortunately I will have to publish around 200 objects and its not that they come in the bus very frequently.
Is there and option to publish data every one minute? Like adding a resident script with sleep internal of 1min?
Regards,