Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
hi, I would use the platform Thingsboard.io to send and collect value data from LM objects.
they allows to do it by 2 ways:
HTTP request ( es. curl -v -X POST http://demo.thingsboard.io/api/v1/eoKkkZ.../telemetry --header Content-Type:application/json --data "{temperature:25}") or
MQTT (es. curl -v -X POST http://demo.thingsboard.io/api/v1/eoKkkZ.../telemetry --header Content-Type:application/json --data "{temperature:25}")
how could I implement everything on LM?
Thanks in advance
Peppe
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
For HTTP use this:
Code: require('json')
require('ltn12')
require('socket.http')
body = json.encode({ temperature = 25 })
response = {}
res, code = socket.http.request({
url = 'http://demo.thingsboard.io/api/v1/eoKkkZ6JL7UbmyOHGX9L/telemetry',
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
['Content-Length'] = #body,
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(response),
})
if res and code == 200 then
log('request ok')
else
log('request error', code, table.concat(response))
end
For MQTT search the forum, there are many examples of how to use it. The data must be encoded using JSON, same as for HTTP requests.
Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
(22.11.2023, 11:12)admin Wrote: For HTTP use this:
Code: require('json')
require('ltn12')
require('socket.http')
body = json.encode({ temperature = 25 })
response = {}
res, code = socket.http.request({
url = 'http://demo.thingsboard.io/api/v1/eoKkkZ6JL7UbmyOHGX9L/telemetry',
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
['Content-Length'] = #body,
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(response),
})
if res and code == 200 then
log('request ok')
else
log('request error', code, table.concat(response))
end
For MQTT search the forum, there are many examples of how to use it. The data must be encoded using JSON, same as for HTTP requests.
Thank you. How to pass a object value?
Code: value = grp.getvalue('4/1/11')
body = json.encode({ temperature = value })
That way doesn't work. What is correct syntax?
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
The syntax is correct, for event scripts use event.getvalue() instead of grp.getvalue().
What kind of error are you getting?
Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
(22.11.2023, 13:38)admin Wrote: The syntax is correct, for event scripts use event.getvalue() instead of grp.getvalue().
What kind of error are you getting?
No errors, sorry. It's all right now.
Thanks
Peppe
Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
(22.11.2023, 11:12)admin Wrote: For HTTP use this:
Code: require('json')
require('ltn12')
require('socket.http')
body = json.encode({ temperature = 25 })
response = {}
res, code = socket.http.request({
url = 'http://demo.thingsboard.io/api/v1/eoKkkZ6JL7UbmyOHGX9L/telemetry',
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
['Content-Length'] = #body,
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(response),
})
if res and code == 200 then
log('request ok')
else
log('request error', code, table.concat(response))
end
For MQTT search the forum, there are many examples of how to use it. The data must be encoded using JSON, same as for HTTP requests.
I am trying to provision an object in mqtt. Thingsboard says me to execute the command:
Code: mosquitto_pub -d -q 1 -h demo.thingsboard.io -p 1883 -t v1/devices/me/telemetry -u "gximaxia" -P "12345678" -m "{temperature:25}"
How I can arrange it via script?
I need send data of dozen of knx objects, how I can do it without give different username and password? What is the short/best way to do it?
Thanks
Peppe
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
Hi,
I would like to implement the so-called Thingsboard.io Server-side RPC ( https://thingsboard.io/docs/pe/user-guide/rpc/) to send simple commands to KNX objects (e.g. on/off, set temperature, etc.).
is it possible? How I can do?
Thanks in advance
Peppe
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
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.
------------------------------
Ctrl+F5
Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
(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.
What do you mean for "locally"? Thingsboard is on a VM in the cloud... is LM Broker app ok for this? Can you give me please some basic advice how to use it?
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
If it is in the cloud then you need broker in the cloud. Our broker app wont work.
------------------------------
Ctrl+F5
Posts: 270
Threads: 72
Joined: May 2017
Reputation:
0
(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
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
It should work. See here for LM MQTT client script.
https://kb.logicmachine.net/integration/mqtt-client/
There are many more examples on the forum.
------------------------------
Ctrl+F5
|