From 88c6bda72c8654c8d20c4b4995a73f170459452a Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 25 May 2016 06:56:24 +0200 Subject: [PATCH] =?UTF-8?q?KeepAlive=20Funktion=20f=C3=BCr=20Android=206,?= =?UTF-8?q?=20verbessertes=20Errorhandling,=20Codebereinigung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 74_AMAD.pm | 41 +- ...4.xml => 74_AMADautomagicFlowset_2.1.5.xml | 646 +++++++++--------- README.md | 6 +- 3 files changed, 351 insertions(+), 342 deletions(-) rename 74_AMADautomagicFlowset_2.1.4.xml => 74_AMADautomagicFlowset_2.1.5.xml (88%) diff --git a/74_AMAD.pm b/74_AMAD.pm index 92a17ed..41e52fa 100644 --- a/74_AMAD.pm +++ b/74_AMAD.pm @@ -37,8 +37,8 @@ use TcpServerUtils; use Encode qw(encode); -my $modulversion = "2.1.3"; -my $flowsetversion = "2.1.4"; +my $modulversion = "2.1.5"; +my $flowsetversion = "2.1.5"; @@ -97,6 +97,7 @@ sub AMAD_Define($$) { $hash->{VERSIONFLOWSET} = $flowsetversion; $hash->{helper}{infoErrorCounter} = 0 if( $hash->{HOST} ); $hash->{helper}{setCmdErrorCounter} = 0 if( $hash->{HOST} ); + $hash->{helper}{deviceStateErrorCounter} = 0 if( $hash->{HOST} ); @@ -138,7 +139,7 @@ sub AMAD_Undef($$) { my ( $hash, $arg ) = @_; if( $hash->{BRIDGE} ) { - delete $modules{AMAD}{defptr}{BRIDGE}; + delete $modules{AMAD}{defptr}{BRIDGE} if(defined($modules{AMAD}{defptr}{BRIDGE})); TcpServer_Close( $hash ); } else { @@ -479,6 +480,8 @@ sub AMAD_ResponseProcessing($$) { readingsBulkUpdate( $hash, "state", "active" ) if( ReadingsVal( $name, "state", 0 ) eq "initialized" ); readingsEndUpdate( $hash, 1 ); + $hash->{helper}{deviceStateErrorCounter} = 0 if( $hash->{helper}{deviceStateErrorCounter} > 0 and ReadingsVal( $name, "deviceState", "offline") eq "online" ); + return undef; } @@ -1019,8 +1022,15 @@ sub AMAD_checkDeviceState($) { Log3 $name, 4, "AMAD ($name) - AMAD_checkDeviceState: run Check"; RemoveInternalTimer( $hash ); - readingsSingleUpdate( $hash, "deviceState", "offline", 1 ) if( ReadingsAge($name,"deviceState",180) > 180 ); - InternalTimer( gettimeofday()+180, "AMAD_checkDeviceState", $hash, 0 ); + + if( ReadingsAge( $name, "deviceState", 90 ) > 90 ) { + + AMAD_statusRequest( $hash ) if( $hash->{helper}{deviceStateErrorCounter} == 0 ); + readingsSingleUpdate( $hash, "deviceState", "offline", 1 ) if( ReadingsAge( $name, "deviceState", 180) > 180 and $hash->{helper}{deviceStateErrorCounter} > 0 ); + $hash->{helper}{deviceStateErrorCounter} = ( $hash->{helper}{deviceStateErrorCounter} + 1 ); + } + + InternalTimer( gettimeofday()+90, "AMAD_checkDeviceState", $hash, 0 ); Log3 $name, 4, "AMAD ($name) - AMAD_checkDeviceState: set new Timer"; } @@ -1081,7 +1091,7 @@ sub AMAD_CommBridge_Read($) { my @data = split( '\R\R', $buf ); my $header = AMAD_Header2Hash( $data[0] ); - my $device = $header->{FHEMDEVICE}; + my $device = $header->{FHEMDEVICE} if(defined($header->{FHEMDEVICE})); my $dhash = $defs{$device}; my $response; my $c; @@ -1289,7 +1299,7 @@ sub AMAD_decrypt($) { How to use AMAD?
Now you need to define a device in FHEM. @@ -1316,7 +1326,6 @@ sub AMAD_decrypt($) { Please us the following command for configuration of the FHEM server IP address in the AMADCommBridge: set AMADCommBridge fhemServerIP <FHEM-IP>.
Additionally the expertMode may be configured. By this setting a direct communication with FHEM will be established without the restriction of needing to make use of a notify to execute set commands.
- NOW please activate the flows in Automagic!!!

You are finished now! After 15 seconds latest the readings of your AMAD Android device should be updated. Consequently each 15 seconds a status request will be sent. If the state of your AMAD Android device does not change to "active" over a longer period of time one should take a look into the log file for error messages.


@@ -1334,7 +1343,7 @@ sub AMAD_decrypt($) {
  • currentMusicArtist - currently playing artist of mediaplayer
  • currentMusicTrack - currently playing song title of mediaplayer
  • daydream - on/off, daydream currently active
  • -
  • deviceState - state of Android devices. !!!It does not show the real state!!! deviceState must be set manually by the command "set DEVICE deviceState" e.g. by your PRESENCE function.
    In case deviceState is set to "offline" no set commands can be issued.
  • +
  • deviceState - state of Android devices. unknown, online, offline.
  • dockingState - undocked/docked, Android device in docking station
  • flow_SetCommands - active/inactive, state of SetCommands flow
  • flow_informations - active/inactive, state of Informations flow
  • @@ -1369,17 +1378,18 @@ sub AMAD_decrypt($) { Set