05.10.2024, 09:18
(This post was last modified: 05.10.2024, 09:18 by CristianAgata.)
(05.10.2024, 08:49)toujour Wrote: Hi,Hi toujour,
what is the better way to send some JSON values to a REST server ?
Something about this ?
https = require('ssl.https')
url = 'http://IP_MACHINE/url'
body = [[{
"timestamp": NOW(),
"meter": grp.getvalue('32/2/4')
}]]
resp = {}
res, code, hdrs, stat = https.request({
url = url,
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
['Content-Length'] = #body,
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(resp),
})
resp = table.concat(resp)
log(res, code, hdrs, stat, resp)
How can I use NOW() and grp.getvalue inside of the JSON ?
try to add this:
Code:
require('json')
ora = os.time()
value = grp.getvalue('your_group_address')
body = json.encode({
timestamp = ora,
meter = value,
})
log (body)
best regards Cristian