2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-15 22:26:04 +00:00

98_CDCOpenData.pm: Cron Timer bei Systemstart nicht korrekt

git-svn-id: https://svn.fhem.de/fhem/trunk@28155 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jowiemann 2023-11-13 09:01:41 +00:00
parent 23f574797f
commit 892974558b

View File

@ -52,10 +52,8 @@ use warnings;
use Blocking;
use HttpUtils;
my $ModulVersion = "01.10";
my $ModulVersion = "01.10a";
my $missingModul = "";
my $GunzipError;
my $Bunzip2Error;
sub CDCOpenData_Log($$$);
sub CDCOpenData_Initialize($);
@ -63,14 +61,14 @@ sub CDCOpenData_Readout_Add_Reading ($$$$@);
sub CDCOpenData_Readout_Process($$);
#eval "use Net::FTP;1" or $missingModul .= "Net::FTP ";
eval "use IO::Uncompress::Gunzip qw(gunzip $GunzipError);1" or $missingModul .= "IO::Uncompress::Gunzip install: sudo apt-get install libio-compress-perl ";
eval "use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error);1" or $missingModul .= "IO::Uncompress::Bunzip2 install: sudo apt-get install libio-compress-perl ";
eval "use Archive::Tar;1" or $missingModul .= "Archive::Tar install: sudo apt-get install libarchive-extract-perl ";
eval "use Net::SSLGlue::FTP;1" or $missingModul .= "Net::SSLGlue::FTP install: sudo apt-get install libnet-sslglue-perl ";
eval "use POSIX;1" or $missingModul .= "POSIX install: sudo apt-get install libtemplate-plugin-posix-perl ";
eval "use File::Path;1" or $missingModul .= "File::Path not available ";
eval "use FHEM::Scheduler::Cron;1" or $missingModul .= "FHEM::Scheduler::Cron: update Fhem ";
eval "use List::Util qw(pairs);1" or $missingModul .= "List::Util: update Perl ";
eval "use IO::Uncompress::Gunzip qw(gunzip);1" or $missingModul .= "IO::Uncompress::Gunzip install: sudo apt-get install libio-compress-perl ";
eval "use IO::Uncompress::Bunzip2 qw(bunzip2);1" or $missingModul .= "IO::Uncompress::Bunzip2 install: sudo apt-get install libio-compress-perl ";
eval "use Archive::Tar;1" or $missingModul .= "Archive::Tar install: sudo apt-get install libarchive-extract-perl ";
eval "use Net::SSLGlue::FTP;1" or $missingModul .= "Net::SSLGlue::FTP install: sudo apt-get install libnet-sslglue-perl ";
eval "use POSIX;1" or $missingModul .= "POSIX install: sudo apt-get install libtemplate-plugin-posix-perl ";
eval "use File::Path;1" or $missingModul .= "File::Path not available ";
eval "use FHEM::Scheduler::Cron;1" or $missingModul .= "FHEM::Scheduler::Cron: update Fhem ";
eval "use List::Util qw(pairs);1" or $missingModul .= "List::Util: update Perl ";
# FIFO Buffer for commands
my @cmdBuffer=();
@ -199,7 +197,9 @@ sub CDCOpenData_Define($$)
# Vorbereitung für CRON Prozess
$hash->{'CONFIG'}->{'IN_REQUEST'} = 0;
$hash->{'CONFIG'}->{'CRON'} = \'0 * * * *';
my $cron = AttrVal($name, 'cronTime', '0 * * * *');
$hash->{'CONFIG'}->{'CRON'} = \$cron;
CDCOpenData_Log $name, 4, "start timer: CDCOpenData_Readout_Start -> hash";
InternalTimer(gettimeofday() + 1, \&CDCOpenData_Cron_Run, $hash, 0);
@ -608,7 +608,7 @@ sub CDCOpenData_Cron_Run($)
} else {
my $cron = AttrVal($name, 'interval', '0 * * * *');
my $cron = AttrVal($name, 'cronTime', '0 * * * *');
$hash->{'CONFIG'}->{'CRON'} = \$cron;
my $err;
@ -633,8 +633,6 @@ sub CDCOpenData_Set($$@)
my $resultStr = "";
my $list = " update:noArg";
# . " Set_2"
# . " ";
if ( lc $cmd eq 'update' ) {
CDCOpenData_Log $hash, 3, "set $name $cmd " . join(" ", @val);
@ -642,19 +640,6 @@ sub CDCOpenData_Set($$@)
CDCOpenData_Readout_Start($hash->{helper}{TimerReadout});
$hash->{fhem}{UPDATE} = 0;
return undef;
} elsif ( lc $cmd eq 'set_1') {
if (int @val >= 0 && int @val <= 2) {
CDCOpenData_Log $hash, 3, "set $name $cmd " . join(" ", @val);
push @cmdBuffer, "call " . join(" ", @val);
return CDCOpenData_Set_Cmd_Start $hash->{helper}{TimerCmd};
}
}
elsif ( lc $cmd eq 'set_2' ) {
CDCOpenData_Log $hash, 3, "set $name $cmd " . join(" ", @val);
push @cmdBuffer, "rescanwlanneighbors " . join(" ", @val);
return CDCOpenData_Set_Cmd_Start $hash->{helper}{TimerCmd};
}
return "Unknown argument $cmd or wrong parameter(s), choose one of $list";
@ -959,9 +944,11 @@ sub CDCOpenData_get_RegenRadar_atLocations($$$$) {
CDCOpenData_Log $name, 3, "ftp login failed: $ftp->message";
if ($fromGet) {
$ftp->quit;
$returnStr = "ERROR: ftp login failed: " . $ftp->message;
return $returnStr;
} else {
$ftp->quit;
$returnStr = "Error|ftp login failed: " . $ftp->message;
$returnStr .= "|" . join('|', @roReadings ) if int @roReadings;
return $returnStr;
@ -1009,9 +996,13 @@ sub CDCOpenData_get_RegenRadar_atLocations($$$$) {
my $uncompressed_fh;
unless ( $uncompressed_fh = IO::Uncompress::Bunzip2->new($remote_tar_bz2_file_handle) ) {
if ($fromGet) {
close $remote_tar_bz2_file_handle;
$ftp->quit;
$returnStr = "ERROR: IO::Uncompress::Bunzip2 failed: $IO::Uncompress::Bunzip2::Bunzip2Error";
return $returnStr;
} else {
close $remote_tar_bz2_file_handle;
$ftp->quit;
$returnStr = "Error|IO::Uncompress::Bunzip2 failed: $IO::Uncompress::Bunzip2::Bunzip2Error";
$returnStr .= "|" . join('|', @roReadings ) if int @roReadings;
return $returnStr;
@ -1058,6 +1049,8 @@ sub CDCOpenData_get_RegenRadar_atLocations($$$$) {
$file_content = $tar->get_content($file);
if ($file_content) {
my $rName = $geoName . ":" . $timestamp;
# find index of ETX character (it marks the end of the header)
$ETX_index = index($file_content,"\x03");
@ -1065,16 +1058,15 @@ sub CDCOpenData_get_RegenRadar_atLocations($$$$) {
# unpack the little-endian number and mask out bits 13..16
# unit of precipitation is 0.01 ltr/m²/h
# $rain_forecast = 0.01*(unpack( 'v*', $rain_forecast ) & 0xFFF);
$rain_forecast = unpack( 'v*', $rain_forecast ) & 0xFFF;
my $rName = $geoName . ":" . $timestamp;
$rain_forecast = unpack( 'v*', $rain_forecast ) & 0xFFF;
# A value of 2500 in the file marks invalid data.
# It is reset to -1 in order to keep the y-axis scale small when plotting.
if ($rain_forecast == 2500) {
$rain_forecast = -1 ;
CDCOpenData_Log $name, 3, "Regen Radar: " . $rName . ": fehlerhafter Wert:";
CDCOpenData_Log $name, 3, "Regen Radar: " . $rName . ": error in value";
} else {
$rain_forecast *= 0.01;
}
@ -1089,14 +1081,13 @@ sub CDCOpenData_get_RegenRadar_atLocations($$$$) {
}
}
}
#close $fh;
# Close the file handles
close $uncompressed_fh;
close $remote_tar_bz2_file_handle;
}
$ftp->quit;
close $remote_tar_bz2_file_handle;
CDCOpenData_Log $name, 5, "################ End get_RegenRadar_atLocations ################";
@ -1153,9 +1144,11 @@ sub CDCOpenData_Readout_Run_Rain_Since_Midnight ($@) {
CDCOpenData_Log $name, 3, "ftp login failed: $ftp->message";
if ($fromGet) {
$ftp->quit;
$returnStr = "ERROR: ftp login failed: " . $ftp->message;
return $returnStr;
} else {
$ftp->quit;
$returnStr = "Error|ftp login failed: " . $ftp->message;
$returnStr .= "|" . join('|', @roReadings ) if int @roReadings;
return $returnStr;
@ -1274,15 +1267,13 @@ sub CDCOpenData_Readout_Run_Rain_Since_Midnight ($@) {
my $twobytes = get_2bytes_from_binfile($tmpDir . $localname, $index);
# unpack the little-endian number and mask out bits 13..16:
# $regenmenge += 0.1 * (unpack( 'v*', $twobytes ) & 0xFFF);
my $upMenge = (unpack( 'v*', $twobytes ) & 0xFFF);
# A value of 2500 in the file marks invalid data.
# It is reset to -1 in order to keep the y-axis scale small when plotting.
if ($upMenge == 2500) {
CDCOpenData_Log $name, 3, "Rain_Since_Midnight: fehlerhafter Wert:";
CDCOpenData_Log $name, 3, "Rain_Since_Midnight: error in value";
} else {
$regenmenge += 0.1 * $upMenge;
}
@ -1384,9 +1375,11 @@ sub CDCOpenData_Readout_Run_getRain($@)
CDCOpenData_Log $name, 3, "ftp login failed: $ftp->message";
if ($fromGet) {
$ftp->quit;
$returnStr = "ERROR: ftp login failed: $ftp->message";
return $returnStr;
} else {
$ftp->quit;
$returnStr = "Error|ftp login failed: " . $ftp->message;
$returnStr .= "|" . join('|', @roReadings ) if int @roReadings;
return $returnStr;
@ -1481,7 +1474,6 @@ sub CDCOpenData_Readout_Run_getRain($@)
# unpack the little-endian number and mask out bits 13..16
# unit of precipitation is 0.1 ltr/m²:
# $regenmenge = 0.1*(unpack( 'v*', $regenmenge ) & 0xFFF);
$regenmenge = unpack( 'v*', $regenmenge ) & 0xFFF;