09.04.2019, 08:21
(09.04.2019, 07:16)admin Wrote: You can use event script to publish and disconnect after publish, like in this post: https://forum.logicmachine.net/showthread.php?tid=1793
Use json.encode to create your data string instead of creating JSON string manually.
This code will publish once connected and disconnect once publish is done.
Code:client.ON_CONNECT = function(stat, code, err)
if stat then
client:publish('devices/' .. device_id .. '/messages/events/', data)
else
log('mqtt connect error', err, code)
end
end
client.ON_PUBLISH = function()
client:disconnect()
running = false
end
Thanks! I will give it a try.