From b159d5a436aa4ff4fe6e3cb4f1bf3c2cb833fef7 Mon Sep 17 00:00:00 2001 From: delmar <> Date: Sun, 18 Apr 2021 16:05:49 +0000 Subject: [PATCH] 49_IPCAM: attrs unknownFormatRetryCount, unknownFormatRetryDelay, handleAnyXmlAsSvg git-svn-id: https://svn.fhem.de/fhem/trunk@24272 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/49_IPCAM.pm | 60 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 9ee9a4067..62795f073 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - feature: 49_IPCAM: attrs unknownFormatRetryCount, unknownFormatRetryDelay + and handleAnyXmlAsSvg - change: 74_GardenaDevice: add new API for mower - bugfix: 70_BOTVAC: transient map cache - bugfix: 73_DoorBird: Event Video Routine diff --git a/fhem/FHEM/49_IPCAM.pm b/fhem/FHEM/49_IPCAM.pm index d15d1321b..45ddb9824 100644 --- a/fhem/FHEM/49_IPCAM.pm +++ b/fhem/FHEM/49_IPCAM.pm @@ -47,7 +47,7 @@ IPCAM_Initialize($$) "cmd01data cmd02data cmd03data cmd04data cmd05data cmd06data cmd07data ". "cmd08data cmd09data cmd10data cmd11data cmd12data cmd13data cmd14data cmd15data ". "model do_not_notify:1,0 showtime:1,0 scheme:http,https ". - "disable:0,1 ". + "disable:0,1 unknownFormatRetryDelay handleAnyXmlAsSvg:0,1 unknownFormatRetryCount ". $readingFnAttributes; } @@ -515,13 +515,36 @@ sub RequestSnapshot_Callback { } elsif($snapshot ne "") { # Log3 $name, 3, "IPCAM ($name) - snapshot response: $data"; - my $imageFormat = guessFileFormat(\$snapshot); + my $imageFormat = guessFileFormat($name, \$snapshot); my @imageTypes = qw(JPEG PNG GIF TIFF BMP ICO PPM XPM XBM SVG); if( ! grep { $_ eq "$imageFormat"} @imageTypes) { Log3 $name, 1, "IPCAM ($name) - Wrong or not supported image format: $imageFormat"; RemoveInternalTimer($hash); + + my $retryCount = int(AttrVal($name, 'unknownFormatRetryCount', 0)); + if ($retryCount > 0) { + my $nrRetries = $hash->{RETRIES_LEFT}; + if (! defined ($nrRetries)) { + $nrRetries = $retryCount; + } + + if ($nrRetries > 0) { + my $retryInterval = AttrVal($name, 'unknownFormatRetryDelay', 2); + + Log3 $name, 1, "IPCAM ($name) - Retrying for $nrRetries more time in $retryInterval seconds"; + InternalTimer(gettimeofday()+$retryInterval, "main::HttpUtils_NonblockingGet", $param); + + $hash->{RETRIES_LEFT} = $nrRetries -1; + } else { + $hash->{RETRIES_LEFT} = undef; + + Log3 $name, 1, "IPCAM ($name) - No more retries"; + } + + } + return undef; } @@ -623,8 +646,8 @@ getScheme($) { ##################################### sub -guessFileFormat($) { - my ($src) = shift; +guessFileFormat($$) { + my ($name,$src) = @_; my $header; my $srcHeader; @@ -645,7 +668,12 @@ guessFileFormat($) { return "PPM" if /^P[1-6]/; return "XPM" if /(^\/\* XPM \*\/)|(static\s+char\s+\*\w+\[\]\s*=\s*{\s*"\d+)/; return "XBM" if /^(?:\/\*.*\*\/\n)?#define\s/; - return "SVG" if /^(<\?xml|[\012\015\t ]*)?\r?\n?disable
  • do_not_notify
  • readingFnAttributes
  • +
  • + handleAnyXmlAsSvg
    + Previous versions of this module, any XML file was (maybe incorrectly) identified as SVG file.
    + Now, only valid SVG files or SVG documents are identified as SVG, leading to a 'unknown format' response for any other XML file.
    + If you rely on the previous behavior for any reason, setting this to 1 will handle any XML as valid SVG, writing it as .svg file to the storage.
    + The default value is 0. +
  • +
  • + unknownFormatRetryCount
    + If this module is unable to guess the correct file format, your camera might have been under heavy load and unable to respond with a proper image file.
    + The file format will be 'unknown' in that case. Setting this to a positive integer allows you to define how often
    + this module should re-try to grab an image.
    + Default value is 0.
    + Example: attr ipcam3 unknownFormatRetryCount 3 +
  • +
  • + unknownFormatRetryDelay
    + This defines the interval in seconds between retries, if [code]unknownFormatRetryCount[/code] is set to a positive integer.
    + The following example sets a 5 seconds delay.
    + Default is 2 seconds.
    + Example: attr ipcam3 unknownFormatRetryDelay 5 +
  • path
    Defines the path and query component of the complete URI to get a snapshot of the