diff --git a/fhem/CHANGED b/fhem/CHANGED index fa928ce03..86b1b3d2a 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 93_DbLog: new Events FRAME_INITIALIZED, SUBPROC_INITIALIZED, + SUBPROC_DISCONNECTED, SUBPROC_STOPPED + (Forum: #133403.0) - feature: 48_MieleAtHome: support optional event-api - bugfix: 72_FRITZBOX: weitere Stabilisierung - feature: 72_FRITZBOX: neue Readings diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index 8307f3cc7..4ab379127 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -38,6 +38,8 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern by DS_Starter: my %DbLog_vNotesIntern = ( + "5.8.7" => "01.05.2023 new Events FRAME_INITIALIZED, SUBPROC_INITIALIZED, SUBPROC_DISCONNECTED, SUBPROC_STOPPED ". + "Forum: https://forum.fhem.de/index.php?topic=133403.0, minor fixes ", "5.8.6" => "25.03.2023 change _DbLog_plotData (intx), Plot Editor: include functions delta-h, delta-h, ...". "remove setter deleteOldDaysNbl, reduceLogNbl ", "5.8.5" => "16.03.2023 fix using https in configCheck after SVN server change ", @@ -263,6 +265,7 @@ sub DbLog_Define { $hash->{HELPER}{OLDSTATE} = 'initialized'; $hash->{HELPER}{MODMETAABSENT} = 1 if($modMetaAbsent); # Modul Meta.pm nicht vorhanden + DbLog_setSchemeTable ($hash, ''); # Tabellen initial setzen DbLog_setVersionInfo ($hash); # Versionsinformationen setzen $hash->{PID} = $$; # remember PID for plotfork @@ -275,8 +278,6 @@ sub DbLog_Define { return $ret; } - InternalTimer(gettimeofday()+2, 'DbLog_setinternalcols', $hash, 0); # set used COLUMNS - DbLog_setReadingstate ($hash, 'waiting for connection'); DbLog_SBP_CheckAndInit ($hash, 1); # SubProcess starten - direkt nach Define !! um wenig Speicher zu allokieren _DbLog_initOnStart ($hash); # von init_done abhängige Prozesse initialisieren @@ -313,16 +314,15 @@ sub _DbLog_initOnStart { readingsDelete ($hash, $r); } - DbLog_setSchemeTable ($hash); - notifyRegexpChanged ($hash, $hash->{REGEXP}); # nur Events dieser Devices an NotifyFn weiterleiten, NOTIFYDEV wird gesetzt wenn möglich - DbLog_SBP_CheckAndInit ($hash); - - my $rst = DbLog_SBP_sendConnectionData ($hash); # Verbindungsdaten an SubProzess senden - if (!$rst) { - Log3 ($name, 3, "DbLog $name - DB connection parameters are initialized in the SubProcess"); - } - - DbLog_execMemCacheAsync ($hash); # InternalTimer DbLog_execMemCacheAsync starten + DbLog_setSchemeTable ($hash); # Tabellenschema nach Laden Attr neu setzen + notifyRegexpChanged ($hash, $hash->{REGEXP}); # nur Events dieser Devices an NotifyFn weiterleiten, NOTIFYDEV wird gesetzt wenn möglich + DbLog_setinternalcols ($hash); # verwendete Feldlängen setzen + + DoTrigger ($name, 'FRAME_INITIALIZED', 1); + + DbLog_SBP_CheckAndInit ($hash); + DbLog_SBP_sendConnectionData ($hash); # Verbindungsdaten an SubProzess senden + DbLog_execMemCacheAsync ($hash); # InternalTimer DbLog_execMemCacheAsync starten return; } @@ -456,7 +456,7 @@ sub DbLog_Attr { if ($aName =~ /SQLite/xs) { if ($init_done == 1) { DbLog_SBP_sendDbDisconnect ($hash, 1); # DB Verbindung und Verbindungsdaten im SubProzess löschen - InternalTimer(gettimeofday()+2.0, 'DbLog_SBP_sendConnectionData', $hash, 0); # neue Verbindungsdaten an SubProzess senden + InternalTimer(gettimeofday()+0.8, 'DbLog_SBP_sendConnectionData', $hash, 0); # neue Verbindungsdaten an SubProzess senden } } @@ -464,13 +464,16 @@ sub DbLog_Attr { if ($cmd eq "set" && $aVal) { unless ($aVal =~ /^[0-9]+$/) { return " The Value of $aName is not valid. Use only figures 0-9 !";} } - InternalTimer(gettimeofday()+0.5, "DbLog_setinternalcols", $hash, 0); + + if ($init_done == 1) { + InternalTimer(gettimeofday()+0.8, "DbLog_setinternalcols", $hash, 0); + } } if($aName eq 'asyncMode') { if ($cmd eq "set" && $aVal) { $hash->{MODE} = 'asynchronous'; - InternalTimer(gettimeofday()+2, 'DbLog_execMemCacheAsync', $hash, 0); + InternalTimer(gettimeofday()+0.8, 'DbLog_execMemCacheAsync', $hash, 0); } else { $hash->{MODE} = 'synchronous'; @@ -492,7 +495,7 @@ sub DbLog_Attr { if ($init_done == 1) { DbLog_SBP_sendDbDisconnect ($hash, 1); # DB Verbindung und Verbindungsdaten im SubProzess löschen - InternalTimer(gettimeofday()+2.0, 'DbLog_SBP_sendConnectionData', $hash, 0); # neue Verbindungsdaten an SubProzess senden + InternalTimer(gettimeofday()+0.8, 'DbLog_SBP_sendConnectionData', $hash, 0); # neue Verbindungsdaten an SubProzess senden } } @@ -523,7 +526,7 @@ sub DbLog_Attr { DbLog_setReadingstate ($hash, $val); if ($do == 0) { - InternalTimer(gettimeofday()+2, "_DbLog_initOnStart", $hash, 0); + InternalTimer(gettimeofday()+0.8, "_DbLog_initOnStart", $hash, 0); } } @@ -544,7 +547,7 @@ sub DbLog_Attr { if ($init_done == 1) { DbLog_SBP_sendDbDisconnect ($hash, 1); # DB Verbindung und Verbindungsdaten im SubProzess löschen - InternalTimer(gettimeofday()+2.0, 'DbLog_SBP_sendConnectionData', $hash, 0); # neue Verbindungsdaten an SubProzess senden + InternalTimer(gettimeofday()+0.8, 'DbLog_SBP_sendConnectionData', $hash, 0); # neue Verbindungsdaten an SubProzess senden } } @@ -5383,7 +5386,7 @@ sub DbLog_SBP_CleanUp { #$subprocess->wait(); kill 'SIGKILL', $pid; - waitpid($pid, 0); + waitpid ($pid, 0); Log3 ($name, 2, qq{DbLog $name - SubProcess PID >$pid< stopped}); @@ -5393,6 +5396,8 @@ sub DbLog_SBP_CleanUp { delete $hash->{HELPER}{LONGRUN_PID}; $hash->{SBP_STATE} = "Stopped"; + + DoTrigger ($name, 'SUBPROC_STOPPED', 1); return; } @@ -5498,9 +5503,23 @@ sub DbLog_SBP_Read { if ($oper =~ /reduceLog/xs) { readingsSingleUpdate($hash, 'reduceLogState', $ret->{res}, 1) if($ret->{res}); } + + ## sendDbConnectData - Read + ############################# + if ($oper =~ /sendDbConnectData/xs) { + Log3 ($name, 3, "DbLog $name - DB connection parameters are initialized in the SubProcess"); + + DoTrigger ($name, 'SUBPROC_INITIALIZED', 1); + } + + ## dbDisconnect - Read + ######################## + if ($oper =~ /dbDisconnect/xs) { + DoTrigger ($name, 'SUBPROC_DISCONNECTED', 1); + } if(AttrVal($name, 'showproctime', 0) && $ot) { - my ($rt,$brt) = split(",", $ot); + my ($rt,$brt) = split ",", $ot; readingsBeginUpdate ($hash); readingsBulkUpdate ($hash, 'background_processing_time', sprintf("%.4f",$brt)); @@ -8279,6 +8298,7 @@ return @v; ################################################################ sub DbLog_setinternalcols { my $hash = shift; + my $name = $hash->{NAME}; $hash->{HELPER}{DEVICECOL} = $DbLog_columns{DEVICE}; @@ -8512,7 +8532,6 @@ sub DbLog_sampleDataFn { no warnings 'uninitialized'; # Forum:74690, bug unitialized $ret .= SVG_sel ("par_${r}_0", $cols, "$f[0]:$f[1]"); # par__, , - use warnings; $ret .= SVG_sel ("par_${r}_3", $dblog_svgfnset, $f[3]); # Funktionsauswahl @@ -8520,6 +8539,7 @@ sub DbLog_sampleDataFn { $ret .= SVG_txt ("par_${r}_4", "
", "$2", $pifl); # RegExp (z.B. $val=~s/^Total..([\d.]*).*/$1/eg) $ret .= SVG_txt ("par_${r}_2", "", $f[2], 1); # der Defaultwert (nicht ausgewertet) + use warnings; push @htmlArr, $ret; } @@ -8536,11 +8556,11 @@ sub DbLog_sampleDataFn { no warnings 'uninitialized'; # Forum:74690, bug unitialized $ret .= SVG_txt ("par_${r}_0", "", "$f[0]:$f[1]::$f[3]", $pifl); # letzter Wert -> Breite der Eingabezeile - use warnings; $f[4] =~ /^(:+)?(.*)/xs; $ret .= SVG_txt ("par_${r}_3", "
", "$2", $pifl); # RegExp (z.B. $val=~s/^Total..([\d.]*).*/$1/eg) - + use warnings; + push @htmlArr, $ret; } } @@ -8799,6 +8819,25 @@ return; That means in this example you have to use: \@,\$ respectively \%.

+ + DbLog specific events

+ + DbLog generates events depending on the initialisation status of the DbLog device: +
+
+ +
    + + + + + + +
    FRAME_INITIALIZED - The basic framework is initialised. Blocking (Get) commands can be executed.
    SUBPROC_INITIALIZED - The SupProcess is ready for use. Non-blocking (set) commands and Data logging can be executed.
    SUBPROC_DISCONNECTED - The SupProcess was separated from the DB.
    SUBPROC_STOPPED - The SupProcess has been stopped.
    +
+ +
+

@@ -10639,6 +10678,25 @@ attr SMA_Energymeter DbLogValueFn Das heißt in diesem Beispiel wäre zu verwenden: \@,\$ bzw. \%.

+ + DbLog spezifische Events

+ + DbLog generiert Events abhängig vom Initialisierungsstatus des DbLog-Devices: +
+
+ +
    + + + + + + +
    FRAME_INITIALIZED - Das grundlegende Rahmenwerk ist initialisiert. Blockierend arbeitende (Get)-Kommandos können ausgeführt werden.
    SUBPROC_INITIALIZED - Der SupProcess ist einsatzbereit. Nichtblockierend arbeitende (Set)-Kommandos und Daten Logging können ausgeführt werden.
    SUBPROC_DISCONNECTED - Der SupProcess wurde von der DB getrennt.
    SUBPROC_STOPPED - Der SupProcess wurde gestoppt.
    +
+ +
+