SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Github Development

Notices

SageTV Github Development Discussion related to SageTV Open Source Development. Use this forum for development topics about the Open Source versions of SageTV, hosted on Github.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-07-2015, 01:37 AM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
External tuning command in SageTV V9 Linux

I want to control my DirecTV Genie HR44 by using http calls to the STB. It looks like they disabled "/tv/tune?major=", but "/remote/processKey?key=" still seems to work.

I can send "remote keys" to the STB by simply doing:
Code:
curl 192.168.1.79:8080/remote/processKey?key=$key
I'm just having trouble finding anything for the Linux version of SageTV to call a script to change the channel. Does anyone know of a way to do this with SageTV v9 Linux?


EDIT:
/tv/tune?major=$channel_number works via curl, but not firefox

Last edited by turak; 11-08-2015 at 12:36 AM.
Reply With Quote
  #2  
Old 11-07-2015, 10:56 AM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
I've written this quick perl script to change channels. It's a work in progress, but it seems to work well. I just need to figure out how to get sage to call it.

I can change to channel 33 by running: /opt/sagetv/server/curl_remote.pl 0033


Here is my script:
Code:
root@banshee:/opt/sagetv/server# cat curl_remote.pl
#!/usr/bin/perl

use strict;

my $stb_ip = '192.168.1.79';
my $log = '/var/log/curl_remote.log';
my $param = shift;

&parse_input( $param );

