(19.07.2023, 13:04)admin Wrote: Try passing username/password like in this example: https://forum.logicmachine.net/showthrea...8#pid26618
Try both username variants - with @ and %40.
Yes that works like a charm
Code:
http = require('socket.http')
mime = require('mime')
json = require('json')
result = http.request({
url = 'http://api.huum.eu/action/home/status',
headers = {
Authorization = 'Basic ' .. mime.b64('username:password')
}
})
data = json.pdecode(result)
log(data)
And now my next question is how to send a JSON POST command?
The url is then: https://api.huum.eu/action/home/start
And the JSON command: {'targetTemperature' : 80}
(19.07.2023, 13:55)Joep Wrote:(19.07.2023, 13:04)admin Wrote: Try passing username/password like in this example: https://forum.logicmachine.net/showthrea...8#pid26618
Try both username variants - with @ and %40.
Yes that works like a charm
Code:http = require('socket.http')
mime = require('mime')
json = require('json')
result = http.request({
url = 'http://api.huum.eu/action/home/status',
headers = {
Authorization = 'Basic ' .. mime.b64('username:password')
}
})
data = json.pdecode(result)
log(data)
And now my next question is how to send a JSON POST command?
The url is then: https://api.huum.eu/action/home/start
And the JSON command: {'targetTemperature' : 80}
I already found the solution.
Code:
function post(url, body)
local ltn12 = require('ltn12')
local http = require('socket.http')
local sink = {}
local res, err = http.request({
url = url,
method = 'POST',
headers = {
['Authorization'] = 'Basic '..(mime.b64('username:password')),
['Content-Length'] = #body,
['Content-Type'] = 'application/json',
},
sink = ltn12.sink.table(sink),
source = ltn12.source.string(body),
})
if res then
return table.concat(sink)
else
return nil, err
end
end
require('json')
url = 'https://api.huum.eu/action/home/start'
body = '{"targetTemperature" : 70}'
result = post(url, body)
data = json.pdecode(result)
log(data)