mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
49_IPCAM: allow zero for snapshots attribute, and some cleanup.
git-svn-id: https://svn.fhem.de/fhem/trunk@24444 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9d04edb0ef
commit
14029547f6
@ -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: allow zero for snapshots attribute, and some cleanup.
|
||||||
- change: 93_DbLog: some minor changes, e.g. PID Info in Log Output
|
- change: 93_DbLog: some minor changes, e.g. PID Info in Log Output
|
||||||
- change: doif.js: tolerate dots in element id, cleanup
|
- change: doif.js: tolerate dots in element id, cleanup
|
||||||
- feature: 89_FULLY: Implemented some new commands
|
- feature: 89_FULLY: Implemented some new commands
|
||||||
|
@ -381,10 +381,13 @@ Get($@) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InternalTimer(gettimeofday(), "IPCAM::RequestSnapshot", $hash);
|
||||||
|
|
||||||
$hash->{READINGS}{snapshots}{VAL} = 0;
|
$hash->{READINGS}{snapshots}{VAL} = 0;
|
||||||
for (my $i=0;$i<$seqImages;$i++) {
|
for (my $i=1;$i<$seqImages;$i++) {
|
||||||
InternalTimer(gettimeofday()+$seqWait, "IPCAM::RequestSnapshot", $hash);
|
|
||||||
$seqWait = $seqWait + $seqDelay;
|
$seqWait = $seqWait + $seqDelay;
|
||||||
|
InternalTimer(gettimeofday()+$seqWait, "IPCAM::RequestSnapshot", $hash);
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
@ -517,7 +520,7 @@ sub RequestSnapshot_Callback {
|
|||||||
|
|
||||||
my $imageFormat = guessFileFormat($name, \$snapshot);
|
my $imageFormat = guessFileFormat($name, \$snapshot);
|
||||||
|
|
||||||
my @imageTypes = qw(JPEG PNG GIF TIFF BMP ICO PPM XPM XBM SVG);
|
my @imageTypes = qw(jpg png gif tiff bmp ico ppm xpm xbm svg);
|
||||||
|
|
||||||
if( ! grep { $_ eq "$imageFormat"} @imageTypes) {
|
if( ! grep { $_ eq "$imageFormat"} @imageTypes) {
|
||||||
Log3 $name, 1, "IPCAM ($name) - Wrong or not supported image format: $imageFormat";
|
Log3 $name, 1, "IPCAM ($name) - Wrong or not supported image format: $imageFormat";
|
||||||
@ -549,9 +552,25 @@ sub RequestSnapshot_Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log3 $name, 3, "IPCAM ($name) - Snapshot Image Format: $imageFormat";
|
Log3 $name, 3, "IPCAM ($name) - Snapshot Image Format: $imageFormat";
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
|
my $lastSnapshot = $name."_snapshot.".$imageFormat;
|
||||||
|
my $modpath = $attr{global}{modpath};
|
||||||
|
my $storage = AttrVal($name,'storage',"$modpath/www/snapshots");
|
||||||
|
if(!open(FH, ">$storage/$lastSnapshot")) {
|
||||||
|
Log3 $name, 0, "IPCAM ($name) - Can't write $storage/$lastSnapshot: $!";
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
readingsEndUpdate($hash, defined($hash->{LOCAL} ? 0 : 1));
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
print FH $snapshot;
|
||||||
|
close(FH);
|
||||||
|
|
||||||
|
my $dateTime = TimeNow();
|
||||||
|
$hash->{STATE} = "last: $dateTime";
|
||||||
|
readingsBulkUpdate($hash, "last", $lastSnapshot, 1);
|
||||||
|
Log3 $name, 4, "IPCAM ($name) - snapshot $storage/$lastSnapshot written.";
|
||||||
|
|
||||||
my $seq = int(defined($hash->{SEQ}) ? $hash->{SEQ} : 0);
|
my $seq = int(defined($hash->{SEQ}) ? $hash->{SEQ} : 0);
|
||||||
my $seqImages = int(AttrVal($name,'snapshots',1));
|
my $seqImages = int(AttrVal($name,'snapshots',1));
|
||||||
|
|
||||||
@ -560,33 +579,19 @@ sub RequestSnapshot_Callback {
|
|||||||
|
|
||||||
my $seqL = length($seqImages);
|
my $seqL = length($seqImages);
|
||||||
my $seqF = sprintf("%0${seqL}d", $seq);
|
my $seqF = sprintf("%0${seqL}d", $seq);
|
||||||
$imageFormat = "JPG" if($imageFormat eq "JPEG");
|
|
||||||
|
|
||||||
my $lastSnapshot = $name."_snapshot.".lc($imageFormat);
|
|
||||||
my $dateTime = TimeNow();
|
|
||||||
my $timestamp = $dateTime;
|
my $timestamp = $dateTime;
|
||||||
$timestamp =~ s/ /_/g;
|
$timestamp =~ s/ /_/g;
|
||||||
$timestamp =~ s/(:|-)//g;
|
$timestamp =~ s/(:|-)//g;
|
||||||
|
|
||||||
my $imageFile;
|
my $imageFile;
|
||||||
if(defined($attr{$name}{timestamp}) && $attr{$name}{timestamp} == 1) {
|
my $useTimestamp = AttrVal($name, 'timestamp', 0);
|
||||||
$imageFile = $name."_".$timestamp.".".lc($imageFormat);
|
if($useTimestamp == 1) {
|
||||||
|
$imageFile = $name."_".$timestamp.".".$imageFormat;
|
||||||
} else {
|
} else {
|
||||||
$imageFile = $name."_snapshot_".$seqF.".".lc($imageFormat);
|
$imageFile = $name."_snapshot_".$seqF.".".$imageFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $modpath = $attr{global}{modpath};
|
|
||||||
my $storage = AttrVal($name,'storage',"$modpath/www/snapshots");
|
|
||||||
if(!open(FH, ">$storage/$lastSnapshot")) {
|
|
||||||
Log3 $name, 0, "IPCAM ($name) - Can't write $storage/$lastSnapshot: $!";
|
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
readingsEndUpdate($hash, defined($hash->{LOCAL} ? 0 : 1));
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
print FH $snapshot;
|
|
||||||
close(FH);
|
|
||||||
|
|
||||||
Log3 $name, 4, "IPCAM ($name) - snapshot $storage/$lastSnapshot written.";
|
|
||||||
if(!open(FH, ">$storage/$imageFile")) {
|
if(!open(FH, ">$storage/$imageFile")) {
|
||||||
Log3 $name, 0, "IPCAM ($name) - Can't write $storage/$imageFile: $!";
|
Log3 $name, 0, "IPCAM ($name) - Can't write $storage/$imageFile: $!";
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
@ -597,8 +602,7 @@ sub RequestSnapshot_Callback {
|
|||||||
close(FH);
|
close(FH);
|
||||||
|
|
||||||
Log3 $name, 4, "IPCAM ($name) - snapshot $storage/$imageFile written.";
|
Log3 $name, 4, "IPCAM ($name) - snapshot $storage/$imageFile written.";
|
||||||
readingsBulkUpdate($hash, "last", $lastSnapshot, 1);
|
|
||||||
$hash->{STATE} = "last: $dateTime";
|
|
||||||
readingsBulkUpdate($hash, "snapshot$seqF", $imageFile, 1);
|
readingsBulkUpdate($hash, "snapshot$seqF", $imageFile, 1);
|
||||||
|
|
||||||
Log3 $name, 4, "IPCAM ($name) - image: $imageFile";
|
Log3 $name, 4, "IPCAM ($name) - image: $imageFile";
|
||||||
@ -658,20 +662,20 @@ guessFileFormat($$) {
|
|||||||
return "error while reading source image: $!" if(!$reading);
|
return "error while reading source image: $!" if(!$reading);
|
||||||
|
|
||||||
local($_) = $srcHeader;
|
local($_) = $srcHeader;
|
||||||
return "JPEG" if /^\xFF\xD8/;
|
return "jpg" if /^\xFF\xD8/;
|
||||||
return "PNG" if /^\x89PNG\x0d\x0a\x1a\x0a/;
|
return "png" if /^\x89PNG\x0d\x0a\x1a\x0a/;
|
||||||
return "GIF" if /^GIF8[79]a/;
|
return "gif" if /^GIF8[79]a/;
|
||||||
return "TIFF" if /^MM\x00\x2a/;
|
return "tiff" if /^MM\x00\x2a/;
|
||||||
return "TIFF" if /^II\x2a\x00/;
|
return "tiff" if /^II\x2a\x00/;
|
||||||
return "BMP" if /^BM/;
|
return "bmp" if /^BM/;
|
||||||
return "ICO" if /^\000\000\001\000/;
|
return "ico" if /^\000\000\001\000/;
|
||||||
return "PPM" if /^P[1-6]/;
|
return "ppm" if /^P[1-6]/;
|
||||||
return "XPM" if /(^\/\* XPM \*\/)|(static\s+char\s+\*\w+\[\]\s*=\s*{\s*"\d+)/;
|
return "xpm" if /(^\/\* XPM \*\/)|(static\s+char\s+\*\w+\[\]\s*=\s*{\s*"\d+)/;
|
||||||
return "XBM" if /^(?:\/\*.*\*\/\n)?#define\s/;
|
return "xbm" if /^(?:\/\*.*\*\/\n)?#define\s/;
|
||||||
if (int(AttrVal($name, 'handleAnyXmlAsSvg', 0)) == 1) {
|
if (int(AttrVal($name, 'handleAnyXmlAsSvg', 0)) == 1) {
|
||||||
return "SVG" if /^(<\?xml|[\012\015\t ]*<svg\b)/;
|
return "svg" if /^(<\?xml|[\012\015\t ]*<svg\b)/;
|
||||||
} else {
|
} else {
|
||||||
return "SVG" if /^(<\?xml version="1.0" encoding="UTF-8"\?>)?\r?\n?<svg/;
|
return "svg" if /^(<\?xml version="1.0" encoding="UTF-8"\?>)?\r?\n?<svg/;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
Loading…
Reference in New Issue
Block a user