sub parse_input()
{
  my $keys = shift;
  chomp $keys;
  &logit( "$keys" );
  foreach my $char ( split //, $keys )
  {
    if ( $char =~ /\d/ )
    {
      print "Char = $char \n";
      open ( CURL, "curl $stb_ip:8080/remote/processKey?key=$char |" );
        while (<CURL>)
        {
          my $output = $_;
          chomp $output;
          &logit( $output );
        }
    }
  }
}

sub logit()
{
  my $message = shift;
  my $timestamp = &getLoggingTime();
  open ( LOG, ">> $log" );
  print LOG "[$timestamp]\t$message\n";
  close LOG;
}


sub getLoggingTime()
{

  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
  my $nice_timestamp = sprintf ( "%04d%02d%02d %02d:%02d:%02d",
                                   $year+1900,$mon+1,$mday,$hour,$min,$sec);
  return $nice_timestamp;
}

root@banshee:/opt/sagetv/server#
Reply With Quote
  #3  
Old 11-07-2015, 11:04 AM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Quote:
Originally Posted by turak View Post
It looks like they disabled "/tv/tune?major=", but "/remote/processKey?key=" still seems to work.
Actually... It looks like curl 192.168.1.79:8080/tv/tune?major=202&minor=65535 works, but you have to include a minor.


EDIT:
I was wrong. You don't need the minor. It just wasn't working when I plugged it into firefox. It works fine if I use curl instead.

Last edited by turak; 11-08-2015 at 12:38 AM.
Reply With Quote
  #4  
Old 11-07-2015, 11:05 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,584
I use GenTuner on linux to change channels (not to directtv, but to some other stb)

https://github.com/jwittkoski/GenericTunerPlugin

It's a SageTV tuner plugin that delegates the actual "tuning" to command/script.
Reply With Quote
  #5  
Old 11-07-2015, 11:18 AM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Thanks.. I was just playing with your old ExternalCommandTunerPlugin-1.5.zip
Reply With Quote
  #6  
Old 11-07-2015, 04:19 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
OK. I've modified my script to work with gentune. I just need to figure out how to get SageTV to load the GenericTunerPlugin.so that I copied to the irtunerplugins directory.



Code:
#!/usr/bin/perl

#  This script controls my DirecTV Genie (hr44) STB.  Just update the IP addess 
#  below and you should be good to go.  You can also turn off debug if you don't
#  want the script to write to a log file.  You can get a list of mini's with the
#  get_clients argument.  Set your genie's IP below and run "tune.pl get_clients"
#  to list the address if your clients.


use strict;




#  List your STB's and IP addresses below.  Use 'xxx.xxx.xxx.xxx|MacAddrOfClient'
#  for mini's. Feel free to comment out and tuners that you don't need.

my %stbs = (
	'DirecTV-Tuner-1' => '192.168.2.243',
	'DirecTV-Tuner-2' => '192.168.2.243|2C088C089B22',
#	'DirecTV-Tuner-3' => '192.168.1.79',
);

my $log = 'c:\TuneChannel\tune.log';   	#  Location of logfile.
#my $log = '/var/log/tune.log';   		#  Location of logfile Linux.

my $debug = 1;  			#  Set to 1 to turn logging on.
					#  Set to 0 to turn logging off.

my $micro_send = 0;   		        #  Set to 1 to send one digit at a time
					#  to the STB instead of the whole channel.
					#  Set to 0 to send the whole channel number.


my $command = $ARGV[0];
my $remote = $ARGV[1];
my $channel = $ARGV[2];


&logit( "Received COMMAND = $command | REMOTE = $remote | CHANNEL = $channel" );
&get_clients if ( $command eq "get_clients" );
&list_keys if ( $command eq "KEYS" );
&send_keys( $channel ) if ( $command eq "TUNE" );
&list_tuners if ( $command eq "REMOTES" );
print "OK\n" if ( $command eq "CAN_TUNE" );


sub list_tuners()
{
  foreach my $tuner ( keys %stbs )
  {
    print $tuner . "\n";
  }
}

sub get_clients()
{
  my ( $ip_addr, $client_addr );
  foreach my $key ( keys %stbs )
  {  
    ( $ip_addr, $client_addr ) = split ( /\|/, $stbs{$key} );
    if ( $client_addr eq '' )
	{
	  open ( CURL, "curl -s $ip_addr:8080/info/getLocations |" );
	  while (<CURL>)
	  {
	    my $output = $_;
	    print $output;
  	    chomp $output;
	    &logit( $output );
      }
	  close CURL;
    }
  }
}

sub list_keys()
{
  my @keys = (
	'1', '2', '3', '4',
	'5', '6', '7', '8',
	'9', '0', 'OK'
	     );

  foreach ( @keys )
  {
    print "$_\n";
  }
}
	
sub send_keys()
{
  my ( $ip_addr, $client_addr );
  my $keys = shift;
  chomp $keys;
  &logit( "$keys" );
  ( $ip_addr, $client_addr ) = split ( /\|/, $stbs{$remote} );
  $client_addr = '&clientAddr=' . $client_addr if ( $client_addr ne '' );
  open ( CURL, "curl -s $ip_addr:8080/remote/processKey?key=poweron$client_addr |" );
    while (<CURL>)
    {
      my $output = $_;
      chomp $output;
      &logit( $output );
    }

  if ( $micro_send )
  {
    foreach my $char ( split //, $keys ) 
    {
      if ( $char =~ /\d/ ) 
      {
        open ( CURL, "curl -s $ip_addr:8080/remote/processKey?key=$char$client_addr |" );
        while (<CURL>) 
        {
          my $output = $_;
          chomp $output;
          &logit( $output );
        }
      }
    }
  } else {
    open ( CURL, "curl -s $ip_addr:8080/tv/tune?major=$channel$client_addr |" );
    while (<CURL>)
    {
      my $output = $_;
      chomp $output;
      &logit( $output );
    }
  }
}

sub logit()
{
  my $message = shift;
  my $timestamp = &getLoggingTime();
  if ( $debug ) 
  {
    open ( LOG, ">> $log" );
    print LOG "[$timestamp]\t$message\n";
    close LOG;
  }
}


sub getLoggingTime() 
{

  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
  my $nice_timestamp = sprintf ( "%04d%02d%02d %02d:%02d:%02d",
                                   $year+1900,$mon+1,$mday,$hour,$min,$sec);
  return $nice_timestamp;
}

Updated to support Genie mini clients.

Last edited by turak; 08-17-2018 at 03:28 PM.
Reply With Quote
  #7  
Old 11-07-2015, 05:22 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
I figured out why GenericTunerPlugin.so wasn't loading. I had to recompile it as a 64bit object since I'm running 64bit SageTV.

In Makefile change:
CFLAGS = -m32 -fPIC -D_FILE_OFFSET_BITS=64

To:
CFLAGS = -m64 -fPIC -D_FILE_OFFSET_BITS=64
Reply With Quote
  #8  
Old 11-07-2015, 05:40 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Except that SageTV Server core dumps when I select "Generic Tuner" with nothing in the logs. I was tailing sagetv_0.txt when it dumped it's core and nothing got logged.


./startsagecore: line 48: 11778 Aborted (core dumped) java -Djava.awt.headless=$HEADLESS $JAVAMEM -XX:+UseAdaptiveSizePolicy -XX:MaxGCPauseMillis=25 -XX:GCTimeRatio=24 -XX:ThreadPriorityPolicy=1 $JAVAOPTS -cp Sage.jar:.:/:$(echo JARs/*.jar | sed 's/ **/:/g') sage.Sage 0 0 x "sagetv Sage.properties" 0>&-
Reply With Quote
  #9  
Old 11-07-2015, 06:03 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Sage blows up every time I select Generic Tuner. hs_err log attached. I don't really know how to debug this.


hs_err_pid16042.log.txt
Reply With Quote
  #10  
Old 11-07-2015, 07:49 PM
Slugger Slugger is offline
SageTVaholic
 
Join Date: Mar 2007
Location: Kingston, ON
Posts: 4,008
Likely the native code needs some tweaks to work as a 64bit library. Most C/C++ code written for 32bit systems won't play so nice if just compiled to 64bit unless you make it 64bit compatible. The change in pointer sizes and integer sizes is usually why code goes boom when compiled to 64bit. Successfully compiled != correct, especially if it compiled successfully, but with warnings.
__________________
Twitter: @ddb_db
Server: Intel i5-4570 Quad Core, 16GB RAM, 1 x 128GB OS SSD (Win7 Pro x64 SP1), 1 x 2TB media drive
Capture: 2 x Colossus
STB Controller: 1 x USB-UIRT
Software:Java 1.7.0_71; SageTV 7.1.9
Clients: 1 x HD300, 2 x HD200, 1 x SageClient, 1 x PlaceShifter
Plugins: Too many to list now...
Reply With Quote
  #11  
Old 11-07-2015, 08:03 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
There weren't any warnings, but then the Makefile didn't have any warning flags.
Reply With Quote
  #12  
Old 11-07-2015, 09:39 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Quote:
Originally Posted by Slugger View Post
Likely the native code needs some tweaks to work as a 64bit library. Most C/C++ code written for 32bit systems won't play so nice if just compiled to 64bit unless you make it 64bit compatible. The change in pointer sizes and integer sizes is usually why code goes boom when compiled to 64bit. Successfully compiled != correct, especially if it compiled successfully, but with warnings.

I suppose you are correct. The source code probably isn't 64bit clean. I don't suppose anyone wants to comb through 400ish lines of C code to port it to 64bit?

Are there any other options for calling an external script to handle channel tuning?
Reply With Quote
  #13  
Old 11-08-2015, 06:36 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,584
I looked at the source code, and there is very little that I can see that would be affected by 64bit.

If you checkout my repo...
https://github.com/stuckless/GenericTunerPlugin

I've added a TestTuner executable... basically it links about the GenericTunerPlugin.o and then calls OpenDevice, MacroTuner, etc. That can be used to verify if GenTuner is working on your system. You can probably modify the TestTuner to have it send a "real" channel, current, I'm sending 256.
Reply With Quote
  #14  
Old 11-08-2015, 11:00 AM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Thanks so much for the test program. WAF is not so good at the moment. The test program changes the channel flawlessly. So it doesn't look like it's a 64bit issue.


Any interaction with the gentuner shared object from SageTV still results in:

root@banshee:/opt/sagetv/server# ./startsagecore: line 48: 27809 Aborted (core dumped) java -Djava.awt.headless=$HEADLESS $JAVAMEM -XX:+UseAdaptiveSizePolicy -XX:MaxGCPauseMillis=25 -XX:GCTimeRatio=24 -XX:ThreadPriorityPolicy=1 $JAVAOPTS -cp Sage.jar:.:/:$(echo JARs/*.jar | sed 's/ **/:/g') sage.Sage 0 0 x "sagetv Sage.properties" 0>&-


I don't know where to go from here. SageTV also dumps it's core when it tries to stop recording from my HD PVR. The recording/playback is just fine until it tries to stop the recording. Then it crashes.


EDIT:
The gentuner plugin worked long enough for me to add a tuner and select a remote, but then caused SageTV to crash again. Now Sage crashes any time I try to select a new remote via the gentuner plugin or if Sage tries to send a channel change.

Last edited by turak; 11-08-2015 at 11:04 AM.
Reply With Quote
  #15  
Old 11-08-2015, 11:46 AM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Here is my gentuner perl script for controlling my DirecTV Genie (HR44) if anyone wants it or if you want to add it to github. I added .txt extension so the forums would let me upload it.






gentuner.HR44.txt

EDIT:
- I updated this to support multiple STB's
- I was missing a : in the poweron command

Last edited by turak; 11-11-2015 at 12:26 AM.
Reply With Quote
  #16  
Old 11-08-2015, 12:34 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,584
I'm wondering if you problem isn't the Generic Tuner Plugin, but rather what happens AFTER that which is accessing the HDPVR.

BTW, are you running this as root, or a normal sagetv user?
Reply With Quote
  #17  
Old 11-08-2015, 03:13 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
I did the following to install ffprobe and now the gentunerplugin seems to be working for the moment.

add-apt-repository ppa:mc3man/trusty-media
apt-get update
apt-get dist-upgrade
apt-get install ffmpeg
reboot

maybe the dist-upgrade fixed something.

Quote:
I'm wondering if you problem isn't the Generic Tuner Plugin, but rather what happens AFTER that which is accessing the HDPVR.
It was crashing in the source configuration when I'd try to select the device as well. I don't think it accesses the HDPVR at that point. Though I am having issues with Sage crashing it stops recording from the HDPVR.

Quote:
BTW, are you running this as root, or a normal sagetv user?
I'm running it as root
Reply With Quote
  #18  
Old 11-08-2015, 03:19 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
And it's crashing again...
Reply With Quote
  #19  
Old 11-08-2015, 03:50 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
This is interesting... I don't think it's the GenTuner plugin at all. I just did the following:
  • I removed the HDPVR from SageTV
  • I shutdown SageTV
  • I moved the GenericTunerPlugin.so out of the irtunerplugins directory
  • I started SageTV server
  • I started adding the HDPVR as a source
  • I selected Firewire tuner plugin
  • SageTV immediately crashed

I think the problem is with whatever is loading the plugins
Reply With Quote
  #20  
Old 11-08-2015, 05:18 PM
turak's Avatar
turak turak is offline
Sage Expert
 
Join Date: Sep 2003
Location: Miami
Posts: 560
Is anyone using tuning plugins with 64bit SageTV 9.0.3.170 on Ubuntu 14.04?

Did I install SageTV correctly? I did the following:

I downloaded the files from github. I untarred the .tar.gz in /opt/sagetv/server. I created the /var/media/ directories. I installed the .deb. I copied in my wiz.bin from my windows server. I copied the Sage.jar into the /opt/sagetv/server directory. I added 64bit java7 to the PATH in my start scripts. I configured samba.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
External Command Tuner Plugin for Linux stuckless SageTV Linux 36 05-16-2017 03:11 PM
Plugin Request: Run external command on error tedson SageTV v7 Customizations 10 06-14-2010 07:32 PM
Adding custom command for launching external program dinki SageMC Custom Interface 14 01-22-2010 08:16 AM
Getting the status after running an external command pedz25 SageMC Custom Interface 0 04-05-2009 06:55 AM
Fail to launch PowerDVD Ultra as external command basset SageTV Customizations 4 12-20-2007 11:59 AM


All times are GMT -6. The time now is 07:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.