11.03.2024, 07:55
(This post was last modified: 11.03.2024, 07:57 by gjniewenhuijse.)
Here my first version
Code:
--[[
https://github.com/apption-labs/meater-cloud-public-rest-api
Rate limit:
Recommended: 2 requests per 60 seconds.
Maximum: 60 requests per 60 seconds.
There may be a delay between the MEATER Cloud seeing your device and it being returned in this endpoint.
- Device must be seen by the MEATER Cloud. Ensure you've completed a cook while connected to MEATER Cloud.
- The MEATER app or Block must have an active Bluetooth connection with the device.
- The MEATER app or Block must have an active MEATER Cloud connection.
--]]
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
iDebug = false
cloudUrl = 'https://public-api.cloud.meater.com/v1'
cloudEmail = 'myemail@address.nl'
cloudPwd = 'mypassword'
-- get token
function getToken()
tbl = {}
local iData = {}
iData['email'] = cloudEmail
iData['password'] = cloudPwd
local iData = json.encode(iData)
res, code = https.request({
url = cloudUrl..'/login',
method = 'POST',
headers = {
['content-type'] = 'application/json',
['content-length'] = #iData,
},
source = ltn12.source.string(iData),
sink = ltn12.sink.table(tbl),
})
if iDebug then log(res, code) end
if res and code == 200 then
resp = table.concat(tbl)
resp = json.pdecode(resp)
return resp.data.token
end
end
-- get device(s)
function getData(iEndpoint)
vToken = getToken()
if vToken then
res, code = https.request({
url = cloudUrl..iEndpoint,
method = 'GET',
headers = {
['authorization'] = 'Bearer ' .. vToken
}
})
if iDebug then log(res, code) end
if res and code == 200 then
return res
else
log(res,code)
end
end
end
log(getData('/devices'))
--getData('/devices/DEVICEID')