diff --git a/CHANGED b/CHANGED
index 36cac8166..65a9e300f 100644
--- a/CHANGED
+++ b/CHANGED
@@ -414,3 +414,6 @@
- ==DATE== (4.4)
- feature: RM100-2 battery empty warning (mare 23.07.08)
- feature: optimising the pgm2/SVG memory usage
+ - feature: autoloading FHEM modules
+ - bugfix: STATE/$value is carrying again the correct value
+ - feature: enhancing the Makefile and the documentation
diff --git a/FHEM/92_FileLog.pm b/FHEM/92_FileLog.pm
index 471ef75a4..ca2ba1a7e 100755
--- a/FHEM/92_FileLog.pm
+++ b/FHEM/92_FileLog.pm
@@ -203,6 +203,7 @@ FileLog_Get($@)
$h{fh} = new IO::File "> $fname[$i]";
}
$h{re} = $fld[1];
+
$h{df} = defined($fld[2]) ? $fld[2] : "";
$h{fn} = $fld[3];
$h{didx} = 10 if($fld[3] && $fld[3] eq "delta-d");
@@ -210,9 +211,15 @@ FileLog_Get($@)
if($fld[0] =~ m/"(.*)"/) {
$h{col} = $1;
- $h{isfix} = 1;
+ $h{type} = 0;
} else {
$h{col} = $fld[0]-1;
+ $h{type} = 1;
+ }
+ if($h{fn}) {
+ $h{type} = 4;
+ $h{type} = 2 if($h{didx});
+ $h{type} = 3 if($h{fn} eq "int");
}
$h{ret} = "";
$d[$i] = \%h;
@@ -225,19 +232,20 @@ FileLog_Get($@)
for my $i (0..int(@a)-1) { # Process each req. field
my $h = $d[$i];
- my $re = $h->{re};
- next if($re && $l !~ m/$re/); # 20%
+ next if($h->{re} && $l !~ m/$h->{re}/); # 20%
my $col = $h->{col};
- my $line = "";
+ my $t = $h->{type};
+ my $line;
- if($h->{isfix}) { # Fixed text
- $line = "$fld[0] $col";
- } elsif(!$h->{fn}) { # The column
- $line = "$fld[0] $fld[$col]";
+ if($t == 0) { # Fixed text
+ $line = "$fld[0] $col\n";
- } elsif($h->{didx}) { # delta-h or delta-d
+ } elsif($t == 1) { # The column
+ $line = "$fld[0] $fld[$col]\n";
+
+ } elsif($t == 2) { # delta-h or delta-d
my $hd = $h->{didx};
my $ld = substr($fld[0],0,$hd);
@@ -248,31 +256,29 @@ FileLog_Get($@)
$ts = "$lda[1]:30:00" if($hd == 13);
my $v = $fld[$col]-$h->{last1};
$v = 0 if($v < 0); # Skip negative delta
- $line = sprintf("%s_%s %0.1f", $lda[0],$ts, $v);
+ $line = sprintf("%s_%s %0.1f\n", $lda[0],$ts, $v);
}
$h->{last1} = $fld[$col];
$h->{last3} = $ld;
}
$h->{last2} = $fld[$col];
$lastdate{$hd} = $fld[0];
+ next if(!$line);
- } elsif($h->{fn} eq "int") { # int function
+ } elsif($t == 3) { # int function
my $val = $fld[$col];
- $line = "$fld[0] $1" if($val =~ m/^([0-9]+).*/);
+ $line = "$fld[0] $1\n" if($val =~ m/^([0-9]+).*/);
- } else {
- $line = "$fld[0] " . eval($h->{fn});
+ } else { # evaluate
+ $line = "$fld[0] " . eval($h->{fn}) . "\n";
}
- next if(!$line);
-
- $h->{count}++;
- $line .= "\n";
if($outf eq "-") {
$h->{ret} .= $line;
} else {
my $fh = $h->{fh};
print $fh $line;
+ $h->{count}++;
}
}
}
@@ -292,7 +298,6 @@ FileLog_Get($@)
if($outf eq "-") {
$h->{ret} .= $line;
- $h->{count}++;
} else {
my $fh = $h->{fh};
print $fh $line;
@@ -300,7 +305,7 @@ FileLog_Get($@)
}
}
if($outf eq "-") {
- $h->{ret} .= "$from $h->{df}\n" if(!$h->{count} && $h->{df} ne "");
+ $h->{ret} .= "$from $h->{df}\n" if(!$h->{ret} && $h->{df} ne "");
$ret .= $h->{ret} if($h->{ret});
$ret .= "#$a[$i]\n";
} else {
diff --git a/HISTORY b/HISTORY
index e97db89cf..456a339be 100644
--- a/HISTORY
+++ b/HISTORY
@@ -305,3 +305,11 @@
Tested with Firefox 3.0.
Todo: Test with IE+Adobe Plugin/Opera.
- feature: HOWTO for webpgm2 (first chapter)
+
+Fri Jul 25 18:14:26 MEST 2008
+ - Autoloading modules. In order to make module installation easier and
+ to optimize memory usage, modules are loaded when the first device of a
+ certain category is defined. Exceptions are the modules prefixed with 99,
+ these are considered "utility" modules and are loaded at the beginning.
+ Some of the older 99_x modules were renamed (99_SVG, 99_dummy), and most
+ contrib modules were moved to the main FHEM directory.
diff --git a/Makefile b/Makefile
index a946bb9d7..2f90ea22f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,43 @@
BINDIR=/usr/local/bin
MODDIR=/usr/local/lib
+VARDIR=/var/log/fhem
VERS=4.3
DATE=2008-07-12
-DIR=fhem-$(VERS)
all:
@echo Nothing to do for all.
@echo To install, check the Makefile, and then \'make install\'
+ @echo or \'make install-pgm2\' to install a web frontend too.
-install:
+install:install-base
+ cp examples/sample_fhem $(VARDIR)/fhem.cfg
+ @echo
+ @echo
+ @echo Edit $(VARDIR)/fhem.cfg then type perl $(BINDIR)/fhem.pl $(VARDIR)/fhem.cfg
+
+install-pgm2:install-base
+ cp webfrontend/pgm2/* $(MODDIR)/FHEM
+ cp docs/commandref.html docs/faq.html docs/HOWTO.html $(MODDIR)/FHEM
+ cp examples/sample_pgm2 $(VARDIR)/fhem.cfg
+ cd examples; for i in *; do cp $$i $(MODDIR)/FHEM/example.$$i; done
+ @echo
+ @echo
+ @echo Edit $(VARDIR)/fhem.cfg then start perl $(BINDIR)/fhem.pl $(VARDIR)/fhem.cfg
+
+install-base:
cp fhem.pl $(BINDIR)
cp -r FHEM $(MODDIR)
- perl -pi -e 's,modpath .,modpath $(MODDIR),' examples/*
-
-install-pgm2:
- cp fhem.pl $(BINDIR)
- cp -r FHEM $(MODDIR)
- cp -r webfrontend/pgm2/* $(MODDIR)
- perl -pi -e 's,modpath .,modpath $(MODDIR),' examples/*
+ mkdir -p $(VARDIR)
+ perl -pi -e 's,modpath \.,modpath $(MODDIR),' examples/*
+ perl -pi -e 's,/tmp,$(VARDIR),' examples/*
dist:
@echo Version is $(VERS), Date is $(DATE)
mkdir .f
cp -r CHANGED FHEM HISTORY Makefile README.CVS em1010pc\
TODO contrib docs examples fhem.pl test webfrontend .f
+ find .f -name CVS -print | xargs rm -rf
find .f -name \*.orig -print | xargs rm -f
find .f -name .#\* -print | xargs rm -f
find .f -type f -print |\
diff --git a/contrib/99_SUNRISE.pm b/contrib/99_SUNRISE.pm
index 1e490098b..5970c66c8 100755
--- a/contrib/99_SUNRISE.pm
+++ b/contrib/99_SUNRISE.pm
@@ -1,4 +1,5 @@
##############################################
+# - Use 99_SUNRISE_EL.pm instead of this module
# - Be aware: Installing the DateTime modules might be tedious, one way is:
# perl -MCPAN -e shell
# cpan> install DateTime::Event::Sunrise
diff --git a/docs/commandref.html b/docs/commandref.html
index 8a8e9d3b3..8127cf2ac 100644
--- a/docs/commandref.html
+++ b/docs/commandref.html
@@ -166,9 +166,16 @@ make editing of multiline commands transparent.
modpath
Specify the path to the modules directory FHEM
. The path
- should not contain the directory FHEM. Every file there with the
- name pattern <number>_<name>.pm will be loaded in the order
- of the number.
+ should not contain the directory FHEM. Upon setting the
+ attribute, the directory will be scanned for filenames of the form
+ NN_<NAME>.pm, and make them available for device definition under
+ <NAME>. If the first device of type <NAME> is defined, the
+ module will be loaded, and its function with the name
+ <NAME>_initialize will be called. Exception to this rule are
+ modules with NN=99, these are considered to be utility modules
+ containing only perl helper functions, they are loaded at startup (i.e.
+ modpath attribute definition time).
+
@@ -325,7 +332,7 @@ make editing of multiline commands transparent.
logtype
Can be applied to FileLog devices.
- Used by the pgm2 webfrontend to offer gnuplot images made from the
+ Used by the pgm2 webfrontend to offer gnuplot/SVG images made from the
logs. The string is made up of tokens separated by comma (,), each
token specifies a different gnuplot program. The token may contain a
colon (:), the part before the colon defines the name of the program,
@@ -357,13 +364,10 @@ make editing of multiline commands transparent.
above, both programs evaluate the same log.
text
- Shows the logfile as it is (plain text).
+ Shows the logfile as it is (plain text). Not gnuplot definition
+ is needed.
- The corresponding gnuplot files (up to the "text" one) must be
- installed, see the fhemweb.pl configuration for the destination
- directory.
-
Example:
attr fhtlog1 logtype ks300_1:Temp/Rain,ks300_2:Hum/Wind,text:Raw-data
@@ -385,42 +389,40 @@ make editing of multiline commands transparent.
devices:
@@ -1148,9 +1166,8 @@ make editing of multiline commands transparent.
of the sunset/sunrise functions should be used with the relative
(+) flag
- In order to use the sunrise_rel()/sunset_rel() functions, copy the
- 99_SUNRISE_EL.pm file from the contrib into the modules (FHEM)
- directory, and put { sunrise_coord(long, lat, "") } into your
+ In order to use the sunrise_rel()/sunset_rel() functions,
+ put { sunrise_coord(long, lat, "") } into your
lastinclude file, as in the above example.
If you are not using sunrise_coord, then the coordinates for
Frankfurt am Main, Germany will be used.
@@ -1217,10 +1234,8 @@ make editing of multiline commands transparent.
href="#list">list output in paranthesis after the device name, or the
string you see when you do a detailed list of the device.
-
Each undefined device (FS20, HMS, FHT) will be reported with the
device name "UNDEFINED". The % parameter will contain the type (FS20,
@@ -1235,8 +1250,8 @@ make editing of multiline commands transparent.
define <name> weblink [link|fileplot] <argument>
This is a placeholder used with webpgm2 to be able to integrate links
- into it, and to be able to put more than one gnuplot picture on one page.
- It has no set or get methods.
+ into it, and to be able to put more than one gnuplot/SVG picture on one
+ page. It has no set or get methods.
Examples:
@@ -1248,13 +1263,11 @@ make editing of multiline commands transparent.
Notes:
- Normally you won't have to define fileplot weblinks manually, as
- fhemweb.pl (webpgm2) makes it easy for you, just plot a logfile (see
+ FHEMWEB makes it easy for you, just plot a logfile (see
logtype) and convert it to weblink. Now you
can group these weblinks by putting them into rooms. If you convert
the current logfile to a weblink, it will always refer to the current
file (and not the one you originally specified).
- - The 99_weblink.pm module is in the contrib directory, you have
- to "install" it manually by copying it into the FHEM directory.
@@ -1271,11 +1284,6 @@ make editing of multiline commands transparent.
define myvar dummy
set myvar 7
- Notes:
-
- - The 99_dummy.pm module is in the contrib directory, you have
- to "install" it manually by copying it into the FHEM directory.
-
>
@@ -2221,8 +2229,8 @@ Send buffer:
2007-10-19 00:31:24 desired-temp 22.5
- If you add the 99_SUNRISE_EL.pm from the contrib directory to your module
- directory, then you have access to the following functions:
+ By using the 99_SUNRISE_EL.pm module, you have access to the following
+ functions:
sunset_rel()
sunset_abs()
diff --git a/docs/faq.html b/docs/faq.html
index 703983926..7aa45a0ff 100644
--- a/docs/faq.html
+++ b/docs/faq.html
@@ -48,11 +48,8 @@ me?
13. I'd like to see directly in the Web frontend if a window is open. How to do that?
-
-
-
-
-
+
+
1. I am using fhem.pl with an fhz1000.pl config file and fhem.pl won't
@@ -123,9 +120,11 @@ start
5. I have the code for my devices in the ELV notation, which contains 1,2,3
-and 4, but you require a hex code.
How should I convert it?
+and 4, but fhem requires a hex code. How should I convert it?
+ Note: current fhem versions accept FS20 codes in ELV notation.
+
The code used by ELV is in the "quaternal" (?) system plus one added to each
digit, so you can even use the 4 button remote for programming. To convert,
you have two choices: the program four2hex in the contrib directory, or the
@@ -154,7 +153,7 @@ and 4, but you require a hex code.
How should I convert it?
-6. I replaced my FHZ1X00PC, now the FHT80b's does not work anymore.
+6. I replaced my FHZ1X00PC, now the FHT80b's does not work anymore.
Help me!
The FHT80b's are talking to a single FHZ1XXX device, which has a unique
@@ -174,8 +173,8 @@ Help me!
-7. I can specify an optional ml/raincounter for a KS300.
-Why do you think that 255 should be the default?
+7. I can specify an optional ml/raincounter for a KS300. Why do you think
+that 255 should be the default?
The manual talks about 0.3l resolution, but I wanted to calibrate my device.
So I filled a plastic bottle with 0.5 liter water from the measuring cup,
@@ -195,7 +194,7 @@ Why do you think that 255 should be the default?
8. The time specification of the builtin at command is not very
-flexible.
Please add day/month/weekday to it.
+flexible. Please add day/month/weekday to it.
I think the command is complex and flexible enough. Use a perl expression
for this functionality like (described in the commandref.html):
@@ -230,22 +229,18 @@ by fhem.pl?
11. I'd like to use this sunrise/sunset stuff, can you help me?
- Copy contrib/99_SUNRISE_EL.pm into your FHEM directory.
- Next look for the geographic coordinates of your home, e.g with a GPS
+ Look for the geographic coordinates of your home, e.g with a GPS
receiver or with googleearth. Compute the latitude/longitude as needed, and
enter them in your lastinclude file with the command:
{sunrise_coord("", "", "") }
- If everything is ok, typing
- { sunrise_abs() }
- in the telnet prompt, will return the time of the sunrise today, in a
- HH:MM:SS format.
+ After restart, { sunrise_abs() } will return the time of the sunrise today,
+ in a HH:MM:SS format.
- 99_SUNRISE_EL.pm is the ExtraLight version of the original 99_SUNRISE.pm,
- which needs the DateTime::Event::Sunrise perl module, which in turn is
- usually difficult to install. If you still want to use the original module,
- then the initialization string will be slightly different:
+ Note: 99_SUNRISE_EL.pm is the ExtraLight version of the original
+ 99_SUNRISE.pm, which needs the DateTime::Event::Sunrise perl module, which
+ in turn is usually difficult to install. If you still want to use the
+ original module, then the initialization string will be slightly different:
{sunrise_coord("", "", "Europe/Berlin") }
-
diff --git a/docs/fhem.html b/docs/fhem.html
index 547f15f91..65bfbc423 100644
--- a/docs/fhem.html
+++ b/docs/fhem.html
@@ -13,8 +13,11 @@
GPL'd server to access devices like FHZ1000/FHZ1300,EM1010PC,WS300,SCIVT.
Formerly known as fhz1000.pl
-Current Version: (as of =DATE=) is =VERS=
-See the CHANGED file for current changes.
+Current Version: (as of =DATE=) is =VERS=
+
+See the CHANGED file for current changes, or the webfrontends section for screenshots.
Description
@@ -45,7 +48,8 @@ Currently implemented features:
- reading EM1000WZ/EM1000EM/EM1000GZ data via an attached EM1010PC
- reading attached SCIVT devices
- reading attached M232 devices
- - reading attached WS2000/WS25000 devices, also via raw network converters(xport)
+ - reading attached WS2000/WS25000 devices, also via raw network
+ converters(xport)
- extract sensor data from IPWE networked weather data receiver
- logging events to files or databases, with regexp filters
- notifying external programs or internal modules when receiving certain
@@ -55,8 +59,8 @@ Currently implemented features:
- different web frontends, choose your favorite
-See commandref.html for a detailed command
-description and faq.html for the F.A.Q.
+See HOWTO.html, commandref.html
+and faq.html for more documentation.
Links:
@@ -123,37 +127,25 @@ description and faq.html for the F.A.Q.
Server installation on Unix
- - Copy the file
fhem.pl
into your path (e.g.
- /usr/local/bin
), and the FHEM directory e.g. to
- /usr/local/lib
.
- - Copy additional modules from the contrib directory
- (like 99_SUNRISE_EL.pm)
- - Make sure that you can access the serial USB
- device (e.g.
/dev/tts/USB0
).
- - Create a configuration file (see the examples directory and
- docs/commandref.html), change at least the modpath
- (
/usr/local/lib
) and define FHZ FHZ (/dev/tts/USB0
)
- parameters.
+ - Check the Makefile for the installation path, then type make install.
+ - Create a configuration file (see the examples directory or
+ docs/commandref.html).
- Start the server with
fhem.pl <configfile>
Server installation on Windows
If you are using cygwin for your perl installation you can follow the guidelines for Unix.
- - be sure you have perl.exe in your path (%PATH%)
- - unpack distribution in a directory of your choice
- - Copy additional modules from the contrib directory
- (like 99_SUNRISE_EL.pm)
- - Make sure that you can access the serial USB
- device via virtual COM-Port or via socket(e.g.
COMX or xport:10001
).
+ - Be sure you have perl.exe in your path (%PATH%)
+ - Make sure that you can access the serial USB device via virtual COM-Port
+ or via socket(e.g.
COMX or xport:10001
).
- Create a configuration file (see the examples directory and
- docs/commandref.html), change at least the modpath
- (
your_install_dir
) and define FHZ FHZ (COM10
)
- parameters.
+ docs/commandref.html)
Start the server with fhem.pl <configfile>
+
General Notes for Webfrontends:
- You don't have to install all of them, one is probably more than
@@ -171,10 +163,15 @@ If you are using cygwin for your perl installation you can follow the guidelines
displaying logfiles as text or plot (SVG builtin or PNG by gnuplot),
navigating/zooming in the plots.
- Screenshots: overview, detail,
- SVG-plots.
+ Screenshots: overview, detail, SVG-plots.
- For installation see the webpgm/pgm2/README file.
+ Installation: make install-pgm2 && perl fhem.pl
+
+ Connect to fhem via http://localhost:8083/fhem. See the
+ Howto there on how to continue.
+
Web frontend 3 (webfrontend/pgm3)
diff --git a/docs/pgm2-1.png b/docs/pgm2-1.png
index a93593b84..5913227d4 100644
Binary files a/docs/pgm2-1.png and b/docs/pgm2-1.png differ
diff --git a/fhem.pl b/fhem.pl
index f6ec95327..cad54a79e 100755
--- a/fhem.pl
+++ b/fhem.pl
@@ -143,7 +143,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.48 2008-07-25 14:14:24 rudolfkoenig Exp $';
+my $cvsid = '$Id: fhem.pl,v 1.49 2008-07-28 12:33:29 rudolfkoenig Exp $';
$init_done = 0;
@@ -633,7 +633,7 @@ CommandInclude($$)
my $bigcmd = "";
$rcvdquit = 0;
while(my $l = <$fh>) {
- chomp($l);
+ $l =~ s/[\r\n]//g;
if($l =~ m/^(.*)\\$/) { # Multiline commands
$bigcmd .= "$1\\\n";
} else {
@@ -1004,7 +1004,7 @@ AssignIoPort($)
my ($hash) = @_;
# Set the I/O device
- for my $p (sort { $defs{$b}{NR} cmp $defs{$a}{NR} } keys %defs) {
+ for my $p (sort { $defs{$b}{NR} <=> $defs{$a}{NR} } keys %defs) {
my $cl = $modules{$defs{$p}{TYPE}}{Clients};
if(defined($cl) && $cl =~ m/:$hash->{TYPE}:/) {
$hash->{IODev} = $defs{$p};
@@ -1369,7 +1369,8 @@ GlobalAttr($$)
foreach my $m (sort readdir(DH)) {
next if($m !~ m/^([0-9][0-9])_(.*)\.pm$/);
$modules{$2}{ORDER} = $1;
- CommandReload(undef, $m) if($1 eq "99"); # Alway load util functions
+ CommandReload(undef, $m) # Always load utility modules
+ if($1 eq "99" && $modules{$2} && !$modules{$2}{LOADED});
$counter++;
}
closedir(DH);
@@ -1772,7 +1773,9 @@ DoTrigger($$)
} elsif(!defined($defs{$dev}{CHANGED})) {
return "";
}
- $defs{$dev}{STATE} = $defs{$dev}{CHANGED}[0];
+
+ # Done by the modules to be able to ignore unimportant messages
+ #$defs{$dev}{STATE} = $defs{$dev}{CHANGED}[0];
# STATE && {READINGS}{state} should be the same
my $r = $defs{$dev}{READINGS};
diff --git a/webfrontend/pgm2/01_FHEMWEB.pm b/webfrontend/pgm2/01_FHEMWEB.pm
index e79f47a91..6a994a21e 100755
--- a/webfrontend/pgm2/01_FHEMWEB.pm
+++ b/webfrontend/pgm2/01_FHEMWEB.pm
@@ -27,6 +27,7 @@ sub FHEMWEB_checkDirs();
sub FHEMWEB_digestCgi($);
sub FHEMWEB_doDetail($);
sub FHEMWEB_fileList($);
+sub FHEMWEB_getAttr($$);
sub FHEMWEB_makeTable($$$$$$$$);
sub FHEMWEB_parseXmlList($);
sub FHEMWEB_showRoom();
@@ -64,6 +65,7 @@ my $__SF; # Short for submit form
my $__ti; # Tabindex for all input fields
my @__zoom; # "qday", "day","week","month","year"
my %__zoom; # the same as @__zoom
+my $__wname; # Web instance name
my $__plotmode; # Current plotmode
my $__plotsize; # Size for a plot
my $__data; # Filecontent from browser when editing a file
@@ -81,8 +83,7 @@ FHEMWEB_Initialize($)
$hash->{DefFn} = "FHEMWEB_Define";
$hash->{UndefFn} = "FHEMWEB_Undef";
- $hash->{AttrFn} = "FHEMWEB_Attr";
- $hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 webname plotmode:gnuplot,gnuplot-scroll,SVG plotsize";
+ $hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 webname plotmode:gnuplot,gnuplot-scroll,SVG plotsize refresh";
}
#####################################
@@ -123,22 +124,10 @@ sub
FHEMWEB_Undef($$)
{
my ($hash, $arg) = @_;
- close($hash->{PORT});
+ close($hash->{PORT}) if(defined($hash->{PORT})); # Clients do not have PORT
return undef;
}
-#####################################
-sub
-FHEMWEB_Attr(@)
-{
- my @a = @_;
-
- if($a[0] eq "set" && $a[2] eq "plotmode" && $a[3] eq "SVG" &&
- !$modules{SVG}{LOADED}) {
- CommandReload(undef, "98_SVG");
- }
-}
-
#####################################
sub
FHEMWEB_Read($)
@@ -175,11 +164,11 @@ FHEMWEB_Read($)
}
- my $name = $hash->{SNAME};
- my $ll = GetLogLevel($name,4);
+ $__wname = $hash->{SNAME};
+
+ my $ll = GetLogLevel($__wname,4);
$FHEMWEBdir = "$attr{global}{modpath}/FHEM";
- $__ME = "/" . (($attr{$name} && $attr{$name}{webname}) ?
- $attr{$name}{webname} : "fhem");
+ $__ME = "/" . FHEMWEB_getAttr("webname", "fhem");
$FHEMWEB_reldoc = "$__ME/commandref.html";
$__SF = "