From 924e4b58a301e9c000eca3b624df321aaff64a77 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 26 Feb 2012 13:36:53 +0000 Subject: [PATCH] FHEMWEB console git-svn-id: https://svn.fhem.de/fhem/trunk@1296 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/webfrontend/pgm2/01_FHEMWEB.pm | 60 +++++++++++++++++++++-------- fhem/webfrontend/pgm2/console.js | 30 +++++++++++++++ fhem/webfrontend/pgm2/longpoll.js | 8 ---- 4 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 fhem/webfrontend/pgm2/console.js diff --git a/fhem/CHANGED b/fhem/CHANGED index dc037af8b..d377d5959 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -16,6 +16,7 @@ - feature: webCmd in smallScreen added - feature: TRX modules by Willi - feature: FHEMWEB icons (by Joerg) + - feature: FHEMWEB console (== inform timer) - 2011-12-31 (5.2) - bugfix: applying smallscreen attributes to firefox/opera diff --git a/fhem/webfrontend/pgm2/01_FHEMWEB.pm b/fhem/webfrontend/pgm2/01_FHEMWEB.pm index 15636ee28..3e579effe 100755 --- a/fhem/webfrontend/pgm2/01_FHEMWEB.pm +++ b/fhem/webfrontend/pgm2/01_FHEMWEB.pm @@ -417,7 +417,7 @@ FW_AnswerCall($) $FW_cmdret = $docmd ? FW_fC($cmd) : ""; if($FW_inform) { # Longpoll header - $me->{inform} = $FW_room; + $me->{inform} = ($FW_room ? $FW_room : $FW_inform); # NTFY_ORDER is larger than the normal order (50-) $me->{NTFY_ORDER} = $FW_cname; # else notifyfn won't be called my $c = $me->{CD}; @@ -806,6 +806,7 @@ FW_roomOverview($) # "Examples", "$FW_ME/cmd=style%20examples", "Edit files", "$FW_ME/cmd=style%20list", "Select style","$FW_ME/cmd=style%20select", + "Console", "$FW_ME/cmd=style%20console", "", ""); my $lastname = ","; # Avoid double "". for(my $idx = 0; $idx < @list; $idx+= 2) { @@ -1576,6 +1577,12 @@ FW_style($$) } FW_pO ""; + } elsif($a[1] eq "console") { + FW_pO ""; + FW_pO "
"; + FW_pO "
"; + FW_pO "
"; + FW_pO "
"; } } @@ -1849,26 +1856,44 @@ FW_Notify($$) return undef if(!$filter); my $ln = $ntfy->{NAME}; - my $dn = $dev->{NAME}; - return undef if($filter ne "all" && AttrVal($dn, "room", "") ne $filter); + my $data; - FW_ReadIcons(); + if($filter eq "all" || AttrVal($dn, "room", "") eq $filter) { + FW_ReadIcons(); - my @old = ($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp); - $FW_wname = $ntfy->{SNAME}; - $FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem"); - $FW_longpoll = 1; - $FW_ss = AttrVal($FW_wname, "smallscreen", 0); - $FW_tp = AttrVal($FW_wname, "touchpad", $FW_ss); - my ($allSet, $cmdlist, $txt) = FW_devState($dn, ""); - ($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp) = @old; + my @old = ($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp); + $FW_wname = $ntfy->{SNAME}; + $FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem"); + $FW_longpoll = 1; + $FW_ss = AttrVal($FW_wname, "smallscreen", 0); + $FW_tp = AttrVal($FW_wname, "touchpad", $FW_ss); + my ($allSet, $cmdlist, $txt) = FW_devState($dn, ""); + ($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp) = @old; + $data = "$dn;$dev->{STATE};$txt\n"; - # Collect multiple changes (e.g. from noties) into one message - $ntfy->{INFORMBUF} = "" if(!defined($ntfy->{INFORMBUF})); - $ntfy->{INFORMBUF} .= "$dn;$dev->{STATE};$txt\n"; - RemoveInternalTimer($ln); - InternalTimer(gettimeofday()+0.1, "FW_FlushInform", $ln, 0); + } elsif($filter eq "console") { + if($dev->{CHANGED}) { # It gets deleted sometimes (?) + my $tn = TimeNow(); + if($attr{global}{mseclog}) { + my ($seconds, $microseconds) = gettimeofday(); + $tn .= sprintf(".%03d", $microseconds/1000); + } + my $max = int(@{$dev->{CHANGED}}); + my $dt = $dev->{TYPE}; + for(my $i = 0; $i < $max; $i++) { + $data .= "$tn $dt $dn ".$dev->{CHANGED}[$i]."
\n"; + } + } + + } + + if($data) { + # Collect multiple changes (e.g. from noties) into one message + $ntfy->{INFORMBUF} .= $data; + RemoveInternalTimer($ln); + InternalTimer(gettimeofday()+0.1, "FW_FlushInform", $ln, 0); + } return undef; } @@ -1881,6 +1906,7 @@ FW_FlushInform($) return if(!$hash); my $c = $hash->{CD}; print $c $hash->{INFORMBUF}; + $hash->{INFORMBUF}=""; CommandDelete(undef, $name); } diff --git a/fhem/webfrontend/pgm2/console.js b/fhem/webfrontend/pgm2/console.js new file mode 100644 index 000000000..c3d081ca2 --- /dev/null +++ b/fhem/webfrontend/pgm2/console.js @@ -0,0 +1,30 @@ +var consConn; + +function +consUpdate() +{ + if(consConn.readyState != 4 || consConn.status != 200) + return; + var el = document.getElementById("console"); + if(el) + el.innerHTML=el.innerHTML+consConn.responseText; + consConn.abort(); + consFill(); +} + +function +consFill() +{ + consConn = new XMLHttpRequest(); + consConn.open("GET", document.location.pathname+"?XHR=1&inform=console", true); + consConn.onreadystatechange = consUpdate; + consConn.send(null); +} + +function +consStart() +{ + setTimeout("consFill()", 1000); +} + +window.onload = consStart; diff --git a/fhem/webfrontend/pgm2/longpoll.js b/fhem/webfrontend/pgm2/longpoll.js index 4f96c452e..163492a38 100644 --- a/fhem/webfrontend/pgm2/longpoll.js +++ b/fhem/webfrontend/pgm2/longpoll.js @@ -1,13 +1,5 @@ var pollConn; -function -cmd(arg) -{ - var req = new XMLHttpRequest(); - req.open("GET", arg, true); - req.send(null); -} - function doUpdate() {