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.

API with Mitsubishi MELCloud for heatingpumps
#4
Here's a working example, it will log all devices from your account.
Code:
email = 'test@test.com' password = '123456' https = require('ssl.https') json = require('json') ltn12 = require('ltn12') function encodepost(t)   local res = {}   local esc = require('socket.url').escape   for k, v in pairs(t) do     res[ #res + 1 ] = esc(k) .. '=' .. esc(v)   end   return table.concat(res, '&') end function login(email, password)   local url = 'https://app.melcloud.com/Mitsubishi.Wifi.Client/Login/ClientLogin'   local data = encodepost({     AppVersion = '1.9.3.0',     Language = '7',     CaptchaChallenge = '',     CaptchaResponse = '',     Persist = 'true',     Email = email,     Password = password,   })   local res, code = https.request(url, data)   if res then     resp = json.pdecode(res)     if type(resp) ~= 'table' then       return nil, 'failed to decode reply data'     elseif resp.ErrorId ~= json.null then       return nil, 'cloud login failed'     else       return resp.LoginData.ContextKey     end   else     return nil, 'login request failed'   end end function getdevices(key)   local url = 'https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices'   local tbl = {}   local res, code = https.request({     url = url,     headers = {       ['X-MitsContextKey'] = key     },     sink = ltn12.sink.table(tbl),   })   if res then     local data = table.concat(tbl)     return json.pdecode(data)   else     return nil, 'get devices request failed'   end end key, err = login(email, password) if key then   items, err = getdevices(key)   if items then     for _, item in ipairs(items) do       local devs = item.Structure.Devices       for _, dev in ipairs(devs) do         log(dev)       end     end   else     log(err)   end else   log(err) end
Reply


Messages In This Thread
RE: API with Mitsubishi MELCloud for heatingpumps - by admin - 12.08.2019, 10:23

Forum Jump: