Making PowerHome send C2DM Messages to your Android Phone

 

This page describes how to make PowerHome send GCM notifications for you. As we tested in the GCM settings page, we can enter a url in a web browser and that will send a GCM message to your phone. In this section, all we are doing is make PowerHome call that same url that you were entering in the address bar of the web browser.

First make sure that your phone is getting GCM messages as described in the GCM settings page. If your phone is getting the messages, then the next step is to make PowerHome send those messages.

To get started, set a PowerHome global variable with the server name a username & password
PHCA_SERVER=”https://phca-web.appspot.com/send?username=myusername&password=mypassword&”

Then you can send a message with the following macro:

ph_geturl1("{PHCA_SERVER}garagedoor=open&anothervariablename=thevariablevalue",1,20)

Note the change with removing the verbose=true from the testing page. Feel free to use the verbose=true for troubleshooting, but for production use it would be best to leave that option off. Create two PowerHome global variables, PHCA_USER and PHCA_PASS and set them equal to your phc-a.net username and password. Then run the macro by right-clicking on the macro detail and choosing “Play”. If that works, you are good to go. You can insert a line like that in any macro so that it executes when something interesting happens. One thing to keep in mind is that the entire url has to be properly escaped. So if your username, password or variable value has any special characters like spaces or quotes, you will have to html escape the url before executing. Fortunately, PowerHome comes with a command to do this for you. Therefore, the command above will become (shown on multiple lines for display purposes only. This command should be entered as a single line into PowerHome)

ph_geturl1("{PHCA_SERVER}cloudpushtest="
   +ph_htmlescape("PHCA is the coolest app for PowerHome!!"),1,20)

Note that as of PowerHome version 2.1.4, urls are not properly escaped when they contain carriage returns or tabs. The implication is that you cannot update a variable value with a value that contain one of those characters. This should be fixed in a new release very soon!

 Posted by at 2:38 pm

Leave a Reply