mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
38_Broadlink.pm: Improved logging
git-svn-id: https://svn.fhem.de/fhem/trunk@14362 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0768193de3
commit
7d67c9c38d
@ -208,16 +208,16 @@ sub Broadlink_send_data(@) {
|
|||||||
push @broadlink_payload, unpack("C*", $val);
|
push @broadlink_payload, unpack("C*", $val);
|
||||||
}
|
}
|
||||||
my $msg = "Try to send a command: " . $cmdname;
|
my $msg = "Try to send a command: " . $cmdname;
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $response = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
my $response = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
||||||
if (length($response) > 0 && $response ne "xxx") {
|
if (length($response) > 0 && $response ne "xxx") {
|
||||||
readingsSingleUpdate ( $hash, "lastCommandSend", $cmdname, 1 );
|
readingsSingleUpdate ( $hash, "lastCommandSend", $cmdname, 1 );
|
||||||
my $msg = $cmdname ." send";
|
my $msg = $cmdname ." send";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
} else {
|
} else {
|
||||||
readingsSingleUpdate ( $hash, "connectionErrorOn", "sendCommand: " . $cmdname, 1 );
|
readingsSingleUpdate ( $hash, "connectionErrorOn", "sendCommand: " . $cmdname, 1 );
|
||||||
my $msg = $cmdname . " command send failed - device not connected?";
|
my $msg = $cmdname . " command send failed - device not connected?";
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = $msg;
|
$hash->{STATE} = $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,14 +227,14 @@ sub Broadlink_check_data(@) {
|
|||||||
my @broadlink_payload = ((0) x 16);
|
my @broadlink_payload = ((0) x 16);
|
||||||
$broadlink_payload[0] = 4;
|
$broadlink_payload[0] = 4;
|
||||||
my $msg = "check for new command";
|
my $msg = "check for new command";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
||||||
#length must be bigger than 0x38, if not, cant get substring with data
|
#length must be bigger than 0x38, if not, cant get substring with data
|
||||||
if (length($data) > 0x38 && $data ne "xxx") {
|
if (length($data) > 0x38 && $data ne "xxx") {
|
||||||
my $err = unpack("C*", substr($data, 0x22, 1)) | (unpack("C*", substr($data, 0x23, 1)) << 8);
|
my $err = unpack("C*", substr($data, 0x22, 1)) | (unpack("C*", substr($data, 0x23, 1)) << 8);
|
||||||
if ($err == 0) {
|
if ($err == 0) {
|
||||||
my $msg = "new command found";
|
my $msg = "new command found";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $enc_payload = substr($data, 0x38);
|
my $enc_payload = substr($data, 0x38);
|
||||||
my $cipher = Broadlink_getCipher($hash);
|
my $cipher = Broadlink_getCipher($hash);
|
||||||
my $decodedData = $cipher->decrypt($enc_payload);
|
my $decodedData = $cipher->decrypt($enc_payload);
|
||||||
@ -247,21 +247,21 @@ sub Broadlink_check_data(@) {
|
|||||||
return substr($decodedData, 4);
|
return substr($decodedData, 4);
|
||||||
} else {
|
} else {
|
||||||
my $msg = "Error receiving command";
|
my $msg = "Error receiving command";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
my $msg = "no new command data found - data length: " . length($data);
|
my $msg = "no new command data found - data length: " . length($data);
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = $msg;
|
$hash->{STATE} = $msg;
|
||||||
}
|
}
|
||||||
$hash->{'.broadlink_checkCommands'}++;
|
$hash->{'.broadlink_checkCommands'}++;
|
||||||
if ($hash->{'.broadlink_checkCommands'} < 15) {
|
if ($hash->{'.broadlink_checkCommands'} < 15) {
|
||||||
my $msg = "no command recorded. retry count:" . $hash->{'.broadlink_checkCommands'};
|
my $msg = "no command recorded. retry count:" . $hash->{'.broadlink_checkCommands'};
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
InternalTimer(gettimeofday()+2, "Broadlink_check_data", $hash);
|
InternalTimer(gettimeofday()+2, "Broadlink_check_data", $hash);
|
||||||
} else {
|
} else {
|
||||||
my $msg = "no command recorded even after a lot of retries. Try to learn again";
|
my $msg = "no command recorded even after a lot of retries. Try to learn again";
|
||||||
Log3 $hash->{NAME}, 3, $msg;
|
Log3 $hash->{NAME}, 3, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = $msg;
|
$hash->{STATE} = $msg;
|
||||||
readingsSingleUpdate ( $hash, "lastFailedRecordedCommand", $hash->{'.newcommandname'}, 1 );
|
readingsSingleUpdate ( $hash, "lastFailedRecordedCommand", $hash->{'.newcommandname'}, 1 );
|
||||||
}
|
}
|
||||||
@ -273,14 +273,14 @@ sub Broadlink_sp3_getStatus(@) {
|
|||||||
my @broadlink_payload = ((0) x 16);
|
my @broadlink_payload = ((0) x 16);
|
||||||
$broadlink_payload[0] = 1;
|
$broadlink_payload[0] = 1;
|
||||||
my $msg = "sp3_status request";
|
my $msg = "sp3_status request";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
||||||
#length must be bigger than 0x38, if not, cant get substring with data
|
#length must be bigger than 0x38, if not, cant get substring with data
|
||||||
if (length($data) > 0x38 && $data ne "xxx") {
|
if (length($data) > 0x38 && $data ne "xxx") {
|
||||||
my $err = unpack("C*", substr($data, 0x22, 1)) | (unpack("C*", substr($data, 0x23, 1)) << 8);
|
my $err = unpack("C*", substr($data, 0x22, 1)) | (unpack("C*", substr($data, 0x23, 1)) << 8);
|
||||||
if ($err == 0) {
|
if ($err == 0) {
|
||||||
my $msg = "sp3 receiving status - data length: " . length($data);
|
my $msg = "sp3 receiving status - data length: " . length($data);
|
||||||
Log3 $hash->{NAME}, 1, $msg;
|
Log3 $hash->{NAME}, 1, $hash->{NAME} . ": " . $msg;
|
||||||
my $enc_payload = substr($data, 0x38);
|
my $enc_payload = substr($data, 0x38);
|
||||||
my $cipher = Broadlink_getCipher($hash);
|
my $cipher = Broadlink_getCipher($hash);
|
||||||
my $decodedData = $cipher->decrypt($enc_payload);
|
my $decodedData = $cipher->decrypt($enc_payload);
|
||||||
@ -291,13 +291,13 @@ sub Broadlink_sp3_getStatus(@) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
my $msg = "Error receiving status";
|
my $msg = "Error receiving status";
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = "unknown";
|
$hash->{STATE} = "unknown";
|
||||||
readingsSingleUpdate ( $hash, "connectionErrorOn", "geStatusWithData", 1 );
|
readingsSingleUpdate ( $hash, "connectionErrorOn", "geStatusWithData", 1 );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
my $msg = "no new command data found - data length: " . length($data);
|
my $msg = "no new command data found - data length: " . length($data);
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = "unknown";
|
$hash->{STATE} = "unknown";
|
||||||
readingsSingleUpdate ( $hash, "connectionErrorOn", "geStatus", 1 );
|
readingsSingleUpdate ( $hash, "connectionErrorOn", "geStatus", 1 );
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ sub Broadlink_sp3_setPower(@) {
|
|||||||
$broadlink_payload[4] = 0;
|
$broadlink_payload[4] = 0;
|
||||||
}
|
}
|
||||||
my $msg = "sp3_status request";
|
my $msg = "sp3_status request";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
||||||
if (length($data) > 0 && $data ne "xxx") {
|
if (length($data) > 0 && $data ne "xxx") {
|
||||||
if ($on == 1) {
|
if ($on == 1) {
|
||||||
@ -325,7 +325,7 @@ sub Broadlink_sp3_setPower(@) {
|
|||||||
} else {
|
} else {
|
||||||
readingsSingleUpdate ( $hash, "connectionErrorOn", "powerChange", 1 );
|
readingsSingleUpdate ( $hash, "connectionErrorOn", "powerChange", 1 );
|
||||||
my $msg = "powerChange - device not connected?";
|
my $msg = "powerChange - device not connected?";
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = "unkown";
|
$hash->{STATE} = "unkown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,18 +335,18 @@ sub Broadlink_enterLearning(@) {
|
|||||||
my @broadlink_payload = ((0) x 16);
|
my @broadlink_payload = ((0) x 16);
|
||||||
$broadlink_payload[0] = 3;
|
$broadlink_payload[0] = 3;
|
||||||
my $msg = "learn new commadn for " . $cmdname;
|
my $msg = "learn new commadn for " . $cmdname;
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
my $data = Broadlink_send_packet($hash, 0x6a, @broadlink_payload);
|
||||||
if (length($data) > 0 && $data ne "xxx") {
|
if (length($data) > 0 && $data ne "xxx") {
|
||||||
$hash->{'.broadlink_checkCommands'} = 0;
|
$hash->{'.broadlink_checkCommands'} = 0;
|
||||||
$hash->{'.newcommandname'} = $cmdname;
|
$hash->{'.newcommandname'} = $cmdname;
|
||||||
my $msg = "start polling for " . $cmdname;
|
my $msg = "start polling for " . $cmdname;
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
InternalTimer(gettimeofday()+2, "Broadlink_check_data", $hash);
|
InternalTimer(gettimeofday()+2, "Broadlink_check_data", $hash);
|
||||||
} else {
|
} else {
|
||||||
readingsSingleUpdate ( $hash, "connectionErrorOn", "enterLearning", 1 );
|
readingsSingleUpdate ( $hash, "connectionErrorOn", "enterLearning", 1 );
|
||||||
my $msg = "command learn failed - device not connected?";
|
my $msg = "command learn failed - device not connected?";
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = $msg;
|
$hash->{STATE} = $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,7 +382,7 @@ sub Broadlink_auth(@) {
|
|||||||
$broadlink_payload[0x36] = ord('1');
|
$broadlink_payload[0x36] = ord('1');
|
||||||
|
|
||||||
my $msg = "try to authenticate";
|
my $msg = "try to authenticate";
|
||||||
Log3 $hash->{NAME}, 5, $msg;
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . $msg;
|
||||||
my $response = Broadlink_send_packet($hash, 0x65, @broadlink_payload);
|
my $response = Broadlink_send_packet($hash, 0x65, @broadlink_payload);
|
||||||
if (length($response) > 0x38 && $response ne "xxx") {
|
if (length($response) > 0x38 && $response ne "xxx") {
|
||||||
my $enc_payload = substr($response, 0x38);
|
my $enc_payload = substr($response, 0x38);
|
||||||
@ -395,7 +395,7 @@ sub Broadlink_auth(@) {
|
|||||||
} else {
|
} else {
|
||||||
readingsSingleUpdate ( $hash, "lastAuthenticationFailed", "", 1 );
|
readingsSingleUpdate ( $hash, "lastAuthenticationFailed", "", 1 );
|
||||||
my $msg = "authentication failed - device not connected? - response length: " . length($response);
|
my $msg = "authentication failed - device not connected? - response length: " . length($response);
|
||||||
Log3 $hash->{NAME}, 4, $msg;
|
Log3 $hash->{NAME}, 4, $hash->{NAME} . ": " . $msg;
|
||||||
$hash->{STATE} = $msg;
|
$hash->{STATE} = $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ sub Broadlink_send_packet(@) {
|
|||||||
ReuseAddr => 1,
|
ReuseAddr => 1,
|
||||||
Timeout => $timeout,
|
Timeout => $timeout,
|
||||||
#Blocking => 0
|
#Blocking => 0
|
||||||
) or Log3 $hash->{NAME}, 5, "Problem with socket";
|
) or Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . "Problem with socket";
|
||||||
|
|
||||||
my $select = IO::Select->new($socket) if $socket;
|
my $select = IO::Select->new($socket) if $socket;
|
||||||
|
|
||||||
@ -507,15 +507,15 @@ sub Broadlink_send_packet(@) {
|
|||||||
if ($select->can_read($timeout)) {
|
if ($select->can_read($timeout)) {
|
||||||
$socket->recv($data, 1024);
|
$socket->recv($data, 1024);
|
||||||
} else {
|
} else {
|
||||||
Log3 $hash->{NAME}, 5, "can't read";
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . "can't read";
|
||||||
}
|
}
|
||||||
$socket->close();
|
$socket->close();
|
||||||
alarm 0;
|
alarm 0;
|
||||||
};
|
};
|
||||||
alarm 0; # race condition protection
|
alarm 0; # race condition protection
|
||||||
Log3 $hash->{NAME}, 3, 'Error Timout' if ( $@ && $@ =~ /Timed Out/ );
|
Log3 $hash->{NAME}, 3, $hash->{NAME} . ": " . 'Error Timout' if ( $@ && $@ =~ /Timed Out/ );
|
||||||
Log3 $hash->{NAME}, 3, "Error: Eval corrupted: $@" if $@;
|
Log3 $hash->{NAME}, 3, $hash->{NAME} . ": " . "Error: Eval corrupted: $@" if $@;
|
||||||
Log3 $hash->{NAME}, 5, length($data) . " bytes received from socket";
|
Log3 $hash->{NAME}, 5, $hash->{NAME} . ": " . length($data) . " bytes received from socket";
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,7 +554,7 @@ sub Broadlink_Save(@) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
my $msg = "Broadlink_Save: Cannot open $statefile: $!";
|
my $msg = "Broadlink_Save: Cannot open $statefile: $!";
|
||||||
Log3 $hash->{NAME}, 1, $msg;
|
Log3 $hash->{NAME}, 1, $hash->{NAME} . ": " . $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -586,7 +586,7 @@ sub Broadlink_Load(@) {
|
|||||||
$hash->{commandList} = $decoded;
|
$hash->{commandList} = $decoded;
|
||||||
} else {
|
} else {
|
||||||
my $msg = "Broadlink_Load: Cannot open $statefile: $!";
|
my $msg = "Broadlink_Load: Cannot open $statefile: $!";
|
||||||
Log3 $hash->{NAME}, 1, $msg;
|
Log3 $hash->{NAME}, 1, $hash->{NAME} . ": " . $msg;
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user