49_IPCAM: imageWithCallback wrapped in internalTimer with 0 delay

git-svn-id: https://svn.fhem.de/fhem/trunk@24213 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
delmar 2021-04-11 08:33:11 +00:00
parent 8dc1b609fd
commit f9d53925c8
2 changed files with 24 additions and 17 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # 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 - bugfix: 47_OBIS: Reintegrate buggy DZG meters support
- change: 49_IPCAM: introduced attribute httpTimeout - change: 49_IPCAM: introduced attribute httpTimeout
- change: 49_IPCAM: introduced incrementalTimeout - change: 49_IPCAM: introduced incrementalTimeout

View File

@ -1,4 +1,4 @@
# $Id$ #create $Id$
# vim: ts=2:et # vim: ts=2:et
################################################################ ################################################################
# #
@ -383,7 +383,7 @@ Get($@) {
} }
$hash->{READINGS}{snapshots}{VAL} = 0; $hash->{READINGS}{snapshots}{VAL} = 0;
for (my $i=0;$i<$seqImages;$i++) { for (my $i=0;$i<$seqImages;$i++) {
InternalTimer(gettimeofday()+$seqWait, "IPCAM::getSnapshot", $hash, 0); InternalTimer(gettimeofday()+$seqWait, "IPCAM::RequestSnapshot", $hash);
$seqWait = $seqWait + $seqDelay; $seqWait = $seqWait + $seqDelay;
} }
return undef; return undef;
@ -393,10 +393,7 @@ Get($@) {
my $callbackCommand = join(" ", @a); my $callbackCommand = join(" ", @a);
Log3 $name, 3, "IPCAM ($name) - imageWithCallback command: $callbackCommand"; Log3 $name, 3, "IPCAM ($name) - imageWithCallback command: $callbackCommand";
my $camUri = createSnapshotUrl($hash); RequestSnapshotWithCallback($hash,$callbackCommand);
Log3 $name, 3, "IPCAM ($name) - imageWithCallback camUri: $camUri";
RequestSnapshotWithCallback($hash, $camUri, $callbackCommand);
return undef; return undef;
@ -411,12 +408,6 @@ Get($@) {
} }
} }
sub getSnapshot($$) {
my ($hash) = @_;
my $snapshotUrl = createSnapshotUrl($hash);
RequestSnapshot($hash, $snapshotUrl);
}
##################################### #####################################
sub sub
createSnapshotUrl($) { createSnapshotUrl($) {
@ -473,17 +464,25 @@ createSnapshotUrl($) {
return $camURI; return $camURI;
} }
sub RequestSnapshot { sub RequestSnapshot {
my ($hash, $camUrl) = @_; my ($hash) = @_;
return RequestSnapshotWithCallback($hash, $camUrl, undef); return ExecuteSnapshotRequest($hash, undef);
} }
sub RequestSnapshotWithCallback { sub RequestSnapshotWithCallback {
my ($hash, $camUrl, $callbackCommand) = @_; my ($hash, $callbackCommand) = @_;
return ExecuteSnapshotRequest($hash, $callbackCommand);
}
sub ExecuteSnapshotRequest {
my ($hash, $callbackCommand) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $camUrl = createSnapshotUrl($hash);
Log3 $name, 3, "IPCAM ($name) - ExecuteSnapshotRequest camUrl: $camUrl";
my $apiParam = { my $apiParam = {
url => $camUrl, url => $camUrl,
method => "GET", method => "GET",
@ -493,7 +492,14 @@ sub RequestSnapshotWithCallback {
timeout => AttrVal($name, 'httpTimeout', 4), timeout => AttrVal($name, 'httpTimeout', 4),
callbackCommand => $callbackCommand callbackCommand => $callbackCommand
}; };
# 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); HttpUtils_NonblockingGet($apiParam);
}
return undef; return undef;
} }