From de1cc4ea3ca86947bffd0c220f720ca196d4f044 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Fri, 9 May 2008 13:58:10 +0000 Subject: [PATCH] Multiline extension, pgm2 reordering git-svn-id: https://svn.fhem.de/fhem/trunk@168 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 7 +- fhem/FHEM/90_at.pm | 9 +- fhem/FHEM/91_notify.pm | 15 +-- fhem/FHEM/92_FileLog.pm | 82 ++++++++++++- fhem/HISTORY | 28 +++++ fhem/docs/commandref.html | 15 ++- fhem/docs/fritzbox.html | 11 +- fhem/fhem.pl | 65 +++++----- fhem/webfrontend/pgm2/01_FHEMWEB.pm | 178 ++++++++++++++++------------ fhem/webfrontend/pgm2/em.gplot | 12 +- fhem/webfrontend/pgm2/fht.gplot | 21 ++-- fhem/webfrontend/pgm2/fs20.gplot | 11 +- fhem/webfrontend/pgm2/ks300_1.gplot | 31 ++++- fhem/webfrontend/pgm2/ks300_2.gplot | 2 +- fhem/webfrontend/pgm2/ks300_3.gplot | 2 +- fhem/webfrontend/pgm2/mpiri.gplot | 19 +-- fhem/webfrontend/pgm2/piri.gplot | 2 +- 17 files changed, 355 insertions(+), 155 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index d1b1c7136..07d88e1a1 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -384,6 +384,7 @@ - feature: contrib/00_LIRC.pm (25.3, by Bernhard) - bugfix : 00_FHZ: additional stty settings for strange Linux versions - bugfix : pgm2 wrong temp summary for FHT's (reported by O.D., 16.4.2008) - -- TODO - emem -2.5kW / getDevData for emwz -1 + - feature: FHEM modules may live on a filesystem with "ignorant" casing (FAT) + - feature: FileLog "set reopen" for manual tweaking of logfiles. + - feature: multiline commands are supported through the command line + - feature: pgm2 installation changes, multiple instances, external css diff --git a/fhem/FHEM/90_at.pm b/fhem/FHEM/90_at.pm index 4f48a2bee..9fbcde946 100755 --- a/fhem/FHEM/90_at.pm +++ b/fhem/FHEM/90_at.pm @@ -25,8 +25,8 @@ at_Define($$) my ($name, undef, $tm, $command) = split("[ \t]+", $def, 4); if(!$command) { - if($hash->{CMD}) { - $command = $hash->{CMD}; # Called from modify + if($hash->{OLDDEF}) { # Called from modify, where command is optional + (undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2); $hash->{DEF} = "$tm $command"; } else { return "Usage: define at "; @@ -65,7 +65,6 @@ at_Define($$) } $hash->{NTM} = $ntm if($rel eq "+" || $fn); $hash->{TRIGGERTIME} = $nt; - $hash->{CMD} = SemicolonEscape($command); $nextat = $nt if(!$nextat || $nextat > $nt); $hash->{STATE} = "Next: " . FmtTime($nt); @@ -85,7 +84,9 @@ at_Exec($) } delete $attr{$name}{skip_next} if($skip); - AnalyzeCommandChain(undef, $defs{$name}{CMD}) if(!$skip && !$disable); + my (undef, $command) = split("[ \t]+", $defs{$name}{DEF}, 2); + $command = SemicolonEscape($command); + AnalyzeCommandChain(undef, $command) if(!$skip && !$disable); my $count = $defs{$name}{REP}; my $def = $defs{$name}{DEF}; diff --git a/fhem/FHEM/91_notify.pm b/fhem/FHEM/91_notify.pm index d921ca64a..982671d15 100755 --- a/fhem/FHEM/91_notify.pm +++ b/fhem/FHEM/91_notify.pm @@ -25,17 +25,17 @@ notify_Define($$) my ($type, $name, $re, $command) = split("[ \t]+", $def, 4); if(!$command) { - if($hash->{CMD}) { - $command = $hash->{CMD}; # Called from modify + if($hash->{OLDDEF}) { # Called from modify, where command is optional + (undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2); $hash->{DEF} = "$re $command"; } else { return "Usage: define notify "; } } + # Checking for misleading regexps eval { "Hallo" =~ m/^$re$/ }; return "Bad regexp: $@" if($@); - $hash->{CMD} = SemicolonEscape($command); $hash->{REGEXP} = $re; $hash->{STATE} = "active"; @@ -46,13 +46,13 @@ notify_Define($$) sub notify_Exec($$) { - my ($log, $dev) = @_; + my ($ntfy, $dev) = @_; - my $ln = $log->{NAME}; + my $ln = $ntfy->{NAME}; return "" if($attr{$ln} && $attr{$ln}{disable}); my $n = $dev->{NAME}; - my $re = $log->{REGEXP}; + my $re = $ntfy->{REGEXP}; my $max = int(@{$dev->{CHANGED}}); my $t = $dev->{TYPE}; @@ -61,7 +61,8 @@ notify_Exec($$) my $s = $dev->{CHANGED}[$i]; $s = "" if(!defined($s)); if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/) { - my $exec = $log->{CMD}; + my (undef, $exec) = split("[ \t]+", $ntfy->{DEF}, 2); + $exec = SemicolonEscape($exec); $exec =~ s/%%/____/g; my $extsyntax= 0; diff --git a/fhem/FHEM/92_FileLog.pm b/fhem/FHEM/92_FileLog.pm index 2f4198837..ae06d6486 100755 --- a/fhem/FHEM/92_FileLog.pm +++ b/fhem/FHEM/92_FileLog.pm @@ -11,8 +11,10 @@ FileLog_Initialize($) { my ($hash) = @_; - $hash->{DefFn} = "FileLog_Define"; - $hash->{UndefFn} = "FileLog_Undef"; + $hash->{DefFn} = "FileLog_Define"; + $hash->{SetFn} = "FileLog_Set"; + $hash->{GetFn} = "FileLog_Get"; + $hash->{UndefFn} = "FileLog_Undef"; $hash->{NotifyFn} = "FileLog_Log"; $hash->{AttrFn} = "FileLog_Attr"; # logtype is used by the frontend @@ -101,6 +103,7 @@ FileLog_Log($$) return ""; } +################################### sub FileLog_Attr(@) { @@ -117,4 +120,79 @@ FileLog_Attr(@) return undef; } + +################################### +sub +FileLog_Set($@) +{ + my ($hash, @a) = @_; + + return "no set argument specified" if(int(@a) != 2); + return "Unknown argument $a[1], choose one of reopen" + if($a[1] ne "reopen"); + + my $fh = $hash->{FH}; + my $cn = $hash->{currentlogfile}; + $fh->close(); + $fh = new IO::File ">>$cn"; + return "Can't open $cn" if(!defined($fh)); + $hash->{FH} = $fh; + return undef; +} + +################################### +sub +FileLog_Get($@) +{ + my ($hash, @a) = @_; + + return "Usage: get $a[0] " if(int(@a) != 4); + my $fh = new IO::File $hash->{currentlogfile}; + seekTo($fh, $hash, $a[1]); +# my @arr = + while(my $l = <$fh>) { + last if($l gt $a[2]); + } + close($fh); + return "EOF" if(!defined($data)); + + return $data; +} + +################################### +sub +seekTo($$$) +{ + my ($fh, $hash, $ts) = @_; + + # If its cached + if($hash->{pos} && $hash->{pos}{$ts}) { + $fh->seek($hash->{pos}{$ts}, 0); + return; + } + + $fh->seek(0, 2); # Go to the end + my $upper = $fh->tell; + + my ($lower, $next, $last) = (0, $upper/2, 0); + while() { # Binary search + $fh->seek($next, 0); + my $data = <$fh>; + if($data !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /) { + $next = $fh->tell; + $data = <$fh>; + } + last if($next eq $last); + + $last = $next; + if($data lt $ts) { + ($lower, $next) = ($next, ($next+$upper)/2); + } else { + ($upper, $next) = ($next, ($lower+$next)/2); + } + } + $hash->{pos}{$ts} = $last; + +} + 1; diff --git a/fhem/HISTORY b/fhem/HISTORY index 9279b6046..fe0a6f9db 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -220,3 +220,31 @@ - Peter S. Wed Mar 19 08:24:00 MET 2008 - 00_FHZ.pm: DoTriger -> DoTrigger + +- Rudi Fri May 9 20:00:00 MEST 2008 + - feature: FHEM modules may live on a filesystem with "ignorant" casing (FAT) + If you install FHEM on a USB-Stick (e.g. for the FritzBox) it may happen + that the filename casing is different from the function names inside the file. + -> Fhem won't find the _Initialize function. Fixed by searching all + function-names for a match with "ignore-case" + - feature: FileLog function "set reopen" impemented. In case you want to delete some + wrong entries from a current logfile, you must tell fhem to reopen the file again + - feature: multiline commands are supported through the command line + Up till now multiline commands were supported only by "include". Now they + are supprted from the (tcp/ip) connection too, so they can be used by the + web frontends. + - feature: pgm2 installation changes, multiple instances, external css + pgm2 (FHEMWEB) is now a "real" fhem module: + - the configuration takes place via attributes + - the css file is external, and each FHEMWEB instance can use its own set + - the default location for pictures, gnuplot scripts and css is the FHEM + module directory + - multiline support for notify and at scripts. + + + + + - feature: FileLog "set reopen" for manual tweaking of logfiles. + - feature: multiline commands are supported through the command line + - feature: pgm2 installation changes, multiple instances, external css + diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 278dd47a7..64a5acdc7 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -98,9 +98,9 @@ configuration file at startup). The commands are either executed directly, or later if they are arguments to the at and notify fhem commands.

