Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Control PH with http post & get? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: August 30 2011 at 06:43 | IP Logged Quote MrGibbage

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 View MrGibbage's Profile Search for other posts by MrGibbage
 
JaredM
Newbie
Newbie


Joined: November 04 2007
Online Status: Offline
Posts: 36
Posted: August 31 2011 at 22:04 | IP Logged Quote JaredM

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 View JaredM's Profile Search for other posts by JaredM
 
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: September 01 2011 at 06:28 | IP Logged Quote MrGibbage

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 View MrGibbage's Profile Search for other posts by MrGibbage
 
JaredM
Newbie
Newbie


Joined: November 04 2007
Online Status: Offline
Posts: 36
Posted: September 03 2011 at 22:16 | IP Logged Quote JaredM

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 View JaredM's Profile Search for other posts by JaredM
 
kev21986
Senior Member
Senior Member
Avatar

Joined: April 04 2007
Location: United States
Online Status: Offline
Posts: 199
Posted: November 21 2011 at 08:31 | IP Logged Quote kev21986

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 View kev21986's Profile Search for other posts by kev21986 Visit kev21986's Homepage
 
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: November 21 2011 at 08:34 | IP Logged Quote MrGibbage

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 View MrGibbage's Profile Search for other posts by MrGibbage
 
kev21986
Senior Member
Senior Member
Avatar

Joined: April 04 2007
Location: United States
Online Status: Offline
Posts: 199
Posted: November 21 2011 at 08:38 | IP Logged Quote kev21986

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 View kev21986's Profile Search for other posts by kev21986 Visit kev21986's Homepage
 
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: November 21 2011 at 08:45 | IP Logged Quote MrGibbage

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 View MrGibbage's Profile Search for other posts by MrGibbage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum