#!/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); }