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?
-
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.. :-) -
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.. :-)@samppa This is very interesting, did you Manage to get this to work? Could you please share?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login