2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-13 17:26:34 +00:00

Fixes/reduced logging on 70_WS3600.pm

Made CUL_FHTTK work with 98_autocreate.pm, (first) GPLOT info is now used
Added sanity checking to fhem.pl, does not save undefined fields anymore
Added fht80tf.gplot, may need (re-)work


git-svn-id: https://svn.fhem.de/fhem/trunk@539 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
painseeker 2010-01-04 23:07:35 +00:00
parent a68040480c
commit a578c71fca
4 changed files with 68 additions and 23 deletions

View File

@ -29,7 +29,7 @@ package main;
#
# Contributed by Kai 'wusel' Siering <wusel+fhem@uu.org> in 2009/2010
# Based in part on work for FHEM by other authors ...
# $Id: 70_WS3600.pm,v 1.1 2010-01-04 15:05:36 painseeker Exp $
# $Id: 70_WS3600.pm,v 1.2 2010-01-04 23:07:35 painseeker Exp $
###########################
use strict;
@ -155,7 +155,7 @@ WS3600_Define($$)
my $FH;
my $dev = sprintf("%s |", $a[2]);
Log 3, "WS3600 using \"$dev\" as parameter to open()";
Log 3, "WS3600 using \"$dev\" as parameter to open(); trying ...";
open($FH, $dev);
if(!$FH) {
return "WS3600 Can't start $dev: $!";
@ -187,7 +187,7 @@ WS3600_Define($$)
# WS3600_GetStatus($hash);
# $init_done = $oid;
Log 3, "WS3600 setting timer";
Log 3, "WS3600 setting callback timer";
my $oid = $init_done;
$init_done = 1;
@ -215,7 +215,7 @@ WS3600_Undef($$)
delete $selectlist{"$name.pipe"};
$hash->{STATE}='undefined';
Log 5, "$name shutdown complete";
Log 3, "$name shutdown complete";
return undef;
}
@ -233,7 +233,7 @@ WS3600_GetStatus($)
# Call us in n seconds again.
# InternalTimer(gettimeofday()+ $hash->{Timer}, "WS3600_GetStatus", $hash, 1);
Log 3, "WS3600 contacting station";
Log 4, "WS3600 contacting station";
open($FH, $dev);
if(!$FH) {
@ -242,7 +242,7 @@ WS3600_GetStatus($)
$hash->{FD}=$FH;
$selectlist{"$name.pipe"} = $hash;
Log 3, "WS3600 pipe opened";
Log 4, "WS3600 pipe opened";
$hash->{STATE} = "running";
$hash->{pipeopentime} = time();
# InternalTimer(gettimeofday() + 6, "WS3600_Read", $hash, 1);
@ -260,19 +260,19 @@ WS3600_Read($)
my $FH;
my $inputline;
Log 3, "WS3600 Read entered";
Log 4, "WS3600 Read entered";
if(!defined($hash->{FD})) {
Log 3, "WS3600 FD undef'd";
Log 3, "Oops, WS3600 FD undef'd";
return undef;
}
if(!$hash->{FD}) {
Log 3, "WS3600 FD empty";
Log 3, "Oops, WS3600 FD empty";
return undef;
}
$FH = $hash->{FD};
Log 3, "WS3600 start reading";
Log 4, "WS3600 reading started";
my @lines;
my $eof;
@ -286,13 +286,20 @@ WS3600_Read($)
($eof, @lines) = nonblockGetLines($FH);
Log 3, "WS3600 ended reading (eof=$eof)";
if(!defined($eof)) {
Log 4, "WS3600 FIXME: eof undefined?!";
$eof=0;
}
Log 4, "WS3600 reading ended with eof==$eof";
# FIXME! Current observed behaviour is "would block", then read of only EOF.
# Not sure if it's always that way; more correct would be checking
# for empty $inputline or undef'd $rawreading,$val. -wusel, 2010-01-04
if($eof != 1) {
foreach my $inputline ( @lines ) {
$inputline =~ s/\s+$//;
my ($rawreading, $val)=split(/ /, $inputline);
Log 3, "WS3600 read $inputline:$rawreading:$val";
Log 5, "WS3600 read $inputline:$rawreading:$val";
if(defined($TranslatedCodes{$rawreading})) {
# delete $defs{$name}{READINGS}{" $rawreading"};
@ -330,9 +337,9 @@ WS3600_Read($)
delete $hash->{FD};
delete $selectlist{"$name.pipe"};
InternalTimer(gettimeofday()+ $hash->{Timer}, "WS3600_GetStatus", $hash, 1);
Log 3, "WS3600 done reading pipe";
Log 4, "WS3600 done reading pipe";
} else {
Log 3, "WS3600 reading would block";
Log 4, "WS3600 (further) reading would block";
}
# $OtherString =~ s/^\s+//;

View File

@ -11,11 +11,13 @@ use warnings;
# - check "UNDEFINED" parameters for BS/USF1000/X10
my %flogpar = (
"CUL_EM:.*" => { GPLOT => "cul_em:Power,", FILTER => "%NAME:CNT:.*" },
"CUL_WS:.*" => { GPLOT => "cul_ws:Temp,", FILTER => "%NAME" },
"FHT:.*" => { GPLOT => "fht:Temp/Act,", FILTER => "%NAME" },
"HMS:HMS100T.*" => { GPLOT => "hms:Temp/Hum,", FILTER => "%NAME:T:.*" },
"KS300:.*" => { GPLOT => "ks300:Temp/Rain,ks300_2:Wind/Hum,",
"CUL_EM:.*" => { GPLOT => "cul_em:Power,", FILTER => "%NAME:CNT:.*" },
"CUL_WS:.*" => { GPLOT => "hms:Temp/Hum,", FILTER => "%NAME" },
"CUL_FHTTK:.*" => { GPLOT => "fht80tf:Window,", FILTER => "%NAME" },
"FHT:.*" => { GPLOT => "fht:Temp/Act,", FILTER => "%NAME" },
"HMS:HMS100TFK_.*" => { GPLOT => "fht80tf:Contact,", FILTER => "%NAME" },
"HMS:HMS100T._.*" => { GPLOT => "hms:Temp/Hum,", FILTER => "%NAME:T:.*" },
"KS300:.*" => { GPLOT => "ks300:Temp/Rain,ks300_2:Wind/Hum,",
FILTER => "%NAME:T:.*" },
);
@ -91,7 +93,7 @@ autocreate_Notify($$)
my $flname = "FileLog_$name";
my ($gplot, $filter) = ("", $name);
foreach my $k (keys %flogpar) {
next if("$type:$name" !~ m/^$k$/);
next if("$type:$name" !~ m/^$k$/);
$gplot = $flogpar{$k}{GPLOT};
$filter = replace_wildcards($hash, $flogpar{$k}{FILTER});
}
@ -110,7 +112,10 @@ autocreate_Notify($$)
next if(!$attr{$me}{weblink} || !$gplot);
$room = replace_wildcards($hash, $attr{$me}{weblink_room});
my $wlname = "weblink_$name";
$cmd = "$wlname weblink fileplot $flname:$lctype:CURRENT";
my $gplotfile;
my $stuff;
($gplotfile, $stuff) = split(/:/, $gplot);
$cmd = "$wlname weblink fileplot $flname:$gplotfile:CURRENT";
Log GetLogLevel($me,2), "autocreate: define $cmd";
$ret = CommandDefine(undef, $cmd);
if($ret) {

19
fhem/FHEM/fht80tf.gplot Normal file
View File

@ -0,0 +1,19 @@
############################
# Display the on and off values for a single FHT80TF device
# FileLog definition:
# define fht80tflog FileLog /var/log/fhem/fht80tf-%Y-%U.log fht80tfdev
set terminal png transparent size <SIZE> crop
set output '<OUT>.png'
set xdata time
set timefmt "%Y-%m-%d_%H:%M:%S"
set xlabel " "
set ytics nomirror
set title '<TL>'
set grid
set yrange [-0.2:1.2]
#FileLog "1"::0:
plot "< awk '{print $1, $4==\"Open\"? 1 : 0; }' <IN>"\
using 1:2 title 'Open/Closed' with impulses

View File

@ -159,7 +159,7 @@ my $nextat; # Time when next timer will be triggered.
my $intAtCnt=0;
my %duplicate; # Pool of received msg for multi-fhz/cul setups
my $duplidx=0; # helper for the above pool
my $cvsid = '$Id: fhem.pl,v 1.97 2010-01-01 15:18:09 rudolfkoenig Exp $';
my $cvsid = '$Id: fhem.pl,v 1.98 2010-01-04 23:07:35 painseeker Exp $';
my $namedef =
"where <name> is either:\n" .
"- a single device name\n" .
@ -862,7 +862,21 @@ WriteStatefile()
my $r = $defs{$d}{READINGS};
if($r) {
foreach my $c (sort keys %{$r}) {
print SFH "setstate $d $r->{$c}{TIME} $c $r->{$c}{VAL}\n";
my $errors=0;
if(!defined($r->{$c}{TIME})) {
Log 4, "ERROR WITH DEF $d: Missing TIME in READINGS of key $c!";
$errors++;
}
if(!defined($r->{$c}{VAL})) {
Log 4, "ERROR WITH DEF $d: Missing VAL in READINGS of key $c!";
$errors++;
}
if($errors==0) {
print SFH "setstate $d $r->{$c}{TIME} $c $r->{$c}{VAL}\n";
} else {
Log 3, "Sanitizer: not saving READING $c of $d due to missing VAL and/or TIME.";
}
}
}
}