This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Meater BBQ thermometer
#3
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')
Reply


Messages In This Thread
Meater BBQ thermometer - by gjniewenhuijse - 10.03.2024, 16:52
RE: Meater BBQ thermometer - by admin - 11.03.2024, 06:37
RE: Meater BBQ thermometer - by gjniewenhuijse - 11.03.2024, 07:55

Forum Jump: