Haiku Haiku Helper DirecTV control

awvidmer

New Member
Sorry if this is covered elsewhere, but I haven't been able to find an example.

I have an Omnipro connected to a HiFi2 for audio, with multiple sources, including iTunes as well as a DirecTV receiver. Using the example code in the HH documentation (and Omni coding), I've set up a physical switch that turns on the local audio zone, and starts iTunes playing.

I would also like to wake up the DirecTV receiver. This is easily accomplished in a browser with a command that looks something like this (address is static receiver address):

Xxxx://192.168.0.177/remote/commandKey?key=guide

I tried to just add this line to the iTunes Play code in HH, but it gave me a parse error.

I assume sending http commands should be a simple affair here, but I can't seem to figure it out.

Any help is greatly appreciated.
 
Its easiest to define a global function you can reuse:
Code:
function sendHTTPRequest(method, url, reply) {
  var req = new XMLHttpRequest();
  req.open(method, url);
  // Unmark line below if you need authentication (basic)
  //req.setRequestHeader("Authorization", "Basic " + btoa("user:password"));
  req.onreadystatechange = reply
  req.send();
}
then you can reuse this easily from any part of your script:
Code:
sendHTTPRequest("GET", "http://192.168.0.177/remote/commandKey?key=guide");
You can simplify the code if you want by making it always use GET, but this example is meant to be more generally useful. You can also handle the reply by passing in a function as the last parameter.
 
Back
Top