From 5e07c2e6b2cf1aaa39a360c6d578f3bea098ab53 Mon Sep 17 00:00:00 2001 From: tdressler <> Date: Sun, 18 May 2008 12:06:02 +0000 Subject: [PATCH] add IPWE support git-svn-id: https://svn.fhem.de/fhem/trunk@196 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/88_IPWE.pm | 150 ++++++++++++++++++++++++++++++++++++++ fhem/HISTORY | 3 + fhem/docs/commandref.html | 64 +++++++++++++++- fhem/docs/fhem.html | 5 +- 5 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 fhem/FHEM/88_IPWE.pm diff --git a/fhem/CHANGED b/fhem/CHANGED index 6683ecbd5..a8e9ebc70 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -404,3 +404,4 @@ - feature: fhem.pl check modules for compiletime errors and do not initialize them - feature: M232 add windows support (thomas 12.05.08) + - feature: add simple ELV IPWE1 support (thomas 12.05.08) \ No newline at end of file diff --git a/fhem/FHEM/88_IPWE.pm b/fhem/FHEM/88_IPWE.pm new file mode 100644 index 000000000..25fa1ca3a --- /dev/null +++ b/fhem/FHEM/88_IPWE.pm @@ -0,0 +1,150 @@ + +package main; +############################################## +# 88_IPWE.pm +# Modul for FHEM +# +# contributed by thomas dressler 2008 +# $Id: 88_IPWE.pm,v 1.1 2008-05-18 12:05:24 tdressler Exp $ + +use strict; +use warnings; +use IO::Socket::INET; + +use vars qw {%attr $init_done}; #make komodo happy +sub Log($$); +##################################### + +sub +IPWE_Initialize($) +{ + my ($hash) = @_; + # Consumer + $hash->{DefFn} = "IPWE_Define"; + $hash->{GetFn} = "IPWE_Get"; + $hash->{AttrList}= "model:ipwe delay loglevel:0,1,2,3,4,5,6"; +} + +##################################### + +sub +IPWE_Define($$) +{ + my ($hash, $def) = @_; + my $name=$hash->{NAME}; + my @a = split("[ \t][ \t]*", $def); + Log 5, "IPWE Define: $a[0] $a[1] $a[2] $a[3]"; + return "Define the host as a parameter i.e. ipwe" if(@a < 3); + + my $host = $a[2]; + my $delay=$a[3]; + $attr{$name}{delay}=$delay if $delay; + Log 1, "ipwe device is none, commands will be echoed only" if($host eq "none"); + + my $socket = IO::Socket::INET->new(PeerAddr=>$host, + PeerPort=>80, #http + timeout=>2, + blocking=>1 + ); + + if (!$socket) { + $hash->{STATE} = "error opening device"; + Log 1,"$name: Error opening Connection to $host"; + return "Can't Connect to $host -> $@ ( $!)\n"; + } + $socket->close; + $hash->{Host} = $host; + $hash->{STATE} = "Initialized"; + InternalTimer(gettimeofday()+$delay, "IPWE_GetStatus", $hash, 0); + return undef; + +} + +sub IPWE_Get($@) +{ + my ($hash, @a) = @_; + return "argument is missing" if(int(@a) != 2); + my $msg; + $hash->{LOCAL} = 1; + my $v = IPWE_GetStatus($hash); + delete $hash->{LOCAL}; + my @data=split (/\n/, $v); + if($a[1] eq "status") { + $msg= "$a[0] $a[1] =>".$/."$v"; + }else { + my ($l)= grep {/$a[1]/}@data; + chop($l); + $msg="$a[0] $a[1] =>$l"; + } + $msg="$a[0]: Unknown get command $a[1]" if (!$msg); + return $msg; + } + + + + + + +##################################### + +sub +IPWE_GetStatus($) +{ + my ($hash) = @_; + + my $buf; + Log 5, "IPWE_GetStatus"; + my $name = $hash->{NAME}; + my $host = $hash->{Host}; + my $text=''; + my $alldata=''; + + my $delay=$attr{$name}{delay}||300; + InternalTimer(gettimeofday()+$delay, "IPWE_GetStatus", $hash, 0); + my $socket = IO::Socket::INET->new(PeerAddr=>$host, + PeerPort=>80, #http + timeout=>2, + blocking=>1 + ); + + if (!$socket) { + $hash->{STATE} = "error opening device"; + Log 1,"$name: Error opening Connection to $host"; + return "Can't Connect to $host -> $@ ( $!)\n"; + } + Log 5, "$name: Connected to $host"; + + $socket->autoflush(1); + $socket->write("GET /ipwe.cgi HTTP/1.0\r\n"); + my @lines=$socket->getlines(); + close $socket; + Log 5,"$name: Data received"; + + my $allines=join('',@lines); + my (@tables)= ($allines=~m#(?:(?!).)*#sgi); + my ($datatable)=grep{/Sensortyp/} @tables; + my (@rows)=($datatable=~m#(?:(?!).)*#sgi); + foreach my $l(@rows) { + next if ($l=~/Sensortyp/); #headline + my ($typ,$id,$sensor,$temp,$hum,$wind,$rain)=($l=~m#(.*?)
#sgi); + next if ($typ=~/^\s+$/); + $text= "Typ: $typ, ID: $id, Name $sensor, T: $temp H: $hum"; + if ($id == 8) { + $text.= ",W: $wind, R: $rain"; + } + Log 5,"$name: $text"; + if (!$hash->{local}){ + $hash->{CHANGED}[0] = $text; + $hash->{READINGS}{$sensor}{TIME} = TimeNow(); + $hash->{READINGS}{$sensor}{VAL} = $text;; + DoTrigger($name, undef) if($init_done); + } + + $alldata.="$text\n"; + } + return $alldata; +} + + +1; + diff --git a/fhem/HISTORY b/fhem/HISTORY index 9d40e64a9..57752a883 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -278,3 +278,6 @@ -tdressler Mo May 12 19:00:00 MEST 2008 - feature : add windows support to M232 + +-tdressler So May 18 13:30:00 MEST 2008 + - feature : add ELV IPWE1 support \ No newline at end of file diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 4b60671a6..a0d52625f 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -427,6 +427,7 @@ make editing of multiline commands transparent.

  • WS300: ws300pc
  • EM1010: em1010pc
  • WS2000: ws2000
  • +
  • IPWE: ipwe

  • @@ -926,6 +927,41 @@ make editing of multiline commands transparent.


    + +

    Type IPWE

    + +

    Type FileLog

    - + +

    Type WS2000:

    + + + +

    Type IPWE

    + diff --git a/fhem/docs/fhem.html b/fhem/docs/fhem.html index f9b3e456a..ebe5b47f2 100644 --- a/fhem/docs/fhem.html +++ b/fhem/docs/fhem.html @@ -15,7 +15,7 @@ Formerly known as fhz1000.pl

    News (as of =DATE=, Version =VERS=)