i installed the NET:UPnP module and ran the script with the right perl path in top..
but it returns this error:
Can't call method "postaction" on an undefined value at C:/xampp/htdocs/XBMC/tv.pl line 43. ,
My script looks like this: (just like yours)
Code: Select all
#!"C:\xampp\perl\bin\perl.exe"
# tv.pl
use warnings;
use strict;
use Net::UPnP::ControlPoint;
my $upnp = Net::UPnP::ControlPoint->new();
my @devs = $upnp->search();
my $tv;
foreach my $dev ( @devs )
{
foreach my $serv ( $dev->getservicelist() )
{
if ( $serv->getservicetype() =~ /TVAgent/ )
{
$tv = $serv;
last;
}
}
}
die "TVAgent not found\n" unless $tv;
my $res = action( 'GetCurrentMainTVChannel' );
print "[*] $res->{CurrentChannel}\n";
$res = action( 'GetWatchingInformation' );
print "[*] $res->{TVMode}\n";
print "[*] $res->{WatchingInformation}\n";
exit 0;
# -----------------------------------------------------------------------------
sub action
{
my ( $act, $args ) = @_;
my $r = $tv->postaction( $act, $args );
unless ( 200 == $r->getstatuscode() )
{
die "Error $act: ". $r->getstatuscode()."\n";
}
my $res = $r->getargumentlist();
unless ( 'OK' eq $res->{Result} )
{
die "Error $act response $res->{Result}\n";
}
return $res;
}
# -----------------------------------------------------------------------------
__END__
What is wrong?