Is HTTPS request from LUUP code possible?



  • Does anyone know if I can make HTTPS request from luup code with cookie support?
    I would login to my pages on Verisure website and get the alarm status to be used in automation as home/away switch. I can do this successfully with two wget HTTPS calls: 1) login and 2) access status page with cookies that store the session authentication. But no luck so far with luup.

    So can that even be done with lua from a scene with luup code?



  • @hek Do you know who could know if saving the cookies is possible with https POST request in luup code?


  • Admin

    Hmm.. this thread might give you a hint on how to do ssl requests from lua. Setting cookies is just a matter of setting the cookie header.

    http://forum.micasaverde.com/index.php/topic,17627.0.html

    But it will require some hacking to pick up the cookie response from the login request and forward it.



  • Thanks @hek

    I got it working with CURL:

    local pw = 'xxx'
    local un = 'xxx'
    
    --login request
    local url_1 = 'https://mypages.verisure.com/j_spring_security_check?locale=fi_FI'
    local command_1 = "curl -c '/tmp/log/cmh/cookie.txt' -d 'j_username="..un.."&j_password="..pw.." "..url_1
    local f_1 = assert(io.popen(command_1, 'r'))
    local response_1 = assert(f_1:read('*a'))
    f_1:close(f_1)
    luup.log("Verisure login response: "..response_1)
    
    --armed status request
    local url_2 = 'https://mypages.verisure.com/remotecontrol?_=14616968783849'
    local command_2 = "curl -k -b '/tmp/log/cmh/cookie.txt' "..url_2
    local f_2 = assert(io.popen(command_2, 'r'))
    local response_2 = assert(f_2:read('*a'))
    f_2:close(f_2)
    luup.log("Verisure status response: "..response_2)
    

    This returns the alarm status of Verisure system:

    [{"date":"Today 8:47 PM","notAllowedReason":"","name":"Samppa Turunen","changeAllowed":true,"id":1,"label":"Armed stay","type":"ARM_STATE","status":"armedhome"}]
    

    Now I need to parse the response string into a variable.

    Then I could make a device for it to be used as home / away switch.
    What would be the easiest example to start packaging the code into a device file for Vera? This would be my very first handmade device.. 🙂


  • Admin

    I would have a look at one of the existing plugins to get some inspiration... that's how I learned the device file format and "normal" structure of Vera plugins.



  • @samppa This is very interesting, did you Manage to get this to work? Could you please share?


Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 1
  • 2
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts