From 473ec763ad3dc2b66f200efed689ee25da057bde Mon Sep 17 00:00:00 2001 From: borisneubert Date: Fri, 18 Apr 2014 13:42:28 +0000 Subject: [PATCH] 02_RSS.pm: HTTPS enabled, png as image type added, autofreshing HTML page with image map added git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@5553 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/02_RSS.pm | 116 +++++++++++++++++++++++++++++++++----------- 2 files changed, 89 insertions(+), 29 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 995bc98e6..fc7dbed24 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,6 +1,8 @@ # 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. - SVN + - feature: 02_RSS.pm: HTTPS enabled, png as image type added, autofreshing + HTML page with image map added - feature: ECMD and ECMDDevice completely reworked, see http://forum.fhem.de/index.php/topic,21515.0.html - feature: new layout command rect and new attribute bgcolor for RSS diff --git a/fhem/FHEM/02_RSS.pm b/fhem/FHEM/02_RSS.pm index 4a607f7e9..5059696ea 100644 --- a/fhem/FHEM/02_RSS.pm +++ b/fhem/FHEM/02_RSS.pm @@ -46,7 +46,7 @@ RSS_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "RSS_Define"; #$hash->{AttrFn} = "RSS_Attr"; - $hash->{AttrList}= "size bg bgcolor tmin"; + $hash->{AttrList}= "size bg bgcolor tmin refresh areas"; $hash->{SetFn} = "RSS_Set"; RSS_addExtension("RSS_CGI","rss","RSS"); @@ -80,7 +80,7 @@ RSS_Define($$) { my @a = split("[ \t]+", $def); - return "Usage: define RSS jpg hostname filename" if(int(@a) != 5); + return "Usage: define RSS jpg|png hostname filename" if(int(@a) != 5); my $name= $a[0]; my $style= $a[2]; my $hostname= $a[3]; @@ -131,7 +131,8 @@ sub RSS_getURL($) { my ($hostname)= @_; # http://hostname:8083/fhem - return "http://$hostname:" . $defs{$FW_wname}{PORT} . $FW_ME; + my $proto = (AttrVal($FW_wname, 'HTTPS', 0) == 1) ? 'https' : 'http'; + return $proto."://$hostname:" . $defs{$FW_wname}{PORT} . $FW_ME; } # ################## @@ -190,10 +191,12 @@ RSS_splitRequest($) { } else { # http://hostname:8083/fhem/rss/myDeviceName.rss # http://hostname:8083/fhem/rss/myDeviceName.jpg + # http://hostname:8083/fhem/rss/myDeviceName.png + # http://hostname:8083/fhem/rss/myDeviceName.html my $call= $request; $call =~ s/^.*\/rss\/([^\/]*)$/$1/; my $name= $call; - $name =~ s/^(.*)\.(jpg|rss)$/$1/; + $name =~ s/^(.*)\.(jpg|png|rss|html)$/$1/; my $ext= $call; $ext =~ s/^$name\.(.*)$/$1/; return ($name,$ext); @@ -206,12 +209,28 @@ RSS_returnRSS($) { my ($name) = @_; my $url= RSS_getURL($defs{$name}{fhem}{hostname}); - - my $code= "$name1"; + my $type = $defs{$name}{fhem}{style}; + my $mime = ($type eq 'png')? 'image/png' : 'image/jpeg'; + my $code= "$name1"; return ("application/xml; charset=utf-8", $code); } +################## +sub +RSS_returnHTML($) { + my ($name) = @_; + + my $url= RSS_getURL($defs{$name}{fhem}{hostname}); + my $type = $defs{$name}{fhem}{style}; + my $img= "$url/rss/$name.$type"; + my $refresh= AttrVal($name, 'refresh', 60); + my $areas= AttrVal($name, 'areas', ""); + my $mime = ($type eq 'png')? 'image/png' : 'image/jpeg'; + my $code= "\n \n $name\n \n \n \n \n \n $areas\n \n \n"; + return ("text/html; charset=utf-8", $code); +} + ################## # Library ################## @@ -547,8 +566,8 @@ RSS_evalLayout($$@) { ################## sub -RSS_returnJPEG($) { - my ($name)= @_; +RSS_returnIMG($$) { + my ($name,$type)= @_; my ($width,$height)= split(/x/, AttrVal($name,"size","800x600")); @@ -641,9 +660,10 @@ RSS_returnJPEG($) { }; warn $@ if $@; # - # return jpeg image + # return image # - return ("image/jpeg; charset=utf-8", $S->jpeg); + return ("image/jpeg; charset=utf-8", $S->jpeg) if $type eq 'jpg'; + return ("image/png; charset=utf-8", $S->png) if $type eq 'png'; } ################## @@ -652,9 +672,9 @@ RSS_returnJPEG($) { sub RSS_CGI(){ - my ($request) = @_; # /rss or /rss/name.rss or /rss/name.jpg + my ($request) = @_; # /rss or /rss/name.rss or /rss/name.jpg or /rss/name.png - my ($name,$ext)= RSS_splitRequest($request); # name, ext (rss, jpg) + my ($name,$ext)= RSS_splitRequest($request); # name, ext (rss, jpg, png) if(defined($name)) { if($ext eq "") { @@ -665,9 +685,13 @@ RSS_CGI(){ } if($ext eq "jpg") { - return RSS_returnJPEG($name); + return RSS_returnIMG($name,'jpg'); + } elsif($ext eq "png") { + return RSS_returnIMG($name,'png'); } elsif($ext eq "rss") { return RSS_returnRSS($name); + } elsif($ext eq "html") { + return RSS_returnHTML($name); } } else { return RSS_Overview(); @@ -689,31 +713,60 @@ RSS_CGI(){

RSS

    - Provides a freely configurable RSS feed.

    + Provides a freely configurable RSS feed and HTML page.

    - Currently a media RSS feed delivering status pictures in JPEG format is supported. This media - RSS feed can be used to feed a status display to a network-enabled photo frame.

    + The media RSS feed delivers status pictures either in JPEG or PNG format. + + This media RSS feed can be used to feed a status display to a + network-enabled photo frame.

    + + In addition, a periodically refreshing HTML page is generated that shows the picture + with an optional HTML image map.

    You need to have the perl module GD installed. This module is most likely not available for small systems like Fritz!Box.

    - RSS is an extension to FHEMWEB. You must install FHEMWEB to use RSS.

    + RSS is an extension to FHEMWEB. You must install FHEMWEB to use RSS.

    + + Beginners might find the RSS Workshop useful.

    Define

      - define <name> RSS jpg <hostname> <filename>

      + define <name> RSS jpg|png <hostname> <filename>

      - Defines the RSS feed. jpg is a fixed literal to allow for future - extensions. <hostname> is the hostname of the fhem server as + Defines the RSS feed. jpg and png are fixed literals to select output format. + <hostname> is the hostname of the fhem server as seen from the consumer of the RSS feed. <filename> is the name of the file that contains the layout definition.

      - Examples: + Examples

        define FrameRSS RSS jpg host.example.org /etc/fhem/layout
        - define MyRSS RSS jpg 192.168.1.222 /var/fhem/conf/layout.txt
        + define MyRSS RSS png 192.168.1.222 /var/fhem/conf/layout.txt

      + + The RSS feeds are at +
        + http://host.example.org:8083/fhem/rss/FrameRSS.rss
        + http://192/168.1.222:8083/fhem/rss/MyRSS.rss
        +
      +
      + + The pictures are at +
        + http://host.example.org:8083/fhem/rss/FrameRSS.jpg
        + http://192/168.1.222:8083/fhem/rss/MyRSS.png
        +
      +
      + + The HTML pages are at +
        + http://host.example.org:8083/fhem/rss/FrameRSS.html
        + http://192/168.1.222:8083/fhem/rss/MyRSS.html
        +
      +
      +
    @@ -730,7 +783,7 @@ RSS_CGI(){ Attributes

      -
    • size
      The dimensions of the JPEG picture in the format +
    • size
      The dimensions of the picture in the format <width>x<height>.

    • bg
      The directory that contains the background pictures (must be in JPEG format).

    • bgcolor <color>
      Sets the background color. <color> is @@ -738,6 +791,10 @@ RSS_CGI(){ color components as in HTML color codes (e.g.FF0000 for red, C0C0C0 for light gray).

    • tmin
      The background picture is shown at least tmin seconds, no matter how frequently the RSS feed consumer accesses the page.

    • +
    • refresh
      Time after which the HTML page is automatically reloaded.

    • +
    • areas
      HTML code that goes into the image map.
      + Example: attr FrameRSS areas <area shape="rect" coords="0,0,200,200" href="http://fhem.de"/><area shape="rect" coords="600,400,799,599" href="http://has:8083/fhem" target="_top"/> +



    @@ -754,20 +811,21 @@ RSS_CGI(){ Example:
      http://host.example.org:8083/fhem/rss/FrameRSS.rss

    - The media RSS feed points to a dynamically generated JPEG picture. The URL of the JPEG picture - belonging to the RSS feed is http://hostname:port/fhem/rss/name.jpg, i.e. the URL - of the RSS feed with the extension rss changed to jpg.

    + The media RSS feed points to a dynamically generated picture. The URL of the picture + belonging to the RSS can be found by replacing the extension ".rss" in feed's URL by ".jpg" or ".png" + depending on defined output format,

    Example:

      http://host.example.org:8083/fhem/rss/FrameRSS.jpg

    +

      http://192.168.100.200:8083/fhem/rss/FrameRSS.png

    - To render the JPEG picture the current, or, if tmin seconds have elapsed, the next + To render the picture the current, or, if tmin seconds have elapsed, the next JPEG picture from the directory bg is chosen and scaled to the dimensions given in size. The background is black if no usable JPEG picture can be found. Next the script in the layout definition is used to superimpose items on the background.

    - You can directly access the URL of the JPEG picture in your browser. Reload the page to see + You can directly access the URL of the picture in your browser. Reload the page to see how it works.

    The media RSS feed advertises to refresh after 1 minute (ttl). Some photo frames ignore it and @@ -857,7 +915,7 @@ RSS_CGI(){ access device readings and do some programming on the fly. See below for examples.

  • textbox <x> <y> <boxwidth> <text>
    Same as before but text is rendered in a box of horizontal width <boxwidth>.

  • time <x> <y>
    Renders the current time in HH:MM format.

  • -
  • seconds <x> <y> <format>
    Renders the curent seconds. Maybe usefull for a RSS Clock. With option colon a :

  • +
  • seconds <x> <y> <format>
    Renders the curent seconds. Maybe useful for a RSS Clock.

  • date <x> <y>
    Renders the current date in DD:MM:YYY format.

  • line <x1> <y1> <x2> <y2> [<thickness>]
    Draws a line from position (<x1>, <y1>) to position (<x2>, <y2>) with optional thickness (default=1).

  • rect <x1> <y1> <x2> <y2> [<filled>]
    Draws a rectangle with corners at positions (<x1>, <y1>) and (<x2>, <y2>), which is filled if the <filled> parameter is set and not zero.