############################################################################### # # Developed with Kate # # (c) 2015-2017 Copyright: Marko Oldenburg (leongaultier at gmail dot com) # All rights reserved # # This script 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 # any later version. # # The GNU General Public License can be found at # http://www.gnu.org/copyleft/gpl.html. # A copy is found in the textfile GPL.txt and important notices to the license # from the author is found in LICENSE.txt distributed with these scripts. # # 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. See the # GNU General Public License for more details. # # # $Id$ # ############################################################################### ## ## ## Das JSON Modul immer in einem eval aufrufen # $data = eval{decode_json($data)}; # # if($@){ # Log3($SELF, 2, "$TYPE ($SELF) - error while request: $@"); # # readingsSingleUpdate($hash, "state", "error", 1); # # return; # } # # ###### Möglicher Aufbau eines JSON Strings für die AMADCommBridge # # {"amad": {"AMADDEVICE": "nexus7-Wohnzimmer","FHEMCMD": "setreading"},"payload": {"reading0": "value0","reading1": "value1","readingX": "valueX"}} # # ## ## package main; my $missingModul = ""; use strict; use warnings; use HttpUtils; use TcpServerUtils; eval "use JSON;1" or $missingModul .= "JSON "; my $modulversion = "3alpha9"; my $flowsetversion = "2.6.12"; # Declare functions sub AMADCommBridge_Attr(@); sub AMADCommBridge_Open($); sub AMADCommBridge_Read($); sub AMADCommBridge_Define($$); sub AMADCommBridge_Header2Hash($); sub AMADCommBridge_HTTP_POST($$); sub AMADCommBridge_HTTP_POSTerrorHandling($$$); sub AMADCommBridge_Initialize($); sub AMADCommBridge_Set($@); sub AMADCommBridge_statusRequest($); sub AMADCommBridge_statusRequestErrorHandling($$$); sub AMADCommBridge_Undef($$); sub AMADCommBridge_ResponseProcessing($$); sub AMADCommBridge_Close($); sub AMADCommBridge_Initialize($) { my ($hash) = @_; # Provider $hash->{ReadFn} = "AMADCommBridge_Read"; $hash->{WriteFn} = "AMADCommBridge_Write"; $hash->{Clients} = ":AMADDevice:"; $hash->{MatchList} = { "1:AMADDevice" => '.*' }; # Consumer $hash->{SetFn} = "AMADCommBridge_Set"; $hash->{DefFn} = "AMADCommBridge_Define"; $hash->{UndefFn} = "AMADCommBridge_Undef"; $hash->{AttrFn} = "AMADCommBridge_Attr"; $hash->{AttrList} = "expertMode:1 ". "port ". "disable:1 ". $readingFnAttributes; foreach my $d(sort keys %{$modules{AMADCommBridge}{defptr}}) { my $hash = $modules{AMADCommBridge}{defptr}{$d}; $hash->{VERSIONMODUL} = $modulversion; $hash->{VERSIONFLOWSET} = $flowsetversion; } } sub AMADCommBridge_Define($$) { my ( $hash, $def ) = @_; my @a = split( "[ \t][ \t]*", $def ); return "too few parameters: define AMADCommBridge'" if( @a != 2); return "Cannot define a HEOS device. Perl modul $missingModul is missing." if ( $missingModul ); my $name = $a[0]; my $host = $a[2]; my $port; $port = $a[3] if($a[3]); $port = 8090 if( not defined($port) and (!$port) ); $hash->{BRIDGE} = 1; $hash->{PORT} = $port; $hash->{VERSIONMODUL} = $modulversion; $hash->{VERSIONFLOWSET} = $flowsetversion; ### Muss in das logische Modul eingepflegt werden # $hash->{helper}{infoErrorCounter} = 0 if( $hash->{HOST} ); # $hash->{helper}{setCmdErrorCounter} = 0 if( $hash->{HOST} ); # $hash->{helper}{deviceStateErrorCounter} = 0 if( $hash->{HOST} ); $attr{$name}{room} = "AMAD" if( !defined( $attr{$name}{room} ) ); Log3 $name, 3, "AMADCommBridge ($name) - defined AMADCommBridge with Socketport $port"; AMADCommBridge_Open( $hash ); $modules{AMADCommBridge}{defptr}{BRIDGE} = $hash; return undef; } sub AMADCommBridge_Undef($$) { my ( $hash, $arg ) = @_; delete $modules{AMADCommBridge}{defptr}{BRIDGE} if( defined($modules{AMADCommBridge}{defptr}{BRIDGE}) and $hash->{BRIDGE} ); TcpServer_Close( $hash ); return undef; } sub AMADCommBridge_Attr(@) { my ( $cmd, $name, $attrName, $attrVal ) = @_; my $hash = $defs{$name}; my $orig = $attrVal; if( $attrName eq "disable" ) { if( $cmd eq "set" ) { if( $attrVal eq "0" ) { readingsSingleUpdate ( $hash, "state", "enabled", 1 ); AMADCommBridge_Open($hash); Log3 $name, 3, "AMADCommBridge ($name) - enabled"; } else { AMADCommBridge_Close($hash); readingsSingleUpdate ( $hash, "state", "disabled", 1 ) if( not defined($hash->{FD}) ); Log3 $name, 3, "AMADCommBridge ($name) - disabled"; } } else { readingsSingleUpdate ( $hash, "state", "enabled", 1 ); AMADCommBridge_Open($hash); Log3 $name, 3, "AMADCommBridge ($name) - enabled"; } } elsif( $attrName eq "port" ) { if( $cmd eq "set" ) { $hash->{PORT} = $attrVal; delete $modules{AMADCommBridge}{defptr}{BRIDGE}; TcpServer_Close( $hash ); Log3 $name, 3, "AMADCommBridge ($name) - CommBridge Port changed. CommBridge are closed and new open!"; AMADCommBridge_CommBridge_Open( $hash ); } else { $hash->{PORT} = 8090; delete $modules{AMADCommBridge}{defptr}{BRIDGE}; TcpServer_Close( $hash ); Log3 $name, 3, "AMADCommBridge ($name) - CommBridge Port changed. CommBridge are closed and new open!"; AMADCommBridge_Open( $hash ); } } return undef; } sub AMADCommBridge_statusRequest($) { my ($hash) = @_; my $name = $hash->{NAME}; my $fhemip = $hash->{HOST}; my $port = $hash->{PORT}; my $host; my $activetask = AttrVal( $name, "checkActiveTask", "none" ); my $userFlowState = AttrVal( $name, "setUserFlowState", "none" ); my $apssid = "none"; $apssid = $hash->{APSSID} if( defined($hash->{APSSID}) ); $apssid = $attr{$name}{setAPSSID} if( defined($attr{$name}{setAPSSID}) ); my $url = "http://" . $host . ":" . $port . "/fhem-amad/deviceInfo/"; # Pfad muß so im Automagic als http request Trigger drin stehen HttpUtils_NonblockingGet( { url => $url, timeout => 5, hash => $hash, method => "GET", header => "Connection: close\r\nfhemip: $fhemip\r\nfhemdevice: $name\r\nactivetask: $activetask\r\napssid: $apssid\r\nbport: $port\r\nuserflowstate: $userFlowState", doTrigger => 1, callback => \&AMADCommBridge_statusRequestErrorHandling, } ); Log3 $name, 5, "AMADCommBridge ($name) - Send statusRequest with URL: \"$url\" and Header: \"fhemIP: $fhemip\r\nfhemDevice: $name\r\nactiveTask: $activetask\r\napSSID: $apssid\""; } sub AMADCommBridge_statusRequestErrorHandling($$$) { my ( $param, $err, $data ) = @_; my $hash = $param->{hash}; my $doTrigger = $param->{doTrigger}; my $name = $hash->{NAME}; my $host = $hash->{HOST}; ### Begin Error Handling if( $hash->{helper}{infoErrorCounter} > 0 ) { readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( ReadingsVal( $name, "flow_Informations", "active" ) eq "inactive" && ReadingsVal( $name, "flow_SetCommands", "active" ) eq "inactive" ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); readingsBulkUpdate ( $hash, "state", "AMAD Flows inactive, device set offline"); } elsif( $hash->{helper}{infoErrorCounter} > 7 && $hash->{helper}{setCmdErrorCounter} > 4 ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED"; $attr{$name}{disable} = 1; readingsBulkUpdate ( $hash, "state", "Unknown Error, device disabled"); $hash->{helper}{infoErrorCounter} = 0; $hash->{helper}{setCmdErrorCounter} = 0; return; } elsif( ReadingsVal( $name, "flow_Informations", "active" ) eq "inactive" ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: Informations Flow on your Device is inactive, will try to reactivate"; } elsif( $hash->{helper}{infoErrorCounter} > 7 ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); readingsBulkUpdate ( $hash, "state", "To many Errors, device set offline"); $hash->{helper}{infoErrorCounter} = 0; } elsif($hash->{helper}{infoErrorCounter} > 2 && ReadingsVal( $name, "flow_Informations", "active" ) eq "active" ){ Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: Please check the AutomagicAPP on your Device"; } readingsEndUpdate( $hash, 1 ); } if( defined( $err ) ) { if( $err ne "" ) { readingsBeginUpdate( $hash ); readingsBulkUpdate ( $hash, "state", "$err") if( ReadingsVal( $name, "state", 1 ) ne "initialized" ); $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( $err =~ /timed out/ ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: connect to your device is timed out. check network"; } elsif( ( $err =~ /Keine Route zum Zielrechner/ ) && $hash->{helper}{infoErrorCounter} > 1 ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: no route to target. bad network configuration or network is down"; } else { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: $err"; } readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: AMADCommBridge_statusRequestErrorHandling: error while requesting AutomagicInfo: $err"; return; } } if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) { readingsBeginUpdate( $hash ); readingsBulkUpdate ( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 1 ) ne "initialized" ); $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( $param->{code} ne 200 ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: ".$param->{code}; } readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: received http code ".$param->{code}." without any data after requesting AMAD AutomagicInfo"; return; } if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state" ,0) ne "initialized" ); $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( $param->{code} eq 404 && ReadingsVal( $name, "flow_Informations", "inactive" ) eq "inactive" ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: check the informations flow on your device"; } elsif( $param->{code} eq 404 && ReadingsVal( $name, "flow_Informations", "active" ) eq "active" ) { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: check the automagicApp on your device"; } else { Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: http error ".$param->{code}; } readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMADCommBridge ($name) - statusRequestERROR: received http code ".$param->{code}." receive Error after requesting AMAD AutomagicInfo"; return; } ### End Error Handling $hash->{helper}{infoErrorCounter} = 0; } sub AMADCommBridge_Set($@) { my ($hash, $name, $cmd, @args) = @_; my ($arg, @params) = @args; if( $cmd eq 'open' ) { AMADCommBridge_Open($hash); } elsif( $cmd eq 'close' ) { AMADCommBridge_Close($hash); } elsif( $cmd eq 'fhemServerIP' ) { readingsSingleUpdate($hash,$cmd,$arg,1); } else { my $list = "open:noArg close:noArg fhemServerIP"; return "Unknown argument $cmd, choose one of $list"; } } sub AMADCommBridge_HTTP_POST($$) { my ( $hash, $url ) = @_; my $name = $hash->{NAME}; my $state = ReadingsVal( $name, "state", 0 ); readingsSingleUpdate( $hash, "state", "Send HTTP POST", 1 ); HttpUtils_NonblockingGet( { url => $url, timeout => 15, hash => $hash, method => "POST", header => "Connection: close", doTrigger => 1, callback => \&AMADCommBridge_HTTP_POSTerrorHandling, } ); Log3 $name, 4, "AMADCommBridge ($name) - Send HTTP POST with URL $url"; readingsSingleUpdate( $hash, "state", $state, 1 ); return undef; } sub AMADCommBridge_HTTP_POSTerrorHandling($$$) { my ( $param, $err, $data ) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; ### Begin Error Handling if( $hash->{helper}{setCmdErrorCounter} > 2 ) { readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "lastSetCommandState", "statusRequest_error" ); if( ReadingsVal( $name, "flow_Informations", "active" ) eq "inactive" && ReadingsVal( $name, "flow_SetCommands", "active" ) eq "inactive" ) { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); readingsBulkUpdate( $hash, "state", "AMAD Flows inactive, device set offline" ); } elsif( $hash->{helper}{infoErrorCounter} > 7 && $hash->{helper}{setCmdErrorCounter} > 4 ) { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED"; $attr{$name}{disable} = 1; readingsBulkUpdate( $hash, "state", "Unknown Error, device disabled" ); $hash->{helper}{infoErrorCounter} = 0; $hash->{helper}{setCmdErrorCounter} = 0; return; } elsif( ReadingsVal( $name, "flow_SetCommands", "active" ) eq "inactive" ) { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: Flow SetCommands on your Device is inactive, will try to reactivate"; } elsif( $hash->{helper}{setCmdErrorCounter} > 9 ) { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); readingsBulkUpdate( $hash, "state", "To many Errors, device set offline" ); $hash->{helper}{setCmdErrorCounter} = 0; } elsif( $hash->{helper}{setCmdErrorCounter} > 4 && ReadingsVal( $name, "flow_SetCommands", "active" ) eq "active" ){ Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: Please check the AutomagicAPP on your Device"; } readingsEndUpdate( $hash, 1 ); } if( defined( $err ) ) { if( $err ne "" ) { readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "state", $err ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" ); $hash->{helper}{setCmdErrorCounter} = ($hash->{helper}{setCmdErrorCounter} + 1); readingsBulkUpdate( $hash, "lastSetCommandState", "setCmd_error" ); if( $err =~ /timed out/ ) { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: connect to your device is timed out. check network"; } elsif( $err =~ /Keine Route zum Zielrechner/ ) { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: no route to target. bad network configuration or network is down"; } else { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: $err"; } readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: error while POST Command: $err"; return; } } if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) { readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $hash, "state", 0 ) ne "initialized" ); $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); readingsBulkUpdate($hash, "lastSetCommandState", "setCmd_error" ); readingsEndUpdate( $hash, 1 ); Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: received http code ".$param->{code}; return; } if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" ); $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); readingsBulkUpdate( $hash, "lastSetCommandState", "setCmd_error" ); if( $param->{code} eq 404 ) { readingsBulkUpdate( $hash, "lastSetCommandError", "" ); Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: setCommands flow is inactive on your device!"; } else { Log3 $name, 5, "AMADCommBridge ($name) - setCommandERROR: http error ".$param->{code}; } return; } ### End Error Handling readingsSingleUpdate( $hash, "lastSetCommandState", "setCmd_done", 1 ); $hash->{helper}{setCmdErrorCounter} = 0; return undef; } sub AMADCommBridge_Open($) { my $hash = shift; my $name = $hash->{NAME}; my $port = $hash->{PORT}; # Oeffnen des TCP Sockets my $ret = TcpServer_Open( $hash, $port, "global" ); if( $ret && !$init_done ) { Log3 $name, 3, "AMADCommBridge ($name) - $ret. Exiting."; exit(1); } readingsSingleUpdate ( $hash, "state", "opened", 1 ) if( defined($hash->{FD}) ); Log3 $name, 3, "AMADCommBridge ($name) - Socket opened."; return; } sub AMADCommBridge_Close($) { my $hash = shift; my $name = $hash->{NAME}; delete $modules{AMADCommBridge}{defptr}{BRIDGE}; TcpServer_Close( $hash ); if( not defined($hash->{FD}) ) { readingsSingleUpdate ( $hash, "state", "closed", 1 ); Log3 $name, 3, "AMADCommBridge ($name) - Socket closed."; } else { Log3 $name, 3, "AMADCommBridge ($name) - can't close Socket."; } return; } sub AMADCommBridge_Read($) { my $hash = shift; if( $hash->{SERVERSOCKET} ) { # Accept and create a child TcpServer_Accept( $hash, "AMADCommBridge" ); return; } # Read 1024 byte of data my $buf; my $ret = sysread($hash->{CD}, $buf, 1024); # When there is an error in connection return if( !defined($ret ) || $ret <= 0 ) { CommandDelete( undef, $hash->{NAME} ); return; } AMADCommBridge_ResponseProcessing($hash,$buf); } sub AMADCommBridge_ResponseProcessing($$) { my ($hash,$buf) = @_; my $name = $hash->{NAME}; my $bhash = $modules{AMADCommBridge}{defptr}{BRIDGE}; my $bname = $bhash->{NAME}; my @data = split( '\R\R', $buf ); #### Verarbeitung der Daten welche über die AMADCommBridge kommen #### Log3 $bname, 5, "AMADCommBridge ($name) - Receive RAW Message in Debugging Mode: $buf"; my $response; my $c; my $json = $data[1]; my $decode_json; $decode_json = eval{decode_json($json)}; if($@){ Log3 $bname, 3, "AMADCommBridge ($name) - error while request: $@"; readingsSingleUpdate($bhash, "state", "error", 1); return; } my $amadDevice = $decode_json->{amad}{AMADDEVICE}; my $fhemcmd = $decode_json->{amad}{FHEMCMD}; if ( $data[0] =~ /currentFlowsetUpdate.xml/ ) { my $fhempath = $attr{global}{modpath}; $response = qx(cat $fhempath/FHEM/lib/74_AMADautomagicFlowset_$flowsetversion.xml); $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; return; } elsif ( $data[0] =~ /installFlow_([^.]*.xml)/ ) { if( defined($1) ){ $response = qx(cat /tmp/$1); $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; return; } } elsif( !defined($amadDevice) ) { readingsSingleUpdate( $bhash, "transmitterERROR", $hash->{NAME}." has no device name sends", 1 ) if( AttrVal( $bname, "expertMode", 0 ) eq "1" ); Log3 $bname, 4, "AMADCommBridge ($name) - ERROR - no device name given. please check your global variable in automagic"; $response = "header lines: \r\n AMADCommBridge receive no device name. please check your global variable in automagic\r\n FHEM to do nothing\r\n"; $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; return; } if( defined($fhemcmd) and ($fhemcmd) ) { if ( $fhemcmd =~ /setreading\b/ ) { my $tv = $data[1]; return Log3 $bname, 3, "AMADCommBridge ($name) - AMADCommBridge: processing receive no reading values from Device: $amadDevice" unless( defined($tv) and ($tv) ); Log3 $bname, 4, "AMADCommBridge ($name) - AMADCommBridge: processing receive reading values - Device: $amadDevice Data: $tv"; Dispatch($bhash,$json,undef); Log3 $name, 4, "AMADCommBridge ($name) - call Dispatcher"; readingsSingleUpdate($bhash,'fhemServerIP',$decode_json->{payload}{'DEVICE-IP'},1) if( defined($decode_json->{payload}{'DEVICE-IP'})); $response = "header lines: \r\n AMADCommBridge receive Data complete\r\n FHEM was processes\r\n"; $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; return; } elsif ( $fhemcmd =~ /set\b/ ) { my $fhemCmd = $data[1]; fhem ("set $fhemCmd") if( ReadingsVal( $bname, "expertMode", 0 ) eq "1" ); readingsSingleUpdate( $bhash, "receiveFhemCommand", "set ".$fhemCmd, 0 ); Log3 $bname, 4, "AMADCommBridge ($name) - AMADCommBridge_CommBridge: set reading receive fhem command"; $response = "header lines: \r\n AMADCommBridge receive Data complete\r\n FHEM execute set command now\r\n"; $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; return; } elsif ( $fhemcmd =~ /voiceinputvalue\b/ ) { my $fhemCmd = lc $data[1]; readingsBeginUpdate( $bhash); readingsBulkUpdate( $bhash, "receiveVoiceCommand", $fhemCmd ); readingsBulkUpdate( $bhash, "receiveVoiceDevice", $amadDevice ); readingsEndUpdate( $bhash, 1 ); Log3 $bname, 4, "AMADCommBridge ($name) - AMADCommBridge_CommBridge: set reading receive voice command: $fhemCmd from Device $amadDevice"; $response = "header lines: \r\n AMADCommBridge receive Data complete\r\n FHEM was processes\r\n"; $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; return; } elsif ( $fhemcmd =~ /readingsval\b/ ) { my $fhemCmd = $data[1]; my @datavalue = split( ' ', $fhemCmd ); $response = ReadingsVal( $datavalue[0], $datavalue[1], $datavalue[2] ); $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; Log3 $bname, 4, "AMADCommBridge ($name) - AMADCommBridge_CommBridge: response ReadingsVal Value to Automagic Device"; return; } # elsif ( $fhemcmd =~ /fhemfunc\b/ ) { # my $fhemCmd = $data[1]; # # Log3 $bname, 4, "AMADCommBridge ($name) - AMADCommBridge_CommBridge: receive fhem-function command"; # # if( $fhemCmd =~ /^{.*}$/ ) { # # $response = $fhemCmd if( ReadingsVal( $name, "expertMode", 0 ) eq "1" ); # # } else { # # $response = "header lines: \r\n AMADCommBridge receive no typical FHEM function\r\n FHEM to do nothing\r\n"; # } # # $c = $hash->{CD}; # print $c "HTTP/1.1 200 OK\r\n", # "Content-Type: text/plain\r\n", # "Connection: close\r\n", # "Content-Length: ".length($response)."\r\n\r\n", # $response; # # return; # } } $response = "header lines: \r\n AMADCommBridge receive incomplete or corrupt Data\r\n FHEM to do nothing\r\n"; $c = $hash->{CD}; print $c "HTTP/1.1 200 OK\r\n", "Content-Type: text/plain\r\n", "Connection: close\r\n", "Content-Length: ".length($response)."\r\n\r\n", $response; } ################## ### my little helper ################## ##### bleibt zu Anschauungszwecken erhalten #sub AMADCommBridge_Header2Hash($) { # # my $string = shift; # my %hash = (); # # foreach my $line (split("\r\n", $string)) { # my ($key,$value) = split( ": ", $line ); # next if( !$value ); # # $value =~ s/^ //; # $hash{$key} = $value; # } # # return \%hash; #} 1; =pod =item device =item summary Integrates Android devices into FHEM and displays several settings. =item summary_DE Integriert Android-Geräte in FHEM und zeigt verschiedene Einstellungen an. =begin html

AMAD

=end html =begin html_DE

AMAD

=end html_DE =cut