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#define <name> IPWE <hostname> [<delay>]
+ delay
: seconds between read accesses(default 300s)define ipwe IPWE ipwe1 120
attr ipwe delay 600
: 10min between readoutslist
statement for the device).
get <name> list
+ get <name> [TH0..TH7, T0..T7, I0..I7, R0..R7, W0..W7, L0..L7, P0..P7,LAST,RAW]
LAST
: Last received Sensor
+ RAW
: original Data from interface
+ get <name> status
+ get <name> < sensorname>
+