A Roku box can be externally controlled through a simple, RESTful service accessed via the http protocol on port 8060, see here. The commands I need to perform are sent via a POST with no body. They provide command line curl examples, like:
$ curl -d '' http://192.168.1.134:8060/keypress/home
I need to write this as a PHP script that will execute a series of actions: keypress/home, launch/appid, keypress/select, keypress/right, keypress/right, keypress/select.
See below for what I came up with for one command. Two questions:
1) My Roku is not responding to this, so what am I doing wrong?
2) What's the best way to send multiple POST requests one after the other?
<?php
$ch = curl_init('http://192.168.1.134:8060/keypress/home');
$data = '';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>
I found a better way to do it, client-side with javascript.
<script>
function post1() {
xhr = new XMLHttpRequest();
xhr.onload=function()
{
alert(xhr.responseText);
}
xhr.open("POST", "http://192.168.1.134:8060/keypress/home");
xhr.send();
}
</script>
<body onload="post1()">