08.07.2024, 09:34
(15.05.2024, 10:03)Daniel Wrote: They support MQTT so you should be good to go. You will need a broker somewhere, if it is locally then you can use LM broker app.
If I put LM and Thingsboard VM under the same Zerotier network, can I use LM MQTT Broker app?
In that case, how I can let TB to send write commands to LM?
Right now I only use a script to send values to TB:
Code:
indirizzo = event.dst
tagEvento = event.tag
--log (event)
--broker = "demo.thingsboard.io"
broker = "xxx.xxx.xxx.xxx"
port = 1883
token = "xxxxxxxxxxxxxxxxxxxxx"
topic = "v1/devices/me/telemetry"
value = event.getvalue()
if value == true then
value = 1
elseif value == false then
value = 0
else
numero = tonumber(value)
if numero ~= nil and numero % 1 ~= 0 then
value = string.format("%.1f", numero)
end
end
value = tostring(value)
old_value = storage.get(indirizzo,"")
if value == old_value then
--log("return")
return
end
storage.set(indirizzo, value)
payload = '{"('..indirizzo..')":' .. value .. '}'
mqtt = require("mosquitto")
client = mqtt.new()
client.ON_CONNECT = function(status, rc, msg)
if status then
--log("mqtt connected: "..payload)
client:publish(topic, tostring(payload))
else
log("mqtt connect failed " .. tostring(msg))
client:disconnect()
end
end
client.ON_PUBLISH = function()
client:disconnect()
end
-- client:login_set(username, password)
client:login_set(token, nil)
status, rc, msg = client:connect(broker, port)
if status then
client:loop_forever()
else
log('connect failed: ' .. tostring(msg))
end
How should be to receive commands?
Thanks a lot!
Peppe