Hi
ich habe mal das Modul so angepasst das geladen wird.
# $Id: 73_km200test.pm 0001 2014-07-25 10:17:00Z sailor $
########################################################################################################################
#
# 73_km200test.pm
# Creates the possibility to access the Buderus central heating system via
# KM200 Communication module
#
# Copyright by Sailor, Stefan M.
# e-mail: Contat via http://forum.fhem.de
#
# This file is part of fhem.
#
# Fhem 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.
#
# Fhem 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 fhem. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################################################################
###START###### Initialize module ##############################################################################START####
package main;
use strict;
use warnings;
use Blocking;
use Time::HiRes qw(gettimeofday sleep);
use HttpUtils;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use base qw( Exporter );
use MIME::Base64;
#use Mcrypt;
#sub km200_Get($@);
sub km200_Define($$);
#sub km200_GetStatus($;$);
sub km200_Undefine($$);
#sub km200_GetIPS($);
my $Version = "V 1.0.0";
my $FW ="V 1.0.x";
my $SN ="123456";
my $Interval = "10";
sub
km200_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
my $name = $hash->{NAME};
$hash->{FirmWare} = $FW;
$hash->{Version} = $Version;
$hash->{SerialNr} = $SN;
$hash->{STATE}="define";
Log3 $name, 4, "km200 : Define H $hash";
Log3 $name, 4, "km200 : Define D $def";
Log3 $name, 4, "km200 : Define A @a";
$attr{$name}{INTERVAL}="25";
$attr{$name}{room}="KM200";
$attr{$name}{disable}="0";
$attr{$name}{verbose}="3";
my $address = $a[2];
$name = $a[0];
#
$hash->{helper}{ADDRESS} = $address;
$hash->{helper}{NAME} = $name;
$Interval = $attr{$name}{INTERVAL};
Log3 $name, 4, "km200 : Define Adr $address";
Log3 $name, 4, "km200 : Define Name $name";
Log3 $name, 4, "km200 : Define Interval: $Interval";
$hash->{helper}{INTERVAL}=$Interval;
# start the status update timer
# RemoveInternalTimer($hash);
# InternalTimer(gettimeofday()+5, "km200_GetStatus", $hash, 0);
km200test_Initialize($hash);
return undef;
}
#############################
sub
km200_Undefine($$)
{
my($hash, $name) = @_;
$name = $hash->{helper}{NAME};
Log3 $name, 4, "km200: Undefine $name";
# Stop the internal GetStatus-Loop and exit
RemoveInternalTimer($hash);
return undef;
}
sub
km200test_Initialize($)
{
my ($hash) = @_;
# require "$attr{global}{modpath}/FHEM/HttpUtils.pm";
# $hash->{GetFn} = "km200_Get";
# $hash->{SetFn} = "km200_Set";
$hash->{DefFn} = "km200_Define";
$hash->{UndefFn} = "km200_Undefine";
# $hash->{FirmWare} = 1;
# $hash->{Version} = 0.1;
# $hash->{SerialNr} = 123456;
$hash->{STATE}="Init";
my $name = $hash->{helper}{NAME};
Log3 $name, 4, "km200: Init $hash";
$hash->{AttrList} = "km200GateLoginName km200GatePassword km200PrivatePassword km200GateIP do_not_notify:1,0 loglevel:0,1,2,3,4,5,6 INTERVAL disable:0,1 ".$readingFnAttributes;
#$hash->{AttrList} = "do_not_notify:1,0 loglevel:0,1,2,3,4,5,6 INTERVAL disable:0,1 ".$readingFnAttributes;
# RemoveInternalTimer($hash);
# InternalTimer(gettimeofday()+5, "km200_GetStatus", $hash, 0);
# To be changed to fhem module attributes
# IP Adresse oder DNS-Hostname des KM200
my $km200_gateway_host = "192.168.178.200";
# Gerätepasswort. Achtung: Ohne Bindestriche und in ASCII!
my $km200_gateway_password = "tjZvrnJicB8DpJyZ";
# Eigenes Passwort wie in der App vergeben
my $km200_private_password = "Hm4711";
# To be changed to fhem module attributes
###START###### Create the secret SALT of the MD5-Hash for AES-encoding #####################################START####
my $Buderus_MD5Salt = pack(
'c*',
0x86, 0x78, 0x45, 0xe9, 0x7c, 0x4e, 0x29, 0xdc,
0xe5, 0x22, 0xb9, 0xa7, 0xd3, 0xa3, 0xe0, 0x7b,
0x15, 0x2b, 0xff, 0xad, 0xdd, 0xbe, 0xd7, 0xf5,
0xff, 0xd8, 0x42, 0xe9, 0x89, 0x5a, 0xd1, 0xe4
);
####END####### Create the secret SALT of the MD5-Hash for AES-encoding ######################################END#####
###START###### Create keys with MD5 ########################################################################START####
# Copy Salt
my $km200_crypt_md5_salt = $Buderus_MD5Salt;
# First half of the key: MD5 of (km200GatePassword . Salt)
my $key_1 = md5($km200_gateway_password . $km200_crypt_md5_salt);
# Second half of the key: - Initial: MD5 of ( Salt)
my $key_2_initial = md5($km200_crypt_md5_salt);
# Second half of the key: - private: MD5 of ( Salt . km200PrivatePassword)
my $key_2_private = md5($km200_crypt_md5_salt . $km200_private_password);
# Create keys
my $km200_crypt_key_initial = ($key_1 . $key_2_initial);
my $km200_crypt_key_private = ($key_1 . $key_2_private);
####END####### Create keys with MD5 #########################################################################END#####
# For testing prupose only - To be deleted
my $InitialKey = "km200_crypt_key_initial: " . $km200_crypt_key_initial;
my $PrivateKey = "km200_crypt_key_private: " . $km200_crypt_key_private;
Log 3, $InitialKey;
Log 3, $PrivateKey;
# For testing prupose only - To be deleted
readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, "InitialKey", $InitialKey );
readingsBulkUpdate( $hash, "PrivateKey", $PrivateKey );
readingsEndUpdate( $hash, 1 );
#readingsBulkUpdate( $hash, "CSV-Laenge", $valL );
}
####END####### Initialize module ###############################################################################END#####
###START####### More or less replicates the equivalent PHP function ###########################################START####
sub str_repeat
{
my $string = shift;
my $count = shift;
return( ${string}x${count} );
}
####END######## More or less replicates the equivalent PHP function ############################################END#####
###START###### Subroutine Encrypt Data ########################################################################START####
#function km200_Encrypt( $encryptData )
#{
# # add PKCS #7 padding
# my $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
# my $encrypt_padchar = $blocksize - ( strlen( $encryptData ) % $blocksize );
# $encryptData .= str_repeat( chr( $encrypt_padchar ), $encrypt_padchar );
#
# # encrypt
# return base64_encode(
# mcrypt_encrypt(
# MCRYPT_RIJNDAEL_128,
# km200_crypt_key_private,
# $encryptData,
# MCRYPT_MODE_ECB,
# ''
# )
# );
#}
####END####### Subroutine Encrypt Data #########################################################################END#####
1;