Sunday, February 24, 2013

Here is a simple web remote you can use with your roku player. Chances are that it won't work directly from the blog. Unfortunately blogspot doesn't have a place to add a download link, so right click on the page, select "view source" and save it as a html file on your local disk. And then open the html, also make sure the input IP address provided is correct for your roku device.

Roku Web Remote

Roku IP :

<= Home
^
< Select >
v
Repeat Info
<< >|| >>
Backspace InstantReplay Search

Sunday, February 10, 2013

Communicating with roku box without remote

It is bound to happen ! Some day you will lose your roku remote and start looking for alternatives. I was trying to re-configure my roku box, and happily did a factory reset by pressing the reset button at the back of the box and then realized...oops, I don't have a remote. Now the hunt for remote started which was nowhere to be seen. The next obvious choice to control roku is an iphone or android, but I don't possess any of apple products (because I love my freedom) and my android was with my wife in a foreign country. All I had was a 3 yr old IBM thinkpad with ubuntu 12.10. Thankfully there are two more choices available. Apparently there are couple of ports open by default on roku box (8060 and 8080-8085) through which you can communicate.
All the settings were gone due to factory reset, so had to connect my Roku-XD with an ethernet cable and by logging into the router got the ip address of the device.
Telnet to ipaddr:8080 succeeded first time and by mistake I quit the console, and after that even after repeated attempts I kept getting connection refused. Searching through net I came across a python script which had a GUI to control, but I couldn't get it to work because telnet to port 8080 wasn't succeeding even though I was able to ping the ip address.
Next was to try the HTTP port, tried few commands and they seemed to go through..bingo ! That was all I needed. Next 10 mins. were spent writing a shell script and I had a reasonable command line remote for controlling the roku box.  You can start the below shell script using the command "roku <ipaddr>" on your command line. Without the ipaddr parameter it connects to 192.168.1.66 by default.

I couldn't figure out how to configure wireless using command line, because it just gets stuck once you select the SSID and the http request doesn't return for you to enter the next command.

Below is the shell script, if this post or the shell script below helped you, I would like to know so please drop me a line. And because blogspot won't allow me to upload the script, its in plain text below. Just copy paste it to your local file, change execute permissions (chmod a+x <filename>) and run.

# Simple script to communicate with your roku box.
#Written by Manish Katiyar 
# Date : 2/9/2013

#Enter your roku IP address here
ipaddr=192.168.1.66

[ ! -z "$1" ] && ipaddr=$1

echo "++++++++++++++++++++++++++++++++++++++++++++++"
echo "Sending commands to roku box ($ipaddr)"
echo "++++++++++++++++++++++++++++++++++++++++++++++"


runcmd() {
   wget -O /dev/null --post-data "" "http://$ipaddr:8060/keypress/$cmd" 2> /dev/null
}

help() {
 echo "Command Usage : $0 [ipaddr]"
 echo "Subcommands :"
 printf "\tHome - [Hh]\n"
 printf "\tRev - [Rr]ev\n"
 printf "\tFwd - [Ff]\n"
 printf "\tPlay - [Pp]\n"
 printf "\tSelect - [Ss]\n"
 printf "\tLeft - [Ll]\n"
 printf "\tRight [Rr]\n"
 printf "\tDown - [Dd]\n"
 printf "\tUp - [Uu]\n"
 printf "\tBack - [Bb]\n"
 printf "\tInstantReplay - Ir\n"
 printf "\tInfo - [Ii]nf\n"
 printf "\tBackspace - bs\n"
 printf "\tSearch - srch\n"
 printf "\tEnter - [Ee]\n"
 printf "\tInput - [Ii]\n"
 printf "\tQuit - [Qq]\n"
 printf "\t? help\n"
}

getinput() {
 echo "Enter your phrase below"
 read word
 wordlen=`echo $word|wc -c`
 wordlen=`expr $wordlen - 1`
 for i in `seq 1 $wordlen`
 do
  char=`echo $word|cut -c $i`
  cmd=Lit_$char
  sleep 0.3
  runcmd
done
}

while [ 1 ]
do
    printf "Enter roku command (?) > "
    read a
    case $a in
      [Hh]) cmd=Home && runcmd ;;
      [Rr]ev) cmd=Rev && runcmd ;;
      [Ff]) cmd=Fwd && runcmd ;;
      [Pp]) cmd=Play && runcmd ;;
      [Ss]) cmd=Select && runcmd ;;
      [Ll]) cmd=Left && runcmd ;;
      [Rr]) cmd=Right && runcmd ;;
      [Uu]) cmd=Up && runcmd ;;
      [Dd]) cmd=Down && runcmd ;;
      [Bb]) cmd=Back && runcmd ;;
      [Ii]r]) cmd=InstantReplay && runcmd ;;
      [Ii]nf) cmd=Info && runcmd ;;
      bs) cmd=Backspace && runcmd ;;
      srch) cmd=Search && runcmd ;;
      [Ee]) cmd=Enter && runcmd ;;
      [Ii]) getinput;;
      [Qq]) exit -1;;
      ?) help;;
     esac
done