Hallo,
ausgehend von diesem Skript habe ich mir zwei eigene Perl Skripte geschrieben.
Das erste kann über die Konsole aufgerufen werden.
Ich nutze das zB aus der rc.xml für openbox um mit den Multimedia Tasten meines Keyboards die TV Lautstärke zu regeln:
#!/usr/bin/perl
use CGI qw(:standard);
use IO::Socket;
use MIME::Base64;
#### Configuration
my $tv = "UE40D5700"; # Might need changing to match your TV type
my $tvip = "192.168.178.21"; # IP Address of TV
my $myip = "192.168.178.26"; # Doesn't seem to be really used
my $mymac = "AB-CD-E1-23-45-67"; # Used for the access control/validation, but not after that AFAIK
####
my $appstring = "iphone..iapp.samsung"; # What the iPhone app reports
my $tvappstring = "iphone.".$tv.".iapp.samsung"; # TV type
my $remotename = "Perl Samsung Remote"; # What gets reported when it asks for permission/also shows in General->Wireless Remote Control menu
# command-line help
if ($ARGV[0] eq "--help") {
print "Usage: samsungremote KEY [KEYS]\n";
print "Normal remote keys:
0 1 2 3 4 5 6 7 8 9
UP DOWN LEFT RIGHT ENTER
MENU PRECH GUIDE INFO RETURN CH_LIST EXIT
SOURCE AD PICTURE_SIZE VOLUP VOLDOWN MUTE
TOOLS POWEROFF CHUP CHDOWN CONTENTS W_LINK
RSS MTS SRS CAPTION TOPMENU SLEEP ESAVING
PLAY PAUSE REWIND FF REC STOP
TV HDMI PIP_ONOFF ASPECT \n";
exit;
}
my $sock = new IO::Socket::INET (
PeerAddr => $tvip,
PeerPort => '55000',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
my $messagepart1 = chr(0x64) . chr(0x00) . chr(length(encode_base64($myip, ""))) . chr(0x00) . encode_base64($myip, "") . chr(length(encode_base64($mymac, ""))) . chr(0x00) . encode_base64($mymac, "") . chr(length(encode_base64($remotename, ""))) . chr(0x00) . encode_base64($remotename, "");
my $part1 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart1)) . chr(0x00) . $messagepart1;
print $sock $part1;
my $messagepart2 = chr(0xc8) . chr(0x00);
my $part2 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart2)) . chr(0x00) . $messagepart2;
print $sock $part2;
# Preceding sections all first time only
if (defined(param("text"))) {
# Send text, e.g. in YouTube app's search, N.B. NOT BBC iPlayer app.
my $text = param("text");
my $messagepart3 = chr(0x01) . chr(0x00) . chr(length(encode_base64($text, ""))) . chr(0x00) . encode_base64($text, "");
my $part3 = chr(0x01) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart3)) . chr(0x00) . $messagepart3;
print $sock $part3;
}
else {
foreach my $argnum (0 .. $#ARGV) {
# Send remote key(s)
my $key = "KEY_" . $ARGV[$argnum];
my $messagepart3 = chr(0x00) . chr(0x00) . chr(0x00) . chr(length(encode_base64($key, ""))) . chr(0x00) . encode_base64($key, "");
my $part3 = chr(0x00) . chr(length($tvappstring)) . chr(0x00) . $tvappstring . chr(length($messagepart3)) . chr(0x00) . $messagepart3;
print $sock $part3;
# sleep(1);
select(undef, undef, undef, 0.5);
}
}
close($sock);
Display More
Auszug aus der rc.xml (das Perl Skript liegt als samsungremote im Pfad - bei mir /usr/local/bin)
<keybind key="XF86AudioMute">
<action name="Execute">
<command>samsungremote MUTE</command>
</action>
</keybind>
<keybind key="XF86AudioLowerVolume">
<action name="Execute">
<command>samsungremote VOLDOWN</command>
</action>
</keybind>
<keybind key="XF86AudioRaiseVolume">
<action name="Execute">
<command>samsungremote VOLUP</command>
</action>
</keybind>
Display More
und das zweite für das OSD des VDR (OSDServer Plugin)
Aufrufen via menu.xml mit
<command name="Samsung Remote" execute="/usr/lib/vdr/osdremote &> /dev/null &" />
#!/usr/bin/perl
# Remote
use IO::Socket;
use MIME::Base64;
#### Configuration
my $tv = "UE40D5700"; # Might need changing to match your TV type
my $tvip = "192.168.178.21"; # IP Address of TV
my $myip = "192.168.178.26"; # Doesn't seem to be really used
my $mymac = "AB-CD-E1-23-45-67"; # Used for the access control/validation, but not after that AFAIK
####
my $appstring = "iphone..iapp.samsung"; # What the iPhone app reports
my $tvappstring = "iphone.".$tv.".iapp.samsung"; # TV type
my $remotename = "Perl Samsung Remote"; # What gets reported when it asks for permission/also shows in General->Wireless Remote Control menu
my $s_sock = new IO::Socket::INET (
PeerAddr => $tvip,
PeerPort => '55000',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $s_sock;
my $messagepart1 = chr(0x64) . chr(0x00) . chr(length(encode_base64($myip, ""))) . chr(0x00) . encode_base64($myip, "") . chr(length(encode_base64($mymac, ""))) . chr(0x00) . encode_base64($mymac, "") . chr(length(encode_base64($remotename, ""))) . chr(0x00) . encode_base64($remotename, "");
my $part1 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart1)) . chr(0x00) . $messagepart1;
print $s_sock $part1;
my $messagepart2 = chr(0xc8) . chr(0x00);
my $part2 = chr(0x00) . chr(length($appstring)) . chr(0x00) . $appstring . chr(length($messagepart2)) . chr(0x00) . $messagepart2;
print $s_sock $part2;
sub SendKey($) {
# Send remote key
my ($key) = @_;
my $messagepart3 = chr(0x00) . chr(0x00) . chr(0x00) . chr(length(encode_base64($key, ""))) . chr(0x00) . encode_base64($key, "");
my $part3 = chr(0x00) . chr(length($tvappstring)) . chr(0x00) . $tvappstring . chr(length($messagepart3)) . chr(0x00) . $messagepart3;
print $s_sock $part3;
}
# OSDServer
use OSDServer;
my $server = OSDServer->Open() or die "open";
my $menu = $server->NewMenu("Samsung Remote");
$menu->EnableEvent(["keyOk"]);
$menu->EnableEvent(["keyBack", "close"]);
$menu->EnableEvent(["keyMenu", "close"]);
my $hdmi = $menu->AddNewOsdItem("HDMI");
my $tv = $menu->AddNewOsdItem("TV");
my $pmode = $menu->AddNewOsdItem("PMode");
my $volup = $menu->AddNewOsdItem("Vol+");
my $voldown = $menu->AddNewOsdItem("Vol-");
my $mute = $menu->AddNewOsdItem("Mute");
my $pip = $menu->AddNewOsdItem("PIP");
my $chup = $menu->AddNewOsdItem("Ch+");
my $chdown = $menu->AddNewOsdItem("Ch-");
my $poweroff = $menu->AddNewOsdItem("PowerOff");
my $sleep = $menu->AddNewOsdItem("Sleep");
$menu->Show();
my (undef,undef,$event) = $menu->SleepEvent();
my (undef, $item, undef) = $menu->GetCurrent();
# Main loop
while (1) {
if ($event eq "close") {
last;
} elsif ($item eq $hdmi and $event eq "keyOk") {
SendKey("KEY_HDMI");
} elsif ($item eq $tv and $event eq "keyOk") {
SendKey("KEY_TV");
} elsif ($item eq $pmode and $event eq "keyOk") {
SendKey("KEY_PMODE");
} elsif ($item eq $volup and $event eq "keyOk") {
SendKey("KEY_VOLUP");
} elsif ($item eq $voldown and $event eq "keyOk") {
SendKey("KEY_VOLDOWN");
} elsif ($item eq $mute and $event eq "keyOk") {
SendKey("KEY_MUTE");
} elsif ($item eq $srs and $event eq "keyOk") {
SendKey("KEY_SRS");
} elsif ($item eq $pip and $event eq "keyOk") {
SendKey("KEY_PIP_ONOFF");
} elsif ($item eq $chup and $event eq "keyOk") {
SendKey("KEY_CHUP");
} elsif ($item eq $chdown and $event eq "keyOk") {
SendKey("KEY_CHDOWN");
} elsif ($item eq $poweroff and $event eq "keyOk") {
SendKey("KEY_POWEROFF");
} elsif ($item eq $sleep and $event eq "keyOk") {
SendKey("KEY_SLEEP");
}
(undef,undef,$event) = $menu->SleepEvent();
(undef, $item, undef) = $menu->GetCurrent();
}
close($s_sock);
$server->Close();
Display More