From f9d53925c87943a1cb25170cf00c13ef98a3ef47 Mon Sep 17 00:00:00 2001 From: delmar <> Date: Sun, 11 Apr 2021 08:33:11 +0000 Subject: [PATCH] 49_IPCAM: imageWithCallback wrapped in internalTimer with 0 delay git-svn-id: https://svn.fhem.de/fhem/trunk@24213 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/49_IPCAM.pm | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 8d2cc6da4..3193ac031 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: 49_IPCAM: imageWithCallback wrapped in internalTimer with 0 delay - bugfix: 47_OBIS: Reintegrate buggy DZG meters support - change: 49_IPCAM: introduced attribute httpTimeout - change: 49_IPCAM: introduced incrementalTimeout diff --git a/fhem/FHEM/49_IPCAM.pm b/fhem/FHEM/49_IPCAM.pm index 93da80299..d15d1321b 100644 --- a/fhem/FHEM/49_IPCAM.pm +++ b/fhem/FHEM/49_IPCAM.pm @@ -1,4 +1,4 @@ -# $Id$ +#create $Id$ # vim: ts=2:et ################################################################ # @@ -383,7 +383,7 @@ Get($@) { } $hash->{READINGS}{snapshots}{VAL} = 0; for (my $i=0;$i<$seqImages;$i++) { - InternalTimer(gettimeofday()+$seqWait, "IPCAM::getSnapshot", $hash, 0); + InternalTimer(gettimeofday()+$seqWait, "IPCAM::RequestSnapshot", $hash); $seqWait = $seqWait + $seqDelay; } return undef; @@ -393,10 +393,7 @@ Get($@) { my $callbackCommand = join(" ", @a); Log3 $name, 3, "IPCAM ($name) - imageWithCallback command: $callbackCommand"; - my $camUri = createSnapshotUrl($hash); - Log3 $name, 3, "IPCAM ($name) - imageWithCallback camUri: $camUri"; - - RequestSnapshotWithCallback($hash, $camUri, $callbackCommand); + RequestSnapshotWithCallback($hash,$callbackCommand); return undef; @@ -411,12 +408,6 @@ Get($@) { } } -sub getSnapshot($$) { - my ($hash) = @_; - my $snapshotUrl = createSnapshotUrl($hash); - RequestSnapshot($hash, $snapshotUrl); -} - ##################################### sub createSnapshotUrl($) { @@ -473,17 +464,25 @@ createSnapshotUrl($) { return $camURI; } - sub RequestSnapshot { - my ($hash, $camUrl) = @_; + my ($hash) = @_; - return RequestSnapshotWithCallback($hash, $camUrl, undef); + return ExecuteSnapshotRequest($hash, undef); } sub RequestSnapshotWithCallback { - my ($hash, $camUrl, $callbackCommand) = @_; + my ($hash, $callbackCommand) = @_; + + return ExecuteSnapshotRequest($hash, $callbackCommand); +} + +sub ExecuteSnapshotRequest { + my ($hash, $callbackCommand) = @_; my $name = $hash->{NAME}; + my $camUrl = createSnapshotUrl($hash); + Log3 $name, 3, "IPCAM ($name) - ExecuteSnapshotRequest camUrl: $camUrl"; + my $apiParam = { url => $camUrl, method => "GET", @@ -493,7 +492,14 @@ sub RequestSnapshotWithCallback { timeout => AttrVal($name, 'httpTimeout', 4), callbackCommand => $callbackCommand }; - HttpUtils_NonblockingGet($apiParam); + + # trying to fix timeouts by wrapping this in internalTimer + if (defined $callbackCommand) { + InternalTimer(gettimeofday(), "main::HttpUtils_NonblockingGet", $apiParam); + } else { + # without callback command, the internal timer has been set before already. + HttpUtils_NonblockingGet($apiParam); + } return undef; }