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.

Python code to LUA
#6
Use this. Make sure you have the latest firmware as requests in such format won't work on older versions.
Change unitid, username, password as needed. unitid is the ID that you see when opening the status page (https://pool.aseko.com/XYZ/data/actual). Sometimes the login fails with gateway timeout, just run the script again if it happens.

Code:
json = require('json')
http = require('socket.http')

unitid = '1234'
username = 'user@example.com'
password = 'password'

body = json.encode({
  username = username,
  password = password,
  agree = 'on'
})

resp, code, hdrs, stat = http.request({
  url = 'https://pool.aseko.com/api/login',
  method = 'POST',
  headers = {
    ['Content-Type'] = 'application/json',
    ['Content-Length'] = #body,
  },
  body = body
})

setcookie = hdrs['set-cookie'] or ''
cookie = setcookie:split(';')[1]

if not cookie then
  log('login failed', resp)
  return
end

resp, code, hdrs, stat = http.request({
  url = 'https://pool.aseko.com/api/units/' .. unitid,
  method = 'GET',
  headers = {
    ['Cookie'] = cookie
  }
})

data = json.pdecode(resp)
if type(data) ~= 'table' then
  log('data request failed', resp)
  return
end

values = {}

for _, var in ipairs(data.variables) do
  values[ var.type ] = var.currentValue
end

grp.checkupdate('1/1/1', values.rx)
grp.checkupdate('1/1/2', values.waterTemp)
grp.checkupdate('1/1/3', values.ph)
Reply


Messages In This Thread
Python code to LUA - by bednarekluc - 16.02.2023, 17:16
RE: Python code to LUA - by Batko - 16.02.2023, 19:01
RE: Python code to LUA - by bednarekluc - 16.02.2023, 19:05
RE: Python code to LUA - by admin - 17.02.2023, 08:26
RE: Python code to LUA - by bednarekluc - 17.02.2023, 08:57
RE: Python code to LUA - by admin - 17.02.2023, 09:14
RE: Python code to LUA - by bednarekluc - 17.02.2023, 09:30
RE: Python code to LUA - by admin - 17.02.2023, 09:38
RE: Python code to LUA - by bednarekluc - 17.02.2023, 10:09

Forum Jump: