Difference between revisions of "Controlling DirecTV Set Top Box (STB) via Network"

From MythTV Official Wiki
Jump to: navigation, search
(Created page with '== Summary == Some DirecTV set top boxes now allow certain operations via the DirecTV HTTP Server on port 8080. The H23 is one example. The set top box must be plugged in to t…')
 
Line 15: Line 15:
 
I found that on my Ubuntu installation, I had to install the JSON library using CPAN.  I followed these instructions:
 
I found that on my Ubuntu installation, I had to install the JSON library using CPAN.  I followed these instructions:
  
sudo cpan
+
sudo cpan
install JSON
+
install JSON
exit
+
exit
  
 
'''directv_http.pl'''
 
'''directv_http.pl'''

Revision as of 19:30, 26 October 2010

Summary

Some DirecTV set top boxes now allow certain operations via the DirecTV HTTP Server on port 8080. The H23 is one example. The set top box must be plugged in to the network in order for this to work.

Documentation on the internet is lacking at the moment, but it is possible currently to change the channel and to gather current (tuned) channel information. The attached perl script allows users to change the channel or gather current channel data. The DirecTV set top box always returns data in JSON.

Perl Script

Attached is my first crack at a script. I'm pretty green at perl so this is quite a hack, but it works. The script takes the following arguments:

Always list the IP address of the receiver first.
Next, type "tune" to change the channel, or "getTuned" to display the JSON for the current listing
If you chose "tune", now enter the channel number

I found that on my Ubuntu installation, I had to install the JSON library using CPAN. I followed these instructions:

sudo cpan
install JSON
exit

directv_http.pl

#!/usr/bin/perl
use LWP::UserAgent;
use JSON;

$ua = LWP::UserAgent->new;
$ua->agent("$0/0.1 " . $ua->agent);
# $ua->agent("Mozilla/8.0") # pretend we are very capable browser

# get args
$dtv_ip = $ARGV[0];
$arg = $ARGV[1];
$chan_num = ;
$numArgs = $#ARGV + 1;
$tune = 1;

if($numArgs == 0)
{
    print "(10) Error: no command line arguments\n";
    exit;
}

if($arg eq "getTuned")
{
    $tune = 0;
}
elsif($arg eq "tune")
{
    $chan_num = $ARGV[2];
    $tune = 1;
}
else
{
    print "(20) Error: command line argument invalid\n";
    exit;
}

$url = 'http://'.$dtv_ip.':8080/tv/tune?major='.$chan_num;
if($tune == 0)
{
    $url = 'http://'.$dtv_ip.':8080/tv/getTuned';
}
$req = HTTP::Request->new(GET => $url);
$req->header('Accept' => 'text/html');

# send request
$res = $ua->request($req);

# check the outcome
if ($res->is_success) 
{
    #print $res->content."\n";
    $json = new JSON;
    $json_text = $json->decode($res->content);
    $check_ok = $json_text->{status}->{msg};
    #print "OK? ".$check_ok . "\n";
    if($check_ok eq "OK")
    {
        if($tune == 0)
        {
            print $res->content . "\n";
        }
        exit;
    }
    else
    {
        print "(30) Error: " . $check_ok . "\n";
        exit;
    }
} 
else 
{
    print "(40) Error: " . $res->status_line . "\n";
    exit;
}