2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-08 13:24:56 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@1430 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
wherzig 2012-04-09 15:40:35 +00:00
parent 014d2eb71f
commit 63596edd68
5 changed files with 190 additions and 199 deletions

View File

@ -1,30 +1,27 @@
#################################################################################
# 45_TRX.pm
# Module for FHEM
#
# Tested with RFXtrx-Receiver (433.92MHz, USB)
# (see http://www.RFXCOM.com/).
# To use this module, you need to define an RFXTRX transceiver:
# define RFXTRX TRX /dev/ttyUSB0
# FHEM Module for RFXtrx433
#
# The module also has code to access a RFXtrx transceiver attached via LAN.
# Derived from 00_CUL.pm: Copyright (C) Rudolf Koenig"
#
# To use it define the IP-Adresss and the Port:
# define RFXTRX TRX 192.168.169.111:10001
# optionally you may issue not to initialize the device (useful if you share an RFXtrx device with other programs)
# define RFXTRX TRX 192.168.169.111:10001 noinit
# Copyright (C) 2012 Willi Herzig
#
# The RFXtrx transceivers supports lots of protocols that may be implemented for FHEM
# writing the appropriate FHEM modules. See the
#
# Willi Herzig, 2012
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
#################################################################################
# derived from 00_CUL.pm
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The GNU General Public License may also be found at http://www.gnu.org/licenses/gpl-2.0.html .
#
###########################
# $Id$
@ -260,6 +257,52 @@ TRX_DoInit($)
} else {
Log 1, "TRX: Init OK";
$hash->{STATE} = "Initialized" if(!$hash->{STATE});
# Analyse result and display it:
if ($buf =~ m/^\x0d\x01\x00(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/) {
my $status = "";
my $seqnbr = $1;
my $cmnd = $2;
my $msg1 = ord($3);
my $msg2 = ord($4);
my $msg3 = ord($5);
my $msg4 = ord($6);
my $msg5 = ord($7);
my $freq = {
0x50 => '310MHz',
0x51 => '315MHz',
0x52 => '433.92MHz receiver only',
0x53 => '433.92MHz transceiver',
0x55 => '868.00MHz',
0x56 => '868.00MHz FSK',
0x57 => '868.30MHz',
0x58 => '868.30MHz FSK',
0x59 => '868.35MHz',
0x5A => '868.35MHz FSK',
0x5B => '868.95MHz'
}->{$msg1} || 'unknown Mhz';
$status .= $freq;
$status .= ", " . sprintf "firmware=%d",$msg2;
$status .= ", protocols enabled: ";
$status .= sprintf "undecoded, " if ($msg3 & 0x80);
$status .= "ProGuard " if ($msg4 & 0x20);
$status .= "FS20 " if ($msg4 & 0x10);
$status .= "LaCrosse " if ($msg4 & 0x08);
$status .= "Hideki " if ($msg4 & 0x04);
$status .= "LightwaveRF " if ($msg4 & 0x02);
$status .= "Mertik " if ($msg4 & 0x01);
$status .= "Visonic " if ($msg5 & 0x80);
$status .= "ATI " if ($msg5 & 0x40);
$status .= "OREGON " if ($msg5 & 0x20);
$status .= "KOPPLA " if ($msg5 & 0x10);
$status .= "HOMEEASY " if ($msg5 & 0x08);
$status .= "AC " if ($msg5 & 0x04);
$status .= "ARC " if ($msg5 & 0x02);
$status .= "X10 " if ($msg5 & 0x01);
my $hexline = unpack('H*', $buf);
Log 4, "TRX: Init status hexline='$hexline'";
Log 1, "TRX: Init status: '$status'";
}
}
#

View File

@ -1,12 +1,26 @@
#################################################################################
# 46_TRX_ELSE.pm
# Modul for FHEM for unkown RFXTRX messages
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# FHEM module unkown RFXtrx433 messages
#
##################################
# Copyright (C) 2012 Willi Herzig
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The GNU General Public License may also be found at http://www.gnu.org/licenses/gpl-2.0.html .
###################################
#
# values for "set global verbose"
# 4: log unknown protocols

View File

@ -1,24 +1,28 @@
#################################################################################
# 46_TRX_LIGHT.pm
#
# Modul for FHEM for
# "X10" -> X10 lighting
# "ARC" -> ARC
# "AB400D" -> ELRO AB400D
# "WAVEMAN" -> Waveman
# "EMW200" -> Chacon EMW200
# "IMPULS" -> IMPULS
# "AC" -> KlikAanKlikUit, NEXA, CHACON, HomeEasy UK
# "HOMEEASY" -> HomeEasy EU
# "ANSLUT" -> ANSLUT
# "KOPPLA" -> Ikea Koppla
# FHEM module for lighting protocols:
# X10 lighting, ARC, ELRO AB400D, Waveman, Chacon EMW200,
# IMPULS, AC (KlikAanKlikUit, NEXA, CHACON, HomeEasy UK),
# HomeEasy EU, ANSLUT, Ikea Koppla
#
# - ms14a: motion sensor
# - x10: generic X10 sensor
# Copyright (C) 2012 Willi Herzig
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The GNU General Public License may also be found at http://www.gnu.org/licenses/gpl-2.0.html .
#
##################################
#

View File

@ -1,35 +1,25 @@
#################################################################################
# 46_TRX_SECURITY.pm
#
# Modul for FHEM for X10, KD101, Visonic
# - X10 security messages tested for
# - ds10a: X10 Door / Window Sensor or compatible devices
# - ss10a: X10 motion sensor
# - sd90: Marmitek smoke detector
# - kr18: X10 remote control
# FHEM module for X10, KD101, Visonic
#
##################################
# Copyright (C) 2012 Willi Herzig
#
# Willi Herzig, 2012
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
##################################
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Some code from X10security code is derived from http://www.xpl-perl.org.uk/.
# xpl-perl/lib/xPL/RF/X10Security.pm:
# Thanks a lot to Mark Hindess who wrote xPL.
#
#SEE ALSO
# Project website: http://www.xpl-perl.org.uk/
# AUTHOR: Mark Hindess, soft-xpl-perl@temporalanomaly.com
#
#Copyright (C) 2007, 2009 by Mark Hindess
#
#This library is free software; you can redistribute it and/or modify
#it under the same terms as Perl itself, either Perl version 5.8.7 or,
#at your option, any later version of Perl 5 you may have available.
# The GNU General Public License may also be found at http://www.gnu.org/licenses/gpl-2.0.html .
#
##################################
#

View File

@ -1,6 +1,6 @@
#################################################################################
# 46_TRX_WEATHER.pm
# Module for FHEM to decode weather sensor messages for RFXtrx
# FHEM module to decode weather sensor messages for RFXtrx
#
# The following devices are implemented to be received:
#
@ -36,21 +36,34 @@
# * "WGR918_A" is STR918, WGR918
# * "TFA_WIND" is TFA
#
# derived from 41_OREGON.pm
#
# Willi Herzig, 2012
# Copyright (C) 2012 Willi Herzig
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Some code was derived and modified from xpl-perl
# from the following two files:
# xpl-perl/lib/xPL/Utils.pm:
# xpl-perl/lib/xPL/RF/Oregon.pm:
#
#SEE ALSO
# Project website: http://www.xpl-perl.org.uk/
# AUTHOR: Mark Hindess, soft-xpl-perl@temporalanomaly.com
#
# Copyright (C) 2007, 2009 by Mark Hindess
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself, either Perl version 5.8.7 or,
# at your option, any later version of Perl 5 you may have available.
##################################
#
# values for "set global verbose"
# 4: log unknown protocols
# 5: log decoding hexlines for debugging
#
# $Id: $
# $Id$
package main;
use strict;
@ -90,7 +103,6 @@ TRX_WEATHER_Define($$)
my $code = $a[2];
$hash->{CODE} = $code;
#$modules{TRX_WEATHER}{defptr}{$name} = $hash;
$modules{TRX_WEATHER}{defptr}{$code} = $hash;
AssignIoPort($hash);
@ -106,73 +118,25 @@ TRX_WEATHER_Undef($$)
return undef;
}
#########################################
# From xpl-perl/lib/xPL/Util.pm:
sub hi_nibble {
($_[0]&0xf0)>>4;
}
sub lo_nibble {
$_[0]&0xf;
}
sub nibble_sum {
my $c = $_[0];
my $s = 0;
foreach (0..$_[0]-1) {
$s += hi_nibble($_[1]->[$_]);
$s += lo_nibble($_[1]->[$_]);
}
$s += hi_nibble($_[1]->[$_[0]]) if (int($_[0]) != $_[0]);
return $s;
}
# --------------------------------------------
# From xpl-perl/lib/xPL/RF/Oregon.pm:
# This function creates a simple key from a device type and message
# length (in bits). It is used to as the index for the parts table.
sub type_length_key {
($_[0] << 8) + $_[1]
}
# --------------------------------------------
# sensor types
my %types =
(
# TEMP
type_length_key(0x50, 0x08) =>
{
part => 'TEMP', method => \&common_temp,
},
0x5008 => { part => 'TEMP', method => \&common_temp, },
# HYDRO
type_length_key(0x51, 0x08) =>
{
part => 'HYDRO', method => \&common_hydro,
},
0x5108 => { part => 'HYDRO', method => \&common_hydro, },
# TEMP HYDRO
type_length_key(0x52, 0x0a) =>
{
part => 'TEMPHYDRO', method => \&common_temphydro,
},
0x520a => { part => 'TEMPHYDRO', method => \&common_temphydro, },
# TEMP HYDRO BARO
type_length_key(0x54, 0x0d) =>
{
part => 'TEMPHYDROBARO', method => \&common_temphydrobaro,
},
0x540d => { part => 'TEMPHYDROBARO', method => \&common_temphydrobaro, },
# RAIN
type_length_key(0x55, 0x0b) =>
{
part => 'RAIN', method => \&common_rain,
},
0x550b => { part => 'RAIN', method => \&common_rain, },
# WIND
type_length_key(0x56, 0x10) =>
{
part => 'WIND', method => \&common_anemometer,
},
0x5610 => { part => 'WIND', method => \&common_anemometer, },
);
# --------------------------------------------
#my $DOT = q{.};
@ -209,12 +173,12 @@ sub humidity {
my $hum = $bytes->[$off];
my $hum_str = ['dry', 'comfortable', 'normal', 'wet']->[$bytes->[$off+1]];
push @$res, {
device => $dev,
type => 'humidity',
current => $hum,
string => $hum_str,
units => '%'
}
device => $dev,
type => 'humidity',
current => $hum,
string => $hum_str,
units => '%'
}
}
sub pressure {
@ -229,12 +193,12 @@ sub pressure {
0x04 => 'rain',
}->{$bytes->[$off+2]} || 'unknown';
push @$res, {
device => $dev,
type => 'pressure',
current => $hpa,
units => 'hPa',
forecast => $forecast,
}
device => $dev,
type => 'pressure',
current => $hpa,
units => 'hPa',
forecast => $forecast,
};
}
sub simple_battery {
@ -250,10 +214,10 @@ sub simple_battery {
}
push @$res, {
device => $dev,
type => 'battery',
current => $battery,
}
device => $dev,
type => 'battery',
current => $battery,
};
}
sub battery {
@ -270,25 +234,13 @@ sub battery {
}
push @$res, {
device => $dev,
type => 'battery',
current => $battery,
}
device => $dev,
type => 'battery',
current => $battery,
};
}
my @uv_str =
(
qw/low low low/, # 0 - 2
qw/medium medium medium/, # 3 - 5
qw/high high/, # 6 - 7
'very high', 'very high', 'very high', # 8 - 10
);
sub uv_string {
$uv_str[$_[0]] || 'dangerous';
}
# Test if to use longid for device type
sub use_longid {
my ($longids,$dev_type) = @_;
@ -356,20 +308,20 @@ sub common_anemometer {
my $avspeed = $bytes->[7]*256 + $bytes->[8];
my $speed = $bytes->[9]*256 + $bytes->[10];
push @res, {
device => $dev_str,
type => 'speed',
current => $speed,
average => $avspeed,
units => 'mps',
} , {
device => $dev_str,
type => 'direction',
current => $dir,
string => $dirname,
units => 'degrees',
}
;
push @res, {
device => $dev_str,
type => 'speed',
current => $speed,
average => $avspeed,
units => 'mps',
} , {
device => $dev_str,
type => 'direction',
current => $dir,
string => $dirname,
units => 'degrees',
};
simple_battery($bytes, $dev_str, \@res, 15);
return @res;
@ -510,7 +462,6 @@ sub common_temphydro {
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
#Log 1,"dev_str=$dev_str";
my @res = ();
@ -607,7 +558,6 @@ sub common_rain {
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
#Log 1,"dev_str=$dev_str";
my @res = ();
@ -621,27 +571,23 @@ sub common_rain {
my $train = $bytes->[7]*256*256 + $bytes->[8]*256 + $bytes->[9];
push @res, {
device => $dev_str,
type => 'rain',
current => $rain,
units => 'mm/h',
} ;
device => $dev_str,
type => 'rain',
current => $rain,
units => 'mm/h',
};
push @res, {
device => $dev_str,
type => 'train',
current => $train,
units => 'mm',
};
device => $dev_str,
type => 'train',
current => $train,
units => 'mm',
};
battery($bytes, $dev_str, \@res, 10);
return @res;
}
sub raw {
$_[0]->{raw} or $_[0]->{raw} = pack 'H*', $_[0]->{hex};
}
# -----------------------------
sub
TRX_WEATHER_Parse($$)
{
@ -683,15 +629,14 @@ TRX_WEATHER_Parse($$)
my $type = $rfxcom_data_array[0];
my $sensor_id = unpack('H*', chr $type);
#Log 1, "TRX_WEATHER: sensor_id=$sensor_id";
my $key = type_length_key($type, $num_bytes);
my $key = ($type << 8) + $num_bytes;
my $rec = $types{$key};
my $rec = $types{$key} || $types{$key&0xfffff};
unless ($rec) {
#Log 3, "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id num_bytes=$num_bytes message='$hexline'.";
Log 4, "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id message='$hexline'";
Log 1, "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id message='$hexline'";
Log 1, "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id message='$hexline'";
return "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id \n";
}
@ -867,11 +812,6 @@ Log 1, "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id message='$hexline'";
$def->{CHANGED}[$n++] = $val;
}
#
#$def->{READINGS}{state}{TIME} = $tm;
#$def->{READINGS}{state}{VAL} = $val;
#$def->{CHANGED}[$n++] = "state: ".$val;
DoTrigger($name, undef);
return $val;