1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/usr/bin/perl -w use strict; use IO::Socket; $| = 1; my ($host, $port, $kidpid, $handle, $line); unless (@ARGV == 2) { die "usage: $0 host port" } ($host, $port) = @ARGV; # create a tcp connection to the specified host and port $handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $host, PeerPort => $port) or die "can't connect to port $port on $host: $!"; while () { #$handle->autoflush(1); # so output gets there right away # print STDERR "[Connected to $host:$port]\n"; # the if{} block runs only in the parent process # copy the socket to standard output $line = <$handle> ; print STDOUT $line; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# socket handle erstellen my $socket = new IO::Socket::INET ( PeerAddr => $host, PeerPort => $port, Proto => 'tcp' ); # Request Header senden print $socket "GET / HTTP/1.0\n\n"; # Speicherort des Streams öffnen open(OUT, ">cut.mp3"); binmode OUT; while(my $s = read($socket, my $buffer, 1024)){ print OUT $buffer; }
my $socket = new IO::Socket::INET("$host:$port"); # kurzform
1 2 3 4 5 6 7 8
my $buffer=''; my $line=''; while(defined($line) && time() < $time+20 && $finished==0) { $handle->read($line,4096); $finished=1 if(index($buffer,'L:')!=-1); $buffer.=$line if(defined($line) && length($line)); }
1
2
3
4
5
6
7
8
9
H:IEQ0111347,00b5b6,0102,00000000,3ed09189,01,32
M:00,01,VgICAQpXb2huemltbWVyAQhjAgZLw7xjaGUAjwIFAQEIY0lFUTAxOTI4MDcKV29obnppbW1lcgEEAFv7SUVRMDE1Njg3NwtXb2huZmVuc3RlcgEFAEu4SUVRMDE0NTQ4OQxFQ08tU2NoYWx0ZXIAAQCPAklFUTAxOTU0NzUGS8O8Y2hlAgQAX9ZJRVEwMTU3Nzc2DUZlbnN0ZXJrw7xjaGUCAQ==
C:00b5b6,7QC1tgACAf9JRVEwMTExMzQ3AQsABEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsABEAAAAAAAAAAQQAAAAAAAAAAAAAAAAAA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GUCAQ==
M:00,01,VgICAQpXb2huemltbWVyAQhjAgZLw7xjaGUAjwIFAQEIY0lFUTAxOTI4MDcKV29obnppbW1lcgEEAFv7SUVRMDE1Njg3NwtXb2huZmVuc3RlcgEFAEu4SUVRMDE0NTQ4OQxFQ08tU2NoYWx0ZXIAAQCPAklFUTAxOTU0NzUGS8O8Y2hlAgQAX9ZJRVEwMTU3Nzc2DUZlbnN0ZXJrw7xjaGUCAQ==
....l
while(( my $line=$handle->getline() ) && time() < $time+20 && $finished==0)
while(( my $line=<$handle> ) && time() < $time+20 && $finished==0)
while( my $line=<$handle> and time() < $time+20 and $finished==0)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
#!/usr/bin/perl use strict; use warnings; use IO::Socket; use MIME::Base64; my $host = "192.168.1.36"; # Your Cube-IP or hostame Here! my $port = "80"; # ewige schleife while(1) { my $handle = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port ) // die("ERROR open Socket $host:$port ($!)\n"); $handle->blocking(0); binmode($handle); my $finished = 0; my $time=time(); my $buffer=''; my $line=''; while(( my $line=$handle->getline() ) && time() < $time+20 && $finished==0) { $handle->read($line,4096); $finished=1 if(index($buffer,'L:')!=-1); $buffer.=$line if(defined($line) && length($line)); } $handle->close(); print "test:"; print $buffer; print "ende"; if(!$finished) { print "No Connection\n"; next; } my %data; my %deviceconf; for my $v (split("\n\n",$buffer)) { if($v=~/^M:(?:[^,]*,){2}([^,]+)/) { my $str=decode_base64($1); $data{meta}{'?1'}=substr_hex(\$str,1); $data{meta}{'?2'}=substr_hex(\$str,1); $data{meta}{RoomCount}=substr_ord(\$str,1); for(1..$data{meta}{RoomCount}) { my $roomid=substr_hex(\$str,1); my $name_length=substr_ord(\$str,1); #$data{rooms}{$roomid}{RoomNameLength}=$name_length; $data{rooms}{$roomid}{RoomName}=substr_del(\$str,$name_length); # TODO: Nachprüfen!!!! $data{rooms}{$roomid}{"RFAdress(?)"}=substr_hex_fix(\$str,3); } $data{meta}{DevCount}=substr_ord(\$str,1); } if($v=~/^L:(.+)/) { my %hilf; my $str=decode_base64($1); for(1..$data{meta}{DevCount}) { my $length=substr_ord(\$str,1); #$hilf{ReadLength}=$length; # TODO: Nachprüfen!!!! $hilf{RFAdress}=substr_hex_fix(\$str,3); $hilf{'?1'}=substr_hex(\$str,1); $hilf{Data1}=substr_bin(\$str,1); $hilf{Data2}=substr_bin(\$str,1); if($length == 11) { $hilf{'?2'}=substr_hex(\$str,1); $hilf{Temperature}=substr_ord(\$str,1)/2; $hilf{DateUntil}=substr_bin(\$str,1); $hilf{TimeUntil}=substr_ord(\$str,1)/2; } my $sub=substr($hilf{Data2},6,2); if($sub eq '00') { $deviceconf{$hilf{RFAdress}}{Mode} = 'auto' } elsif($sub eq '01') { $deviceconf{$hilf{RFAdress}}{Mode} = 'manu' } elsif($sub eq '10') { $deviceconf{$hilf{RFAdress}}{Mode} = 'vacation' } else { $deviceconf{$hilf{RFAdress}}{Mode} = 'boost' } $deviceconf{$hilf{RFAdress}}{LiveDataX} = $hilf{Data3}; } } } if ($deviceconf{'005bfb'}{Mode} eq 'auto' && $deviceconf{'004bb8'}{Mode} eq 'auto' ) { print $deviceconf{'005bfb'}{Mode}; } else { print $deviceconf{'005bfb'}{Mode}; } sleep(10); } ######################################################################## sub substr_del { return substr( ${$_[0]}, 0, $_[1], '') } sub substr_ord { return unpack('C*', substr_del(@_) ); } sub substr_hex { return unpack('H*', substr_del(@_)); } # TODO: Nachprüfen!!!! sub substr_hex_fix { my $str=shift; my $length=shift; my $ret=''; $ret.=substr("00".substr_hex($str,1),-2,2) for(1..$length); return $ret; } # TODO: Nachprüfen!!!! sub substr_bin { return substr(("0"x8).unpack('B*', substr_del(@_)),-8,8); }
1 2 3 4 5 6 7 8 9 10
my $finished = 0; my $time=time(); my $buffer=''; while(time() < $time+20 && $finished==0) { my $line=''; $handle->read($line,4096); $finished=1 if(index($buffer,'L:')!=-1); $buffer.=$line if(length($line)); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#!/usr/bin/perl -w use strict; use warnings; use IO::Socket; my $host = "192.168.0.36"; # Your Cube-IP or hostame Here! my $port = "80"; while(1) { my $handle = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port ) // die("ERROR open Socket $host:$port ($!)\n"); $handle->blocking(0); binmode($handle); my $finished = 0; my $buffer=''; while($finished==0) { my $line=''; $handle->read($line,4096); $finished=1 if(index($buffer,'L:')!=-1); $buffer.=$line if(length($line)); } $handle->close(); if(!$finished) { print "No Connection\n"; next; } open(STATION, ">/home/kami/scripts/test"); foreach my $v (split("\r",$buffer)) { print STATION $v."\n"; } close (STATION); sleep(3); system("./alwindow.php", "windowsstatus"); print $?; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/php -q
<?php
#print_r($argv);
$finished = 0;
$jetzt = time();
$handle = @fopen('/home/kami/scripts/test', "r");
if ($handle) {
while (!feof($handle)) {
$arr[] = fgets($handle, 4096);
}
fclose($handle);
}
ob_start();
foreach ($arr as $v)
{
if (substr($v,0,2) == "M:")
{
$arr2 = explode(',',$v);
$str = base64_decode($arr2[2]);
$pos = 0;
$readlen = 1; $data["meta"]["?1"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = 1; $data["meta"]["?2"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = 1; $data["meta"]["RoomCount"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
for($j = 1 ; $j <= $data["meta"]["RoomCount"] ; $j++)
{
$readlen = 1; $RoomID = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = 1; $data["rooms"][$RoomID]["RoomNameLength"] = htmlentities(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = $data["rooms"][$RoomID]["RoomNameLength"]; for($i = $pos; $i < $readlen+$pos ; $i++) $data["rooms"][$RoomID]["RoomName"] .= htmlentities(substr($str,$i,1)).""; $pos += $readlen;
$readlen = 3; for($i = $pos; $i < $readlen+$pos ; $i++) $data["rooms"][$RoomID]["RFAdress(?)"] .= str_pad(dechex(ord(substr($str,$i,1))),2,"0",STR_PAD_LEFT).""; $pos += $readlen;
}
$readlen = 1; $data["meta"]["DevCount"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
}
if (substr($v,0,2) == "L:")
{
$v = substr($v,2,strlen($v));
$str = base64_decode($v);
$pos = 0;
for($j = 1 ; $j <= $data["meta"]["DevCount"]; $j++)
{
unset($hilf);
$readlen = 1; $hilf["ReadLength"] = htmlentities(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = 3; for($i = $pos; $i < $readlen+$pos ; $i++) $hilf["RFAdress"] .= str_pad(dechex(ord(substr($str,$i,1))),2,"0",STR_PAD_LEFT).""; $pos += $readlen;
$readlen = 1; $hilf["?1"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = 1; $hilf["Data1"] .= str_pad(decbin(ord(substr($str,$pos,1))),8,"0",STR_PAD_LEFT).""; $pos += $readlen;
$readlen = 1; $hilf["Data2"] .= str_pad(decbin(ord(substr($str,$pos,1))),8,"0",STR_PAD_LEFT).""; $pos += $readlen;
if($hilf["ReadLength"] == 11)
{
$readlen = 1; $hilf["?2"] = dechex(ord(substr($str,$pos,1))).""; $pos += $readlen;
$readlen = 1; $hilf["Temperature"] = (ord(substr($str,$pos,1))/2).""; $pos += $readlen;
$readlen = 2; for($i = $pos; $i < $readlen+$pos ; $i++) $hilf["DateUntil"] .= str_pad(decbin(ord(substr($str,$i,1))),8,"0",STR_PAD_LEFT).""; $pos += $readlen;
$readlen = 1; $hilf["TimeUntil"] = (ord(substr($str,$pos,1))*0.5).""; $pos += $readlen;
}
if($hilf["ReadLength"] == 11)
{
$deviceconf[$hilf["RFAdress"]]["Temperature"] = $hilf["Temperature"];
}
$deviceconf[$hilf["RFAdress"]]["LowBatt"] = substr($hilf["Data2"],0,1);
switch (substr($hilf["Data2"],6,2))
{
case "00" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "auto"; break;
case "01" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "manu"; break;
case "10" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "vacation"; break;
case "11" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "boost"; break;
}
}
//echo $v;
}
}
$ob = ob_get_contents();
ob_end_clean();
switch ($argv[1])
{
case "windowsstatus" : if ($deviceconf['005bfb']['Mode']=="auto" && $deviceconf['004bb8']['Mode'] =="auto" )
echo "2\n";
else echo "1\n";
break;
case "tempkueche" : echo $deviceconf['008f02']["Temperature"]; break;
case "tempwohn" : echo $deviceconf['010863']["Temperature"]; break;
case "batwohn" : echo $deviceconf['010863']["LowBatt"]; break;
case "batkueche" : echo $deviceconf['008f02']["LowBatt"]; break;
case "modekueche" : echo $deviceconf['008f02']["Mode"]; break;
case "modewohn" : echo $deviceconf['010863']["Mode"]; break;
}
?>
print STATION $buffer;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
if (substr($v,0,2) == "L:")
{
$data["meta"]["DevCount"]=5;
$v = substr($v,2,strlen($v));
$str = base64_decode($v);
$pos = 0;
for($j = 1 ; $j <= $data["meta"]["DevCount"]; $j++)
{
unset($hilf);
$hilf["ReadLength"] = htmlentities(ord(substr($str,$pos,1)));
$pos += 1;
for($i = $pos; $i < (3+$pos) ; $i++)
$hilf["RFAdress"] .= str_pad(dechex(ord(substr($str,$i,1))),2,"0",STR_PAD_LEFT);
$pos += 5;
$hilf["Data2"] .= str_pad(decbin(ord(substr($str,$pos,1))),8,"0",STR_PAD_LEFT)."";
$deviceconf[$hilf["RFAdress"]]["LowBatt"] = substr($hilf["Data2"],0,1);
$pos += 1;
if($hilf["ReadLength"] == 11)
{
$pos += 1;
$deviceconf[$hilf["RFAdress"]]["Temperature"] = (ord(substr($str,$pos,1))/2)."";
$pos += 4;
}
switch (substr($hilf["Data2"],6,2))
{
case "00" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "auto"; break;
case "01" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "manu"; break;
case "10" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "vacation"; break;
case "11" : $deviceconf[$hilf["RFAdress"]]["Mode"] = "boost"; break;
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
use HTML::Entities; use MIME::Base64; ... my %data; my %deviceconf; ... if (substr($v,0,2) eq "L:") { $data{"meta"}{"DevCount"}=5; substr($v,0,2,''); my $str = decode_base64($v); my $pos = 0; for my $j (1..$data{"meta"}{"DevCount"}) { my %hilf; # versteh ich nicht. Hier sind nur Zahlen enthalten # keine Ahnung warum hier htmlentities drüber läuft $hilf{"ReadLength"} = htmlentities(ord(substr($str,$pos,1))); $pos += 1; for my $i ($pos..(2+$pos)) { $hilf{"RFAdress"} .= dechex2( substr( $str,$i,1 ) ); $pos += 5; $hilf{"Data2"} .= decbin8( substr( $str,$pos,1 ) ).""; $deviceconf{$hilf{"RFAdress"}}{"LowBatt"} = substr($hilf{"Data2"},0,1); $pos += 1; if($hilf{"ReadLength"} == 11) { $pos += 1; $deviceconf{$hilf{"RFAdress"}}{"Temperature"} = (ord(substr($str,$pos,1))/2).""; $pos += 4; } my $val=substr($hilf{"Data2"},6,2) if($val eq "00") { $deviceconf{$hilf{"RFAdress"}}{"Mode"} = "auto"; } elsif($val eq "01") { $deviceconf{$hilf{"RFAdress"}}{"Mode"} = "manu"; } elsif($val eq "10") { $deviceconf{$hilf{"RFAdress"}}{"Mode"} = "vacation"; } elsif($val eq "11") { $deviceconf{$hilf{"RFAdress"}}{"Mode"} = "boost"; } } } } ... sub htmlentities { my $str=shift; return encode_entities($str); } # kombination aus str_pad, decbin und ord sub decbin8 { my $str=shift; return unpack('B8',$str); } # kombination aus str_pad, dechex und ord sub dechex2 { my $str=shift; return unpack('H2',$str); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#!/usr/bin/perl -w use strict; use warnings; use utf8; use IO::Socket; use MIME::Base64; use Data::Dumper; $Data::Dumper::Useqq=1; my $host = "192.168.1.36"; # Your Cube-IP or hostame Here! my $port = "80"; my $devices = "5"; my $handle = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port ) // die("ERROR open Socket $host:$port ($!)\n"); $handle->blocking(0); binmode($handle); while(1) { my $finished = 0; my $time=time(); my $buffer=''; while(time() < $time+20 && $finished==0) { my $line=''; $handle->read($line,4096); $finished=1 if(index($buffer,'L:')!=-1); $buffer.=$line if(length($line)); } if(!$finished) { print "No Connection\n"; next; } my %data; my %deviceconf; for my $v (split(/[\x0D\x0A]+/,$buffer)) { if($v=~/^L:(.+)/g) { my %hilf; my $str=decode_base64($1); for(1..$devices) { my $length=substr_ord(\$str,1); next if($length<6); my ($rfaddr,$x1,$data1,$data2)=unpack('H6 H2 B8 B8',substr($str,0,6,'')); if($rfaddr eq '005fd6') { $rfaddr = 'KuecheFe' } elsif($rfaddr eq '008f02') { $rfaddr = 'KuecheTh' } elsif($rfaddr eq '010863') { $rfaddr = 'WohnTh' } elsif($rfaddr eq '004bb8') { $rfaddr = 'WohnFe' } elsif($rfaddr eq '005bfb') { $rfaddr = 'Eco' } else {$rfaddr = $rfaddr} $deviceconf{$rfaddr}={ LowBat => substr($data2,0,1,'') }; if($length == 11) { my ($x2,$temp,$date,$time)=unpack('C C B16 C',substr($str,0,5,'')); $deviceconf{$rfaddr}{Temperatur}=$temp/2; } my $sub=substr($data2,6,2); if($sub == 0) { $deviceconf{$rfaddr}{Mode} = 'auto' } elsif($sub == 1) { $deviceconf{$rfaddr}{Mode} = 'manu' } elsif($sub == 2) { $deviceconf{$rfaddr}{Mode} = 'vacation' } elsif($sub == 3) { $deviceconf{$rfaddr}{Mode} = 'boost' } } } } print Dumper(\%deviceconf); sleep(1); $handle->send("l:"); } $handle->close(); sub substr_del { return substr( ${$_[0]}, 0, $_[1], '') } sub substr_ord { return unpack('C*', substr_del(@_) ); } sub substr_hex { return unpack('H*', substr_del(@_)); } sub substr_hex_fix { my $str=shift; my $length=shift; return unpack("H".($length*2), substr_del($str,$length)); } sub substr_bin { return unpack('B8', substr_del(@_)); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#!/usr/bin/perl -w use strict; use warnings; use utf8; use IO::Socket; use MIME::Base64; use Data::Dumper; $Data::Dumper::Useqq=1; my $host = "192.168.1.36"; # Your Cube-IP or hostame Here! my $port = "80"; my $devices = "5"; my $handle = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port ) // die("ERROR open Socket $host:$port ($!)\n"); $handle->blocking(0); binmode($handle); while(1) { my $finished = 0; my $time=time(); my $buffer=''; print "Send2\n"; while(time() < $time+20 && $finished==0) { my $line=''; $handle->read($line,4096); $finished=1 if(index($buffer,'L:')!=-1); $buffer.=$line if(length($line)); } if(!$finished) { print "No Connection\n"; next; } print $buffer; sleep(1); print "Send\n"; $handle->send("l:\n"); } $handle->close();
Quotealso ich kann da machne was ich will. Unter Telnet brauche ich nur l:(Enter) schicken und alles klappt unter Perl kommt nix rein. Habe mir folgendes Skript zum Testen geschrieben. Aber kein Erfolg. Vielleicht hat jemand ja einen Tipp: