Thread Kontinuierlich Net-Stream anzeigen
(29 answers)
Opened by kami at 2011-11-09 13:05
Hi,
das klappt leider auch nicht nun ist der $buffer immer leer. Gruß kami So sieht das Skript jetzt aus: Code (perl): (dl
)
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); } Last edited: 2011-11-10 18:41:48 +0100 (CET) |