Logic Machine Forum
Meater BBQ thermometer - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Meater BBQ thermometer (/showthread.php?tid=5295)



Meater BBQ thermometer - gjniewenhuijse - 10.03.2024

Hello,

I read  GitHub - apption-labs/meater-cloud-public-rest-api: MEATER Cloud REST API documentation. 

But i don't know how to get the data from that cloud thermometer. Anyone done this before?


RE: Meater BBQ thermometer - admin - 11.03.2024

There are many similar examples with REST communication on the forum: https://forum.logicmachine.net/showthread.php?tid=3756&pid=26977#pid26977


RE: Meater BBQ thermometer - gjniewenhuijse - 11.03.2024

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')