We have moved at community.getvera.com

Author Topic: HELP Convert Groovy to Lua Heating  (Read 414 times)

Offline Newzwaver

  • Sr. Member
  • ****
  • Posts: 271
  • Karma: +4/-3
HELP Convert Groovy to Lua Heating
« on: March 03, 2017, 07:54:09 am »

I need your help, trying to make a plug in for a thermostat and it uses Groovy so i am hoping to convert the following;
def login() {
    def params = [
        uri: "${data.server}",
        path: 'api/login',
        requestContentType: "application/x-www-form-urlencoded; charset=UTF-8",
        body: ["email": settings.email, "password": settings.password, "stayConnected": "0"]
    requestApi("login", params);
    if (data.auth.error){
       data.error = error(data.auth.error.code)
       sendEvent(name: 'error', value: "${data.error}")
      log.info("login and password :: OK")
       sendEvent(name: 'error', value: "")

I have worked this to the following code taken from another plugin
local HOST = "www.neviweb.com"
local URL_PORTAL = "https://" .. HOST .. "/api/login/,"
 local response, status, header = https.request{
      url = URL_PORTAL,
      method = "POST",
      headers = {
    ["Origin"] = URL_PORTAL,
    ["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8",
    ["Content-Length"] = #theBody,
      source = ltn12.source.string(theBody),
      sink = ltn12.sink.table(auth_response)

Should this not work?  It should send the same message.


Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: HELP Convert Groovy to Lua Heating
« Reply #1 on: March 03, 2017, 08:09:55 am »
Looks about right.  Easiest thing would be to try it out in the Lua Test window.  Does it work there?

You do, of course, have to include the appropriate library module for https.request to work.

3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.