mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
a1397d1c34
git-svn-id: https://svn.fhem.de/fhem/trunk@2076 2b470e98-0d58-463d-a4d8-8e2adae1ed80
385 lines
12 KiB
Perl
385 lines
12 KiB
Perl
##############################################################################
|
|
#
|
|
# 70_STV.pm
|
|
#
|
|
# a module to send messages or commands to a Samsung TV
|
|
# for example a LE40B650
|
|
#
|
|
# written 2012 by Gabriel Bentele <gabriel at bentele.de>>
|
|
#
|
|
# $Id$
|
|
#
|
|
# Version = 1.1
|
|
#
|
|
##############################################################################
|
|
#
|
|
# define <name> STV <host>
|
|
#
|
|
# set <name> <key> <value>
|
|
#
|
|
# where <key> is one of mute, volume, call, sms, date
|
|
# examples:
|
|
# set <name> mute on
|
|
# set <name> volume 20
|
|
# set <name> call Peter 1111111 Klaus 222222Peter 1111111 Klaus 222222
|
|
# set <name> sms Peter 1111111 Klaus 222222 das ist der text
|
|
# set <name> date 2012-12-10 18:07:04 Peter 11111 Bier 2012-12-11 23:59:20 Paulaner
|
|
#
|
|
##############################################################################
|
|
|
|
package main;
|
|
use IO::Socket::INET;
|
|
|
|
my @gets = ('dummy');
|
|
|
|
sub
|
|
STV_Initialize($)
|
|
{
|
|
my ($hash) = @_;
|
|
$hash->{DefFn} = "STV_Define";
|
|
$hash->{StateFn} = "STV_SetState";
|
|
$hash->{SetFn} = "STV_Set";
|
|
$hash->{AttrList} = "loglevel:0,1,2,3,4,5";
|
|
|
|
}
|
|
|
|
sub
|
|
STV_SetState($$$$)
|
|
{
|
|
my ($hash, $tim, $vt, $val) = @_;
|
|
|
|
$val = $1 if($val =~ m/^(.*) \d+$/);
|
|
return "Undefined value $val" if(!defined($it_c2b{$val}));
|
|
return undef;
|
|
}
|
|
|
|
|
|
sub
|
|
STV_Define($$)
|
|
{
|
|
my ($hash, $def) = @_;
|
|
|
|
my @args = split("[ \t]+", $def);
|
|
|
|
if (int(@args) < 2)
|
|
{
|
|
return "energy_Define: too much arguments. Usage:\n" .
|
|
"define <name> STV <host> <port>";
|
|
}
|
|
|
|
$hash->{Host} = $args[2];
|
|
$hash->{STATE} = 'Initialized';
|
|
|
|
Log 3, "sub define2 with host: $hash->{Host}";
|
|
|
|
return undef;
|
|
}
|
|
|
|
sub connection($$)
|
|
{
|
|
my $tmp = shift ;
|
|
Log 4, "connection message: $tmp";
|
|
my $TV = shift;
|
|
my $buffer = "";
|
|
my $tmp2 = "";
|
|
|
|
my $sock = new IO::Socket::INET (
|
|
PeerAddr => $TV,
|
|
PeerPort => '52235',
|
|
Proto => 'tcp',
|
|
Timout => 5
|
|
);
|
|
if (defined ($sock)){
|
|
print $sock $tmp;
|
|
my $buff ="";
|
|
while ((read $sock, $buff, 1) > 0){
|
|
$buffer .= $buff;
|
|
}
|
|
@tmp2 = split (/\n/,$buffer);
|
|
Log 3, "$TV response: $tmp2[0]";
|
|
Log 4, "$TV buffer response: $buffer";
|
|
$sock->close();
|
|
Log 4, "$TV: socket closed";
|
|
}else{
|
|
Log 4, "$TV: not able to close socket";
|
|
}
|
|
}
|
|
|
|
sub STV_Set($@)
|
|
{
|
|
my ($hash, @a) = @_;
|
|
my $name = $hash->{NAME};
|
|
my $TV = $hash->{Host};
|
|
my $count = @a;
|
|
|
|
my $arg = lc($a[1]); # mute volume
|
|
my $cont1 = ucfirst($arg); # Mute
|
|
my $cont2 = "";
|
|
my $cont3 = "";
|
|
my $cont4 = "";
|
|
my $cont5 = "";
|
|
my $cont6 = "";
|
|
my $cont7 = "";
|
|
my $cont8 = "";
|
|
my $cont9 = "";
|
|
|
|
if (defined $a[2]) { $cont2 = $a[2]}
|
|
if (defined $a[3]) { $cont3 = $a[3]}
|
|
if (defined $a[4]) { $cont4 = $a[4]}
|
|
if (defined $a[5]) { $cont5 = $a[5]}
|
|
if (defined $a[6]) { $cont6 = $a[6]}
|
|
if (defined $a[7]) { $cont7 = $a[7]}
|
|
if (defined $a[8]) { $cont8 = $a[8]}
|
|
if (defined $a[9]) { $cont9 = $a[9]}
|
|
|
|
my $callsoap = "";
|
|
my $message = "";
|
|
my $head = "";
|
|
my $kind = 0;
|
|
my $size = "";
|
|
my $body = "";
|
|
|
|
if ( $arg eq "mute" )
|
|
{
|
|
$kind = 1;
|
|
if ( $cont2 eq "off" ){
|
|
$cont2 = 0 ;
|
|
}else {
|
|
$cont2 = 1 ;
|
|
}
|
|
}
|
|
if ( $arg eq "volume")
|
|
{
|
|
if ( $cont2 > 0 and $cont2 < 100 ){
|
|
$kind = 1;
|
|
}else {
|
|
Log 3, "$name Volume: not correct";
|
|
$kind = 0;
|
|
}
|
|
}
|
|
if ( $arg eq "call")
|
|
{
|
|
$kind = 2;
|
|
|
|
}
|
|
if ( $arg eq "sms")
|
|
{
|
|
$kind = 3;
|
|
for my $i (6..$count){
|
|
$body .= $a[$i];
|
|
$body .= " ";
|
|
}
|
|
}
|
|
if ( $arg eq "date")
|
|
{
|
|
$kind = 4;
|
|
for my $i (10..$count){
|
|
$body .= $a[$i];
|
|
$body .= " ";
|
|
}
|
|
}
|
|
|
|
if ( $kind eq 1){
|
|
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
|
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
|
|
$callsoap .= "<s:Body>\r\n";
|
|
$callsoap .= "<ns0:Set$cont1 xmlns:ns0=\"urn:schemas-upnp-org:service:RenderingControl:1\">\r\n";
|
|
$callsoap .= "<InstanceID>0</InstanceID>\r\n";
|
|
$callsoap .= "<Desired$cont1>$cont2</Desired$cont1>\r\n";
|
|
$callsoap .= "<Channel>Master</Channel>\r\n";
|
|
$callsoap .= "</ns0:Set$cont1>\r\n";
|
|
$callsoap .= "</s:Body>\r\n";
|
|
$callsoap .= "</s:Envelope>\r\n";
|
|
|
|
$size = length($callsoap);
|
|
|
|
$head .= "POST /upnp/control/RenderingControl1 HTTP/1.1\r\n";
|
|
$head .= "Content-Type: text/xml; charset=\"utf-8\"\r\n";
|
|
$head .= "SOAPACTION: \"SoapAction:urn:schemas-upnp-org:service:RenderingControl:1#Set$cont1\"\r\n";
|
|
$head .= "Cache-Control: no-cache\r\n";
|
|
$head .= "Host: $TV:52235\r\n";
|
|
$head .= "Content-Length: $size\r\n";
|
|
$head .= "Connection: Close\r\n";
|
|
$head .= "\r\n";
|
|
|
|
$message .= $head;
|
|
$message .= $callsoap;
|
|
}
|
|
|
|
my $calldate=`date +"%Y-%m-%d"`;
|
|
chomp($calldate);
|
|
my $calltime=`date +"%H:%M:%S"`;
|
|
chomp($calltime);
|
|
|
|
if ( $kind eq 2 ){ # CALL
|
|
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
|
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\r\n";
|
|
$callsoap .= "<s:Body>\r\n";
|
|
$callsoap .= "<u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\\\">\r\n";
|
|
$callsoap .= "<MessageType>text/xml</MessageType>\r\n";
|
|
$callsoap .= "<MessageID>1334799348</MessageID>\r\n";
|
|
$callsoap .= "<Message>\r\n";
|
|
$callsoap .= "<Category>Incoming Call</Category>\r\n";
|
|
$callsoap .= "<DisplayType>Maximum</DisplayType>\r\n";
|
|
$callsoap .= "<CallTime>\r\n";
|
|
$callsoap .= "<Date>$calldate</Date>\r\n";
|
|
$callsoap .= "<Time>$calltime</Time>\r\n";
|
|
$callsoap .= "</CallTime>\r\n";
|
|
$callsoap .= "<Callee>\r\n";
|
|
$callsoap .= "<Name>An: $cont4</Name>\r\n";
|
|
$callsoap .= "<Number>Nr: $cont5</Number>\r\n";
|
|
$callsoap .= "</Callee>\r\n";
|
|
$callsoap .= "<Caller>\r\n";
|
|
$callsoap .= "<Name>Von: $cont2</Name>\r\n";
|
|
$callsoap .= "<Number>Nr: $cont3</Number>\r\n";
|
|
$callsoap .= "</Caller>\r\n";
|
|
$callsoap .= "</Message>\r\n";
|
|
$callsoap .= "</u:AddMessage>\r\n";
|
|
$callsoap .= "</s:Body>\r\n";
|
|
$callsoap .= "</s:Envelope>\r\n";
|
|
|
|
$size = length($callsoap);
|
|
$head .= "POST /PMR/control/MessageBoxService HTTP/1.1\r\n";
|
|
$head .= "Content-Type: text/xml; charset=\"utf-8\"\r\n";
|
|
$head .= "SOAPACTION: \"urn:samsung.com:service:MessageBoxService:1#AddMessage\"\r\n";
|
|
$head .= "Cache-Control: no-cache\r\n";
|
|
$head .= "Host: $TV:52235\r\n";
|
|
$head .= "Content-Length: $size\r\n";
|
|
$head .= "Connection: Close\r\n";
|
|
$head .= "\r\n";
|
|
|
|
$message .= $head;
|
|
$message .= $callsoap;
|
|
}
|
|
|
|
if ( $kind eq 3 ){ # SMS
|
|
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
|
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\r\n";
|
|
$callsoap .= "<s:Body>\r\n";
|
|
$callsoap .= "<u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\\\">\r\n";
|
|
$callsoap .= "<MessageType>text/xml</MessageType>\r\n";
|
|
$callsoap .= "<MessageID>1334799348</MessageID>\r\n";
|
|
$callsoap .= "<Message>\r\n";
|
|
$callsoap .= "<Category>SMS</Category>\r\n";
|
|
$callsoap .= "<DisplayType>Maximum</DisplayType>\r\n";
|
|
$callsoap .= "<ReceiveTime>\r\n";
|
|
$callsoap .= "<Date>$calldate</Date>\r\n";
|
|
$callsoap .= "<Time>$calltime</Time>\r\n";
|
|
$callsoap .= "</ReceiveTime>\r\n";
|
|
$callsoap .= "<Receiver>\r\n";
|
|
$callsoap .= "<Name>An: $cont4</Name>\r\n";
|
|
$callsoap .= "<Number>Nr: $cont5</Number>\r\n";
|
|
$callsoap .= "</Receiver>\r\n";
|
|
$callsoap .= "<Sender>\r\n";
|
|
$callsoap .= "<Name>Von: $cont2</Name>\r\n";
|
|
$callsoap .= "<Number>Nr: $cont3</Number>\r\n";
|
|
$callsoap .= "</Sender>\r\n";
|
|
$callsoap .= "<Body>Inhalt: $body</Body>\r\n";
|
|
$callsoap .= "</Message>\r\n";
|
|
$callsoap .= "</u:AddMessage>\r\n";
|
|
$callsoap .= "</s:Body>\r\n";
|
|
$callsoap .= "</s:Envelope>\r\n";
|
|
|
|
$size = length($callsoap);
|
|
$head .= "POST /PMR/control/MessageBoxService HTTP/1.1\r\n";
|
|
$head .= "Content-Type: text/xml; charset=\"utf-8\"\r\n";
|
|
$head .= "SOAPACTION: \"urn:samsung.com:service:MessageBoxService:1#AddMessage\"\r\n";
|
|
$head .= "Cache-Control: no-cache\r\n";
|
|
$head .= "Host: $TV:52235\r\n";
|
|
$head .= "Content-Length: $size\r\n";
|
|
$head .= "Connection: Close\r\n";
|
|
$head .= "\r\n";
|
|
|
|
$message .= $head;
|
|
$message .= $callsoap;
|
|
}
|
|
|
|
if ( $kind eq 4 ){ # Termin
|
|
$callsoap .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
|
$callsoap .= "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\r\n";
|
|
$callsoap .= "<s:Body>\r\n";
|
|
$callsoap .= "<u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\\\">\r\n";
|
|
$callsoap .= "<MessageType>text/xml</MessageType>\r\n";
|
|
$callsoap .= "<MessageID>1334799348</MessageID>\r\n";
|
|
$callsoap .= "<Message>\r\n";
|
|
$callsoap .= "<Category>Schedule Reminder</Category>\r\n";
|
|
$callsoap .= "<DisplayType>Maximum</DisplayType>\r\n";
|
|
$callsoap .= "<StartTime>\r\n";
|
|
$callsoap .= "<Date>$cont2</Date>\r\n";
|
|
$callsoap .= "<Time>$cont3</Time>\r\n";
|
|
$callsoap .= "</StartTime>\r\n";
|
|
$callsoap .= "<Owner>\r\n";
|
|
$callsoap .= "<Name>Fr: $cont4</Name>\r\n";
|
|
$callsoap .= "<Number>Nr: $cont5</Number>\r\n";
|
|
$callsoap .= "</Owner>\r\n";
|
|
$callsoap .= "<Subject>Betreff: $cont6</Subject>\r\n";
|
|
$callsoap .= "<EndTime>\r\n";
|
|
$callsoap .= "<Date>$cont7</Date>\r\n";
|
|
$callsoap .= "<Time>$cont8</Time>\r\n";
|
|
$callsoap .= "</EndTime>\r\n";
|
|
$callsoap .= "<Location>Ort: $cont9</Location>\r\n";
|
|
$callsoap .= "<Body>Inhalt: $body</Body>\r\n";
|
|
$callsoap .= "</Message>\r\n";
|
|
$callsoap .= "</u:AddMessage>\r\n";
|
|
$callsoap .= "</s:Body>\r\n";
|
|
$callsoap .= "</s:Envelope>\r\n";
|
|
|
|
$size = length($callsoap);
|
|
$head .= "POST /PMR/control/MessageBoxService HTTP/1.1\r\n";
|
|
$head .= "Content-Type: text/xml; charset=\"utf-8\"\r\n";
|
|
$head .= "SOAPACTION: \"urn:samsung.com:service:MessageBoxService:1#AddMessage\"\r\n";
|
|
$head .= "Cache-Control: no-cache\r\n";
|
|
$head .= "Host: $TV:52235\r\n";
|
|
$head .= "Content-Length: $size\r\n";
|
|
$head .= "Connection: Close\r\n";
|
|
$head .= "\r\n";
|
|
|
|
$message .= $head;
|
|
$message .= $callsoap;
|
|
}
|
|
|
|
if ( $kind ne 0 ){
|
|
connection($message, $TV);
|
|
}else{
|
|
return "Unknown argument $name, choose one of mute volume call sms date";
|
|
}
|
|
}
|
|
|
|
1;
|
|
|
|
=pod
|
|
=begin html
|
|
|
|
<a name="STV"></a>
|
|
|
|
<h3>STV</h3>
|
|
<ul><p>
|
|
This module supports Samsung TV devices with few commands. It's developed and tested with Samsung LE39B650.<br>
|
|
</p>
|
|
<b>Define</b><br>
|
|
<code>define <name> STV <host>]</code><br>
|
|
<p>
|
|
Example:<br>
|
|
define Television1 STV 192.168.178.20 <br>
|
|
</p>
|
|
<b>Set</b><br>
|
|
set <name> <value> <nummber><br>where value is one of:<br><br>
|
|
<ul>
|
|
<li><code>mute</code> </li>
|
|
<li><code>volume </code> </li>
|
|
<li><code>call</code> </li>
|
|
<li><code>sms </code> </li>
|
|
<li><code>date </code> </li>
|
|
</ul>
|
|
<br>Example:<br>
|
|
set <name> mute <br>
|
|
set <name> volume 20 <br>
|
|
set <name> call Peter 012345678 Phone 87654321 <br><br>
|
|
|
|
<b>Get</b><br>
|
|
<ul>N/A</ul><br>
|
|
</ul>
|
|
|
|
=end html
|
|
=cut
|