-If commands are read from a file, then a line ending with \ will be -concatenated with the next one, so long lines (e.g. perl oneliners) can be -split in multiple lines

+A line ending with \ will be concatenated with the next one, so long lines +(e.g. multiple perl commands) can be split in multiple lines. Some web fronteds +make editing of multiline commands transparent.

@@ -1826,6 +1826,15 @@ Send buffer:
2007-10-19 00:31:24 desired-temp 22.5

+ +

Type FileLog:

+
    + set <name> reopen
    + + Used to reopen a FileLog after making some manual changes to the logfile. +
    +
+ diff --git a/fhem/docs/fritzbox.html b/fhem/docs/fritzbox.html index 11606e1df..642e1b95f 100644 --- a/fhem/docs/fritzbox.html +++ b/fhem/docs/fritzbox.html @@ -29,7 +29,6 @@
What does not work right now:
    -
  • Automatic startup after reboot of the fritzbox
  • Gnuplot. No idea how to replace it, perhaps we compile a fritzbox version
  • EM1010PC. I tried it without batteries, and I think the USB interface @@ -81,6 +80,12 @@ telnet fritz.box 7072
to define your devices. +
  • To enable automatic startup after reboot of the fritzbox enter the + following at the end of the /var/flash/debug.cfg:
    +
      + /bin/sleep 120
      + cd /var/media/ftp/*Partition*/usr/fhem && ./rc.fhem +

  • Tips:
    @@ -123,8 +128,8 @@

    Links

      -
    • Complete fhem package for the fritzbox: - fb_fhem_0.2.tar.gz
    • +
    • Complete fhem package for the fritzbox: + fb_fhem_0.3.tar.gz
    • Telnet on the fritzbox: ip-phone-thread
    • diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 2085018ee..05640c367 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -45,26 +45,27 @@ sub AssignIoPort($); sub CallFn(@); sub CommandChain($$); sub DoClose($); +sub FmtDateTime($); +sub FmtTime($); sub GetLogLevel(@); -sub HandleTimeout(); +sub GlobalAttr($$); sub HandleArchiving($); +sub HandleTimeout(); sub IOWrite($@); sub InternalTimer($$$$); sub Log($$); sub OpenLogfile($); +sub PrintHash($$); sub ResolveDateWildcards($@); sub SemicolonEscape($); sub SignalHandling(); sub TimeNow(); -sub FmtDateTime($); -sub FmtTime($); sub WriteStatefile(); sub XmlEscape($); +sub devspec2array($); +sub doGlobalDef($); sub fhem($); sub fhz($); -sub doGlobalDef($); -sub PrintHash($$); -sub devspec2array($); sub CommandAttr($$); sub CommandDefaultAttr($$); @@ -138,7 +139,7 @@ my %intAt; # Internal at timer hash. my $intAtCnt=0; my $reread_active = 0; my $AttrList = "room comment"; -my $cvsid = '$Id: fhem.pl,v 1.41 2008-04-28 17:27:14 rudolfkoenig Exp $'; +my $cvsid = '$Id: fhem.pl,v 1.42 2008-05-09 13:58:10 rudolfkoenig Exp $'; $init_done = 0; @@ -441,13 +442,22 @@ AnalyzeInput($) my ($cmd, $rest) = split("\n", $client{$c}{buffer}, 2); $client{$c}{buffer} = $rest; if($cmd) { - AnalyzeCommandChain($c, $cmd); - return if(!defined($client{$c})); # quit + if($cmd =~ m/\\$/) { # Multi-line + $client{$c}{prevlines} .= $cmd . "\n"; + } else { + if($client{$c}{prevlines}) { + $cmd = $client{$c}{prevlines} . $cmd; + undef($client{$c}{prevlines}); + } + AnalyzeCommandChain($c, $cmd); + return if(!defined($client{$c})); # quit + } } else { - $client{$c}{prompt} = 1; + $client{$c}{prompt} = 1; # Empty return } - syswrite($client{$c}{fd}, "FHZ> ") - if($client{$c}{prompt} && $rest !~ m/\n/); + + syswrite($client{$c}{fd}, $client{$c}{prevlines} ? "> " : "FHZ> ") + if($client{$c}{prompt} && !$rest); } } @@ -457,7 +467,7 @@ sub AnalyzeCommandChain($$) { my ($c, $cmd) = @_; - $cmd =~ s/#.*$//; + $cmd =~ s/#.*$//s; $cmd =~ s/;;/____/g; foreach my $subcmd (split(";", $cmd)) { $subcmd =~ s/____/;/g; @@ -478,8 +488,9 @@ AnalyzeCommand($$) Log 5, "Cmd: >$cmd<"; return if(!$cmd); - if($cmd =~ m/^{.*}$/) { # Perl code + if($cmd =~ m/^{.*}$/s) { # Perl code + $cmd =~ s/\\\n/ /g; # Multi-line # Make life easier for oneliners: %value = (); foreach my $d (keys %defs) { $value{$d} = $defs{$d}{STATE } } @@ -502,7 +513,7 @@ AnalyzeCommand($$) } - if($cmd =~ m/^"(.*)"$/) { # Shell code, always in bg + if($cmd =~ m/^"(.*)"$/s) { # Shell code, always in bg system("$1 &"); return; } @@ -526,7 +537,7 @@ AnalyzeCommand($$) } if(!defined($cmds{$fn})) { - my $msg = "Unknown command $fn, try help"; + my $msg = "Unknown command $fn, try help"; if($cl) { syswrite($client{$cl}{fd}, "$msg\n"); } else { @@ -616,7 +627,7 @@ CommandInclude($$) while(my $l = <$fh>) { chomp($l); if($l =~ m/^(.*)\\$/) { # Multiline commands - $bigcmd .= $1; + $bigcmd .= "$1\\\n"; } else { AnalyzeCommandChain($cl, $bigcmd . $l); $bigcmd = ""; @@ -996,10 +1007,11 @@ CommandModify($$) return "Define $a[0] first" if(!defined($defs{$a[0]})); my $hash = $defs{$a[0]}; - my $odef = $hash->{DEF}; + $hash->{OLDDEF} = $hash->{DEF}; $hash->{DEF} = $a[1]; my $ret = CallFn($a[0], "DefFn", $hash, "$a[0] $hash->{TYPE} $a[1]"); - $hash->{DEF} = $odef if($ret); + $hash->{DEF} = $hash->{OLDDEF} if($ret); + delete($hash->{OLDDEF}); return $ret; } @@ -1162,6 +1174,7 @@ XmlEscape($) { my $a = shift; return "" if(!$a); + $a =~ s/\\\n/
      /g; # Multi-line $a =~ s/&/&/g; $a =~ s/"/"/g; $a =~ s/"; +my $__SF; my $__ti; # Tabindex for all input fields @@ -98,7 +68,7 @@ FHEMWEB_Initialize($) $hash->{DefFn} = "FHEMWEB_Define"; $hash->{UndefFn} = "FHEMWEB_Undef"; - $hash->{AttrList}= "loglevel:0,1,2,3,4,5,6"; + $hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 fhemwebdir fhemwebname"; } ##################################### @@ -114,14 +84,16 @@ FHEMWEB_Define($$) $hash->{STATE} = "Initialized"; $hash->{PORT} = IO::Socket::INET->new( Proto => 'tcp', - LocalHost => ($global ? undef : "localhost"), + LocalHost => (($global && $global eq "global") ? undef : "localhost"), LocalPort => $port, Listen => 10, ReuseAddr => 1); + return "Can't open server port at $port: $!" if(!$hash->{PORT}); + $hash->{FD} = $hash->{PORT}->fileno(); $hash->{SERVERSOCKET} = "True"; - Log 2, "FHEMWEB port $port opened"; + Log(2, "FHEMWEB port $port opened"); return undef; } @@ -149,7 +121,7 @@ FHEMWEB_Read($) if(!@clientinfo) { Print("ERROR", 1, "016 Accept failed for admin port"); - Log 1, "Accept failed for HTTP port ($name: $!)"; + Log(1, "Accept failed for HTTP port ($name: $!)"); return; } @@ -166,13 +138,19 @@ FHEMWEB_Read($) $nhash{BUF} = ""; $defs{$nhash{NAME}} = \%nhash; - Log $ll, "Connection accepted from $nhash{NAME}"; + Log($ll, "Connection accepted from $nhash{NAME}"); return; } my $name = $hash->{SNAME}; my $ll = GetLogLevel($name,4); + $FHEMWEBdir = ($attr{$name} && $attr{$name}{fhemwebdir}) ? + $attr{$name}{fhemwebdir} : "$attr{global}{modpath}/FHEM"; + $__ME = "/" . (($attr{$name} && $attr{$name}{fhemwebname}) ? + $attr{$name}{fhemwebname} : "fhem"); + $FHEMWEB_reldoc = "$__ME/commandref.html"; + $__SF = "
      "; # Data from HTTP Client my $buf; @@ -182,27 +160,29 @@ FHEMWEB_Read($) close($hash->{CD}); delete($defs{$hash->{NAME}}); # Don't delete the attr entry. - Log $ll, "Connection closed for $hash->{NAME}"; + Log($ll, "Connection closed for $hash->{NAME}"); return; } $hash->{BUF} .= $buf; - #Log 1, "Got: >$hash->{BUF}<"; + #Log(1, "Got: >$hash->{BUF}<"); return if($hash->{BUF} !~ m/\n\n$/ && $hash->{BUF} !~ m/\r\n\r\n$/); my @lines = split("[\r\n]", $hash->{BUF}); my ($mode, $arg, $method) = split(" ", $lines[0]); $hash->{BUF} = ""; - Log $ll, "HTTP $hash->{NAME} GET $arg"; + Log($ll, "HTTP $hash->{NAME} GET $arg"); FHEMWEB_AnswerCall($arg); my $c = $hash->{CD}; my $l = length($__RET); + my $exp = localtime(time()+300) . " GMT"; print $c "HTTP/1.1 200 OK\r\n", "Content-Length: $l\r\n", + "Expires: $exp\r\n", "Content-Type: $__RETTYPE\r\n\r\n", $__RET; } @@ -225,27 +205,35 @@ FHEMWEB_AnswerCall($) $__ti = 1; # Lets go: - if($arg !~ m/^$__ME(.*)/) { - if($arg =~ m/^$FHEMWEB_reldoc/) { - open(FH, $FHEMWEB_absdoc) || return; - pO join("", ); - close(FH); - } elsif($arg =~ m/^$FHEMWEB_relicondir(.*)$/) { - $__RETTYPE = "image/gif"; - open(FH, "$FHEMWEB_absicondir$1") || return; - pO join("", ); - close(FH); - } else { - Log 5, "Unknown document $arg requested"; - } + if($arg =~ m/^$FHEMWEB_reldoc/) { + open(FH, "$FHEMWEBdir/commandref.html") || return; + pO join("", ); + close(FH); + return; + } elsif($arg =~ m,^$__ME/style.css,) { + open(FH, "$FHEMWEBdir/style.css") || return; + pO join("", ); + close(FH); + $__RETTYPE = "text/css"; + return; + } elsif($arg =~ m,^$__ME/icons/(.*)$,) { + open(FH, "$FHEMWEBdir/$1") || return; + pO join("", ); + close(FH); + $__RETTYPE = "image/gif"; + return; + } elsif($arg !~ m/^$__ME(.*)/) { + Log(5, "Unknown document $arg requested"); return; } + my $cmd = FHEMWEB_digestCgi($1); $__cmdret = fC($cmd) if($cmd && $cmd !~ /^showlog/ && $cmd !~ /^toweblink/ && - $cmd !~ /^showarchive/); + $cmd !~ /^showarchive/ && + $cmd !~ /^edit/); FHEMWEB_parseXmlList(); return FHEMWEB_showLog($cmd) if($cmd =~ m/^showlog /); @@ -264,9 +252,9 @@ FHEMWEB_AnswerCall($) } } - pO "$__title\n"; + pO "$__title"; + pO ""; + pO "\n"; if($__cmdret) { $__detail = ""; @@ -300,8 +288,9 @@ FHEMWEB_digestCgi($) foreach my $pv (split("&", $arg)) { $pv =~ s/\+/ /g; $pv =~ s/%(..)/chr(hex($1))/ge; - #Log 1, "P1: $pv"; my ($p,$v) = split("=",$pv, 2); + $v =~ s/[\r]\n/\\\n/g; + #Log(0, "P: $p, V: $v"); if($p eq "detail") { $__detail = $v; } if($p eq "room") { $__room = $v; } @@ -337,6 +326,7 @@ FHEMWEB_parseXmlList() ####### INT, ATTR & STATE if($l =~ m,^\t\t\t<(.*) key="(.*)" value="([^"]*)"(.*)/>,) { my ($t, $n, $v, $m) = ($1, $2, $3, $4); + $v =~ s/<br>/
      /g; $__devs{$name}{$t}{$n}{VAL} = $v; if($m) { $m =~ m/measured="(.*)"/; @@ -392,8 +382,9 @@ FHEMWEB_makeTable($$$$$$$$) { my($d,$t,$header,$hash,$clist,$ccmd,$makelink,$cmd) = (@_); - $t = "EM" if($t =~ m/^EM.*$/); return if(!$hash && !$clist); + + $t = "EM" if($t =~ m/^EM.*$/); # EMWZ,EMEM,etc. pO " \n"; # Header @@ -420,7 +411,13 @@ FHEMWEB_makeTable($$$$$$$$) } else { pO ""; } - pO ""; + + if($v eq "DEF") { + FHEMWEB_makeEdit($d, $t, "modify", $hash->{$v}{VAL}); + } else { + pO ""; + } + pO "" if($hash->{$v}{TIM}); pO "" if($cmd); @@ -490,6 +487,14 @@ FHEMWEB_doDetail($) pO "
      \n"; pO "
      $v$hash->{$v}{VAL}$hash->{$v}{VAL}$hash->{$v}{TIM}$cmd
      "; if($iname) { - pO ""; } else { pO ""; @@ -796,7 +801,7 @@ FHEMWEB_showLog($) my $path = "$1/$file"; $path = $__devs{$d}{ATTR}{archivedir}{VAL} . "/$file" if(!-f $path); - my $gplot_pgm = "$FHEMWEB_gnuplotdir/$type.gplot"; + my $gplot_pgm = "$FHEMWEBdir/$type.gplot"; return FHEMWEB_fatal("Cannot read $gplot_pgm") if(!-r $gplot_pgm); return FHEMWEB_fatal("Cannot read $path") if(!-r $path); @@ -809,7 +814,7 @@ FHEMWEB_showLog($) $gplot_script =~ s//$path/g; $gplot_script =~ s//$file/g; - open(FH, "|$FHEMWEB_gnuplot > /dev/null");# feed it to gnuplot + open(FH, "|gnuplot > /dev/null");# feed it to gnuplot print FH $gplot_script; close(FH); @@ -865,6 +870,30 @@ FHEMWEB_textfield($$) return $s; } +sub +FHEMWEB_makeEdit($$$$) +{ + my ($name, $type, $cmd, $val) = @_; + + pO ""; +} + ################## sub FHEMWEB_submit($$) @@ -891,10 +920,13 @@ pO(@) sub fC($) { + my ($cmd) = @_; my $oll = $attr{global}{verbose}; $attr{global}{verbose} = 0; - my $ret = AnalyzeCommand(undef, shift); - $attr{global}{verbose} = $oll; + my $ret = AnalyzeCommand(undef, $cmd); + if($cmd !~ m/attr.*global.*verbose/) { + $attr{global}{verbose} = $oll; + } return $ret; } diff --git a/fhem/webfrontend/pgm2/em.gplot b/fhem/webfrontend/pgm2/em.gplot index 4999ea1c6..d3570344d 100644 --- a/fhem/webfrontend/pgm2/em.gplot +++ b/fhem/webfrontend/pgm2/em.gplot @@ -4,15 +4,19 @@ #================= -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" set xlabel " " -set ytics nomirror set title '' +set ylabel "Power (KW)" +set y2label "Power (KW)" set grid -#set ytics .2 +set ytics +set y2tics +set format y "%.1f" +set format y2 "%.1f" -plot "" using 1:4 title 'Power (KW)' with lines +plot "" using 1:4 notitle with lines diff --git a/fhem/webfrontend/pgm2/fht.gplot b/fhem/webfrontend/pgm2/fht.gplot index cb2883701..e7de9cb0a 100644 --- a/fhem/webfrontend/pgm2/fht.gplot +++ b/fhem/webfrontend/pgm2/fht.gplot @@ -3,21 +3,24 @@ # FileLog definition: # define FileLog fhtlog1 fht1:.*(temp|actuator).* /var/log/fht1-%Y-%U.log # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" set xlabel " " set ytics nomirror set y2tics -set ytics 1 +#set ytics set title '' -set grid +set grid xtics y2tics + +set y2label "temperature (Celsius)" +set ylabel "Actuator (%)" -set ylabel "Temperature (Celsius)" -set y2label "Actuator (%)" plot \ - "< awk '/measured/{print $1, $4; s=1}' "\ - using 1:2 axes x1y1 title 'Measured temperature' with lines,\ - "< awk '/actuator/ {print $1, $4+0; have=1} /measured/ {s=$1} END { if(!have) print (s, 0)}' "\ - using 1:2 axes x1y2 title 'Actuator (%)' with lines + "< awk '/measured/{print $1, $4}' "\ + using 1:2 axes x1y2 title 'Measured temperature' with lines lw 2,\ + "< awk '/desired/ {print $1, $4+0}' "\ + using 1:2 axes x1y2 title 'Desired temperature' with steps,\ + "< awk '/actuator/ {print $1, $4+0}' "\ + using 1:2 axes x1y1 title 'Actuator (%)' with lines\ diff --git a/fhem/webfrontend/pgm2/fs20.gplot b/fhem/webfrontend/pgm2/fs20.gplot index ab9bae14c..2b2da76d2 100644 --- a/fhem/webfrontend/pgm2/fs20.gplot +++ b/fhem/webfrontend/pgm2/fs20.gplot @@ -3,14 +3,19 @@ # FileLog definition: # define FileLog fs20log fs20dev /var/log/fs20dev-%Y-%U.log # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" set xlabel " " set title '' -set noytics + +set ytics ("Off" 0, "On" 1) +set y2tics ("Off" 0, "On" 1) set yrange [-0.1:1.1] +set y2range [-0.1:1.1] +set ylabel "Pumpe" +set y2label "Pumpe" plot "< awk '{print $1, $3==\"on\"? 1 : 0; }' "\ - using 1:2 title 'On/Off' with steps + using 1:2 notitle with steps diff --git a/fhem/webfrontend/pgm2/ks300_1.gplot b/fhem/webfrontend/pgm2/ks300_1.gplot index 2d7b370d2..888fbe6b2 100644 --- a/fhem/webfrontend/pgm2/ks300_1.gplot +++ b/fhem/webfrontend/pgm2/ks300_1.gplot @@ -3,7 +3,7 @@ # FileLog definition: # define FileLog ks300log ks300:.*H:.* /var/log/ks300-%Y-%U.log # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" @@ -13,8 +13,27 @@ set y2tics set title '' set grid -set ylabel "Temperature (Celsius)" -set y2label "Rain (l/m2)" -plot "" using 1:4 axes x1y1 title 'Temperature' with lines,\ - " | perl -ane '@a = split(\"[_:]\", $F[0]); if(defined($lh) && $lh ne $a[1]) { printf(\"${ld}_$lh:30:00 %f\n\", $hv); $hv = 0; } if($lv) { $hv += ($F[9]-$lv); } $lh = $a[1]; $ld = $a[0]; $lv = $F[9]; END { printf(\"${ld}_$lh:30:00 %f\n\", $hv) }'" using 1:2 axes x1y2 title 'Rain/h' with histeps,\ - " | perl -ane '@a = split(\"[_]\", $F[0]); if(defined($ld) && $ld ne $a[0]) { printf(\"${ld}_12:00:00 %f\n\", $dv); $dv = 0; } if($lv) { $dv += ($F[9]-$lv); } $ld = $a[0]; $lv = $F[9]; END {printf(\"${ld}_12:00:00 %f\n\", $dv)}'" using 1:2 axes x1y2 title 'Rain/day' with histeps +set y2label "Temperature (Celsius)" +set format y "%0.1f" +set ylabel "Rain (l/m2)" +set yrange [0:] + +# Computing Rain/h and Rain/d values by accumulating the changes. + +plot "" using 1:4 axes x1y2 title 'Temperature' with lines lw 2,\ + " | perl -ane '\ + @a = split(\"[_:]\", $F[0]);\ + if(defined($lh) && $lh ne $a[1])\ + { printf(\"${ld}_$lh:30:00 %f\n\", $hv); $hv = 0; }\ + if($lv) { $hv += ($F[9]-$lv); }\ + $lh = $a[1]; $ld = $a[0]; $lv = $F[9];\ + END { printf(\"${ld}_$lh:30:00 %f\n\", $hv) }'"\ + using 1:2 axes x1y1 title 'Rain/h' with histeps,\ + " | perl -ane '\ + @a = split(\"[_]\", $F[0]);\ + if(defined($ld) && $ld ne $a[0]) {\ + printf(\"${ld}_12:00:00 %f\n\", $dv); $dv = 0; }\ + if($lv) { $dv += ($F[9]-$lv); }\ + $ld = $a[0]; $lv = $F[9];\ + END {printf(\"${ld}_12:00:00 %f\n\", $dv)}'"\ + using 1:2 axes x1y1 title 'Rain/day' with histeps diff --git a/fhem/webfrontend/pgm2/ks300_2.gplot b/fhem/webfrontend/pgm2/ks300_2.gplot index b93bf3402..c8fff205c 100644 --- a/fhem/webfrontend/pgm2/ks300_2.gplot +++ b/fhem/webfrontend/pgm2/ks300_2.gplot @@ -3,7 +3,7 @@ # FileLog definition: # define FileLog ks300log ks300:.*H:.* /var/log/ks300-%Y-%U.log # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" diff --git a/fhem/webfrontend/pgm2/ks300_3.gplot b/fhem/webfrontend/pgm2/ks300_3.gplot index 9033d763a..a2ce53716 100644 --- a/fhem/webfrontend/pgm2/ks300_3.gplot +++ b/fhem/webfrontend/pgm2/ks300_3.gplot @@ -3,7 +3,7 @@ # FileLog definition: # define FileLog ks300log ks300:.*H:.* /var/log/ks300-%Y-%U.log # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" diff --git a/fhem/webfrontend/pgm2/mpiri.gplot b/fhem/webfrontend/pgm2/mpiri.gplot index fc80b3a42..4021c4eb6 100644 --- a/fhem/webfrontend/pgm2/mpiri.gplot +++ b/fhem/webfrontend/pgm2/mpiri.gplot @@ -3,18 +3,21 @@ # define pirilog FileLog /var/log/piri-%Y-%m-%d.log piri.* # The devices are called piri.sz, piri.flo, piri.flu, prir.wz1 and piri.wz2 # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S" set xlabel " " +set ylabel "Piri" +set y2label "Piri" set title '' -set noytics -set yrange [-0.1:1.1] +set ytics ("Sz" 0.8, "FlO" 0.6, "FlU" 0.4, "Wz1" 0.2, "Wz2" 0.0) +set y2tics ("Sz" 0.8, "FlO" 0.6, "FlU" 0.4, "Wz1" 0.2, "Wz2" 0.0) +set yrange [-0.1:0.9] plot\ - "< awk '/sz/ {print $1, 0.8; }' " using 1:2 title 'sz' with points,\ - "< awk '/flo/{print $1, 0.6; }' " using 1:2 title 'flo' with points,\ - "< awk '/flu/{print $1, 0.4; }' " using 1:2 title 'flu' with points,\ - "< awk '/wz1/{print $1, 0.2; }' " using 1:2 title 'wz1' with points,\ - "< awk '/wz2/{print $1, 0.0; }' " using 1:2 title 'wz2' with points + "< awk '/sz/ {print $1, 0.8; }' " using 1:2 notitle with points,\ + "< awk '/flo/{print $1, 0.6; }' " using 1:2 notitle with points,\ + "< awk '/flu/{print $1, 0.4; }' " using 1:2 notitle with points,\ + "< awk '/wz1/{print $1, 0.2; }' " using 1:2 notitle with points,\ + "< awk '/wz2/{print $1, 0.0; }' " using 1:2 notitle with points diff --git a/fhem/webfrontend/pgm2/piri.gplot b/fhem/webfrontend/pgm2/piri.gplot index bd67aa63e..f9112f477 100644 --- a/fhem/webfrontend/pgm2/piri.gplot +++ b/fhem/webfrontend/pgm2/piri.gplot @@ -3,7 +3,7 @@ # FileLog definition: # define FileLog fs20log fs20dev /var/log/fs20dev-%Y-%U.log # -set terminal png size 800,200 crop +set terminal png transparent size 800,200 crop set output '.png' set xdata time set timefmt "%Y-%m-%d_%H:%M:%S"
      \n"; pO "Delete $d\n"; + + my $pgm = "Javascript:" . + "s=document.getElementById('edit').style;". + "if(s.display=='none') s.display='block'; else s.display='none';". + "s=document.getElementById('disp').style;". + "if(s.display=='none') s.display='block'; else s.display='none';"; + pO "Modify $d"; + pO "
      \n"; FHEMWEB_makeTable($d, $t, "State,Value,Measured", @@ -547,7 +552,7 @@ FHEMWEB_checkDirs() { return if($__iconsread && (time() - $__iconsread) < 5); %__icons = (); - if(opendir(DH, $FHEMWEB_absicondir)) { + if(opendir(DH, $FHEMWEBdir)) { while(my $l = readdir(DH)) { next if($l =~ m/^\./); my $x = $l; @@ -647,7 +652,7 @@ FHEMWEB_showRoom() pO "$d$v"; + pO "
      "; + my $eval = $val; + $eval =~ s/
      /\n/g; + if($type eq "at" || $type eq "notify") { + pO ""; + } else { + pO ""; + } + $__ti++; + pO "
      " . FHEMWEB_submit("cmd.${cmd}$name", "$cmd $name"); + pO "
      "; + $eval = "
      $eval
      " if($eval =~ m/\n/); + pO "
      $eval
      "; + pO "