diff --git a/CHANGED b/CHANGED
index 9f8508f0b..88ef72f6c 100644
--- a/CHANGED
+++ b/CHANGED
@@ -20,6 +20,7 @@
- feature: FHEMWEB console (== inform timer)
- feature: remove dependency on Google::Weather, major rewrite (Boris)
- feature: started experimental interface implementation (fhem API v2) (Boris)
+ - feature: sleep issued in at/notify/etc is not blocking fhem anymore
- 2011-12-31 (5.2)
diff --git a/docs/commandref.html b/docs/commandref.html
index ef28fe532..6f4b0acca 100644
--- a/docs/commandref.html
+++ b/docs/commandref.html
@@ -1020,12 +1020,11 @@ A line ending with \ will be concatenated with the next one, so long lines
Example:
sleep 0.5
- notify btn3 set lamp toggle;;sleep 0.5;;set lamp toggle
+ define n3 notify btn3.* set lamp toggle;;sleep 0.5;;set lamp toggle
- Note: As the server is not multithreaded, everything is blocked for
- the given amount.
-
+ Note: sleep followed by another command and issued in at/notify/etc is not
+ blocking fhem.
diff --git a/fhem.pl b/fhem.pl
index 110c65c53..513374153 100755
--- a/fhem.pl
+++ b/fhem.pl
@@ -183,6 +183,7 @@ my $namedef =
"- a range seperated by dash (-)\n";
my $stt_sec; # Used by SecondsTillTomorrow()
my $stt_day; # Used by SecondsTillTomorrow()
+my @cmdList; # Remaining commands in a chain. Used by sleep
$init_done = 0;
@@ -683,7 +684,8 @@ AnalyzeCommandChain($$)
$cmd =~ s/#.*$//s;
$cmd =~ s/;;/SeMiCoLoN/g;
- foreach my $subcmd (split(";", $cmd)) {
+ @cmdList = split(";", $cmd);
+ while(my $subcmd = shift @cmdList) {
$subcmd =~ s/SeMiCoLoN/;/g;
my $lret = AnalyzeCommand($c, $subcmd);
push(@ret, $lret) if(defined($lret));
@@ -725,7 +727,6 @@ AnalyzeCommand($$)
$cmd =~ s/^(\\\n|[ \t])*//;# Strip space or \\n at the begginning
$cmd =~ s/[ \t]*$//;
-
Log 5, "Cmd: >$cmd<";
return undef if(!$cmd);
@@ -1929,10 +1930,26 @@ CommandSleep($$)
return "Cannot interpret $param as seconds" if($param !~ m/^[0-9\.]+$/);
Log 4, "sleeping for $param";
- select(undef, undef, undef, $param);
+
+ if(!$cl && @cmdList && $param && $init_done) {
+ InternalTimer(gettimeofday()+$param, "WakeUpFn", join(";;", @cmdList), 0);
+ @cmdList=();
+
+ } else {
+ select(undef, undef, undef, $param);
+
+ }
return undef;
}
+sub
+WakeUpFn($)
+{
+ my $param = shift;
+ my $ret = AnalyzeCommandChain(undef, $param);
+ Log 2, "After sleep: $ret" if($ret);
+}
+
#####################################
# Return the time to the next event (or undef if there is none)