diff --git a/fhem/webfrontend/pgm2/01_FHEMWEB.pm b/fhem/webfrontend/pgm2/01_FHEMWEB.pm index 12921f63b..c6ea184e5 100755 --- a/fhem/webfrontend/pgm2/01_FHEMWEB.pm +++ b/fhem/webfrontend/pgm2/01_FHEMWEB.pm @@ -87,21 +87,20 @@ FW_Define($$) ($global && $global ne "global")); $hash->{STATE} = "Initialized"; - $hash->{PORT} = IO::Socket::INET->new( + $hash->{SERVERSOCKET} = IO::Socket::INET->new( Proto => 'tcp', LocalHost => (($global && $global eq "global") ? undef : "localhost"), LocalPort => $port, Listen => 10, ReuseAddr => 1); - return "Can't open server port at $port: $!" if(!$hash->{PORT}); + return "Can't open server port at $port: $!" if(!$hash->{SERVERSOCKET}); - $hash->{FD} = $hash->{PORT}->fileno(); + $hash->{FD} = $hash->{SERVERSOCKET}->fileno(); + $hash->{PORT} = $port; $selectlist{"$name.$port"} = $hash; - $hash->{SERVERSOCKET} = 1; Log(2, "FHEMWEB port $port opened"); - return undef; } @@ -110,8 +109,19 @@ sub FW_Undef($$) { my ($hash, $arg) = @_; - close($hash->{CD}) if(defined($hash->{CD})); # Clients - close($hash->{PORT}) if(defined($hash->{PORT})); # Server + my $name = $hash->{NAME}; + + return undef if($hash->{INUSE}); + + if(defined($hash->{CD})) { # Clients + close($hash->{CD}); + delete($selectlist{$hash->{NAME}}); + } + if(defined($hash->{SERVERSOCKET})) { # Server + close($hash->{SERVERSOCKET}); + $name = $name . "." . $hash->{PORT}; + delete($selectlist{$name}); + } return undef; } @@ -120,11 +130,11 @@ sub FW_Read($) { my ($hash) = @_; + my $name = $hash->{NAME}; if($hash->{SERVERSOCKET}) { # Accept and create a child - my @clientinfo = $hash->{PORT}->accept(); - my $name = $hash->{NAME}; + my @clientinfo = $hash->{SERVERSOCKET}->accept(); my $ll = GetLogLevel($name,4); if(!@clientinfo) { @@ -162,8 +172,8 @@ FW_Read($) my $ret = sysread($hash->{CD}, $buf, 1024); if(!defined($ret) || $ret <= 0) { - my $r = CommandDelete(undef, $hash->{NAME}); - Log($ll, "Connection closed for $hash->{NAME}"); + my $r = CommandDelete(undef, $name); + Log($ll, "Connection closed for $name"); return; } @@ -175,9 +185,17 @@ FW_Read($) my ($mode, $arg, $method) = split(" ", $lines[0]); $hash->{BUF} = ""; - Log($ll, "HTTP $hash->{NAME} GET $arg"); + Log($ll, "HTTP $name GET $arg"); + $hash->{INUSE} = 1; + my $cacheable = FW_AnswerCall($arg); + delete($hash->{INUSE}); + if(!$selectlist{$name}) { # removed by rereadcfg, reinsert + $selectlist{$name} = $hash; + $defs{$name} = $hash; + } + my $c = $hash->{CD}; my $l = length($__RET); my $e = ($cacheable? ("Expires: ".localtime(time()+900)." GMT\r\n") : ""); diff --git a/fhem/webfrontend/pgm2/cul_em.gplot b/fhem/webfrontend/pgm2/cul_em.gplot index e15fe0165..7ae328e61 100644 --- a/fhem/webfrontend/pgm2/cul_em.gplot +++ b/fhem/webfrontend/pgm2/cul_em.gplot @@ -1,7 +1,8 @@ ############################ # Display the power reported by the EM1010 # Corresponding FileLog definition: -# define ememlog FileLog /var/log/fhem/emem-%Y.log emem:power.* +# define ememlog FileLog /var/log/fhem/em-%Y.log emem:power.* +# define emwzlog FileLog /var/log/fhem/em-%Y.log emwz:power.* set terminal png transparent size crop set output '.png' diff --git a/fhem/webfrontend/pgm2/cul_emem.gplot b/fhem/webfrontend/pgm2/cul_emem.gplot new file mode 100644 index 000000000..152109146 --- /dev/null +++ b/fhem/webfrontend/pgm2/cul_emem.gplot @@ -0,0 +1,32 @@ +############################ +# Display the power reported by the EM1000FM received bei CUL + +#set terminal png transparent size crop +set terminal png size crop +set output '.png' +set xdata time +set timefmt "%Y-%m-%d_%H:%M:%S" +set xlabel "Energiemonitor EM1000EM" + +set title '' +set ylabel "Power (kW)" +set y2label "Power (kWh)" +set grid +set ytics +set y2tics +set logscale y +set logscale y2 +set format y "%.1f" +set format y2 "%.1f" + +#FileLog 8::0: +#FileLog 10::0: + + +plot \ + "< awk '/5MIN:/ {print $1, $8}' "\ + using 1:2 axes x1y2 title 'kWh' with lines lw 1,\ + "< awk '/TOP:/ {print $1, $10}' "\ + using 1:2 axes x1y1 title 'Spitze kW' with lines lw 2\ + +