From 7b6b2a67aaab672935c24d5017eec5b0b18d5611 Mon Sep 17 00:00:00 2001 From: borisneubert <> Date: Sat, 7 Mar 2015 10:50:05 +0000 Subject: [PATCH] 02_HTTPSRV: query string sets readings (Stefan Strobel) git-svn-id: https://svn.fhem.de/fhem/trunk@8163 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/02_HTTPSRV.pm | 43 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 37ab2e8bc..3f74e3b1d 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 02_HTTPSRV: query string sets readings (Stefan Strobel) - bugfix: 57_CALVIEW: - bugfix in set function - change: 57_CALVIEW: - fixed function 'set intervall' - see comandref for detail (now use the define diff --git a/fhem/FHEM/02_HTTPSRV.pm b/fhem/FHEM/02_HTTPSRV.pm index 63ed142f0..eb44b3316 100644 --- a/fhem/FHEM/02_HTTPSRV.pm +++ b/fhem/FHEM/02_HTTPSRV.pm @@ -44,7 +44,9 @@ HTTPSRV_Initialize($) { $hash->{DefFn} = "HTTPSRV_Define"; $hash->{UndefFn} = "HTTPSRV_Undef"; #$hash->{AttrFn} = "HTTPSRV_Attr"; - $hash->{AttrList} = "directoryindex"; + $hash->{AttrList} = "directoryindex " . + "readings"; + $hash->{AttrFn} = "HTTPSRV_Attr"; #$hash->{SetFn} = "HTTPSRV_Set"; return undef; @@ -85,6 +87,25 @@ HTTPSRV_Undef($$) { return undef; } +################## +sub +HTTPSRV_Attr(@) +{ + my ($cmd,$name,$aName,$aVal) = @_; + if ($cmd eq "set") { + if ($aName =~ "readings") { + if ($aVal !~ /^[A-Z_a-z0-9\,]+$/) { + Log3 $name, 3, "$name: Invalid reading list in attr $name $aName $aVal (only A-Z, a-z, 0-9, _ and , allowed)"; + return "Invalid reading name $aVal (only A-Z, a-z, 0-9, _ and , allowed)"; + } + addToDevAttrList($name, $aName); + } + } + return undef; +} + + + ################## # # here we answer any request to http://host:port/fhem/$infix and below @@ -108,6 +129,17 @@ sub HTTPSRV_CGI() { # return error if no such device return("text/plain; charset=utf-8", "No HTTPSRV device for $link") unless($name); + my $fullName = $filename; + foreach my $reading (split (/,/, AttrVal($name, "readings", ""))) { + my $value = ""; + if ($fullName =~ /^([^\?]+)\?(.*)($reading)=([^;&]*)([&;].*)?$/) { + $filename = $1; + $value = $4; + Log3 $name, 5, "$name: set Reading $reading = $value"; + readingsSingleUpdate($defs{$name}, $reading, $value, 1); + } + }; + # set directory index $filename= AttrVal($name,"directoryindex","index.html") unless($filename); my $MIMEtype= filename2MIMEType($filename); @@ -147,7 +179,8 @@ sub HTTPSRV_CGI() {

HTTPSRV

@@ -179,6 +217,7 @@ sub HTTPSRV_CGI() {