Author Topic: Guidance needed - problem with Includes - encdec/json  (Read 104 times)

Offline WhiteBeard

  • Sr. Newbie
  • *
  • Posts: 49
  • Karma: +1/-0
Guidance needed - problem with Includes - encdec/json
« on: December 07, 2017, 10:29:18 pm »
Disclaimer: I'm not a developer, so please go easy on me :)

I'm looking for a way to get the status of Zipato Zipatile's internal sensors (PIR, Temp, Humidity, etc), which is possible via REST API and MqTT. It is my understanding the MqTT Vera plugin allows publishing only, so that eliminates the MqTT option.

I found a sample REST API LUA code which looks very promising, but it generates the following 2 errors when I run it on Vera:
luup_require can't find encdec
luup_require can't find json


My assumption is that these 2 dependencies are not available on Vera, hence the error? If so, where do I go from there?

Any advise will be greatly appreciated.


I'm posting the entire referenced LUA code below:

Code: [Select]
username = 'user@domain.com'
password = 'pass'
serial = '1234'

https = require('ssl.https')
ltn12 = require('ltn12')
sha1 = require('encdec').sha1
json = require('json')

function dorequest(url, headers)
  local tbl = {}

  local res, err = https.request({
      url = url,
      headers = headers,
      sink = ltn12.sink.table(tbl)
    })

  if res then
    return table.concat(tbl)
  else
    return nil, err
  end
end

res, err = dorequest('https://my.zipato.com/zipato-web/v2/user/init')
log('init', res, err)

if res then
  data = json.decode(res)
  password = sha1(password)
  token = sha1(data.nonce .. password)

  headers = {
    ['accept'] = 'application/json',
    ['cookie'] = 'JSESSIONID=' .. data.jsessionid .. ';',
  }

  url = 'https://my.zipato.com/zipato-web/v2/user/login?token=' .. token .. '&username=' .. username
  res, err = dorequest(url, headers)
  log('login', res, err)

  if res then
    url = 'https://my.zipato.com/zipato-web/v2/box/reboot/' .. serial
    res, err = dorequest(url, headers)
    log('reboot', res, err)
  end
end

Online jswim788

  • Hero Member
  • *****
  • Posts: 550
  • Karma: +30/-2
Re: Guidance needed - problem with Includes - encdec/json
« Reply #1 on: December 07, 2017, 10:43:26 pm »
You can get a json decoder from here: http://dkolf.de/src/dkjson-lua.fsl/home  Upload and change the require to json = require('dkjson').

I've never tried it, but looks like you could get a sha1 encoder here: https://github.com/kikito/sha1.lua

Offline WhiteBeard

  • Sr. Newbie
  • *
  • Posts: 49
  • Karma: +1/-0
Re: Guidance needed - problem with Includes - encdec/json
« Reply #2 on: December 08, 2017, 09:46:10 pm »
Great thanks for this. I'll test it out and report back.