Author |
|
MrGibbage Super User
Joined: October 23 2006 Location: United States
Online Status: Offline Posts: 513
|
Posted: August 30 2011 at 06:43 | IP Logged
|
|
|
I was wondering if it would be possible to control PH with simple http post and get
commands? I guess there would have to be some sort of authentication built into the
url as well, such as an api key or something? Something like
http://myPHwebServer?getGarageDoorStatus&apiKey=###
http://myPHwebServer?runMacro=lightsOff&apiKey=###
http://myPHwebServer?getGlobalVarValue&apiKey=###
http://myPHwebServer?setGlobalVarValue=someValue&apiKey=###
I think something like this would really open some doors for people building custom
interfaces to PH.
__________________ Skip
|
Back to Top |
|
|
JaredM Newbie
Joined: November 04 2007
Online Status: Offline Posts: 36
|
Posted: August 31 2011 at 22:04 | IP Logged
|
|
|
Yep, this is doable today using the PH Web Server. For example, via GET:
http://myPHwebServer/ph-cgi/formula?formula=ph_macro('lights Off')
Or do a POST to /ph-cgi/eval and send "formula=..." in the request body.
As for authentication, you can use basic auth, where the username+password is sent (with minor obfuscation) in the request header. I remember reading something about also being able to auth using a cookie but am not sure exactly how to configure that. A 3rd option, should you be so inclined, is no authentication at all. You can accomplish this my adding the IP address to the Trusted IPs list on the Web settings page.
|
Back to Top |
|
|
MrGibbage Super User
Joined: October 23 2006 Location: United States
Online Status: Offline Posts: 513
|
Posted: September 01 2011 at 06:28 | IP Logged
|
|
|
That's awesome. I am writing an android application to
interface with PH, and this will help out a lot.
Is there more documentation for the ph-cgi funtionality?
Thanks for the help.
__________________ Skip
|
Back to Top |
|
|
JaredM Newbie
Joined: November 04 2007
Online Status: Offline Posts: 36
|
Posted: September 03 2011 at 22:16 | IP Logged
|
|
|
In PH Explorer::Setup::Web you can get a look at some other built-in webpages, like /ph-cgi/directsql. I have a Windows Phone 7 app (on my phone, not published) and I use /ph-cgi/eval for everything. Since you can send as long a formula as you want, I've found it the most flexible way to communicate remotely.
This thread talks about /ph-cgi/evalformula which sounds like it does the samething as eval but after executing your code redirects to a url you specify.
One problem you might run in to: don't forget to URL Encode the data (forumla) you send. When in doubt check PH's event log to see that it received what you intended to send.
|
Back to Top |
|
|
kev21986 Senior Member
Joined: April 04 2007 Location: United States
Online Status: Offline Posts: 199
|
Posted: November 21 2011 at 08:31 | IP Logged
|
|
|
From my testing the socket server responds much faster than the http
server. If you are writing an app I would recommend using sockets. There is
next to no information on how it works but I have pieced it together a
node.js module to communicate with PH.
https://github.com/respectTheCode/ctrlHome/blob/master/libs/ ph.js
__________________ Kevin Smith
@respectTheCode
|
Back to Top |
|
|
MrGibbage Super User
Joined: October 23 2006 Location: United States
Online Status: Offline Posts: 513
|
Posted: November 21 2011 at 08:34 | IP Logged
|
|
|
Yes, I agree. The socket server is much faster. I give the
users the choice of using http or the socket server.
__________________ Skip
|
Back to Top |
|
|
kev21986 Senior Member
Joined: April 04 2007 Location: United States
Online Status: Offline Posts: 199
|
Posted: November 21 2011 at 08:38 | IP Logged
|
|
|
Any chance you have figured out how to get the UDP stuff to work? I would
love to get status updates pushed from PH without creating triggers.
__________________ Kevin Smith
@respectTheCode
|
Back to Top |
|
|
MrGibbage Super User
Joined: October 23 2006 Location: United States
Online Status: Offline Posts: 513
|
Posted: November 21 2011 at 08:45 | IP Logged
|
|
|
No, I didn't need to use UDP. The way my app works I didn't need it. I require
the users to put statements in their macros that send updates directly to their
phones. At least the phone doesn't have to poll for updates. But if a user wants
to poll for an update, they have that option too with my app.
__________________ Skip
|
Back to Top |
|
|