added new features to ipcam.pm

git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2010 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mfr69bs
2012-10-22 22:47:50 +00:00
parent ddde94081b
commit 54d07470f2
2 changed files with 52 additions and 18 deletions

View File

@@ -43,7 +43,7 @@ IPCAM_Initialize($$)
$hash->{DefFn} = "IPCAM_Define"; $hash->{DefFn} = "IPCAM_Define";
$hash->{UndefFn} = "IPCAM_Undef"; $hash->{UndefFn} = "IPCAM_Undef";
$hash->{GetFn} = "IPCAM_Get"; $hash->{GetFn} = "IPCAM_Get";
$hash->{AttrList} = "delay credentials path query snapshots storage ". $hash->{AttrList} = "delay credentials path query snapshots storage timestamp:0,1 ".
"do_not_notify:1,0 showtime:1,0 ". "do_not_notify:1,0 showtime:1,0 ".
"loglevel:0,1,2,3,4,5,6 disable:0,1"; "loglevel:0,1,2,3,4,5,6 disable:0,1";
} }
@@ -86,11 +86,12 @@ IPCAM_Undef($$) {
sub sub
IPCAM_Get($@) { IPCAM_Get($@) {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $modpath = $attr{global}{modpath};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $seqImages; my $seqImages;
my $seqDelay; my $seqDelay;
my $seqWait; my $seqWait;
my $storage = (defined($attr{$name}{storage}) ? $attr{$name}{storage} : ""); my $storage = (defined($attr{$name}{storage}) ? $attr{$name}{storage} : "$modpath/www/snapshots");
# check syntax # check syntax
return "argument is missing @a" return "argument is missing @a"
@@ -106,13 +107,24 @@ IPCAM_Get($@) {
return "Attribute 'query' is defined but empty." return "Attribute 'query' is defined but empty."
if(defined($attr{$name}{query}) && $attr{$name}{query} eq ""); if(defined($attr{$name}{query}) && $attr{$name}{query} eq "");
# define default storage
if(!defined($attr{$name}{storage}) || $attr{$name}{storage} eq "") {
$attr{$name}{storage} = $storage;
}
if(! -d $storage) {
my $ret = mkdir "$storage";
if($ret == 0) {
Log 1, "ipcam Error while creating: $storage: $!";
return "Error while creating storagepath $storage: $!";
}
}
# get argument
my $arg = $a[1]; my $arg = $a[1];
if($arg eq "image") { if($arg eq "image") {
return "Attribute 'storage' is missing. Please add this attribute first!"
if(!$storage);
$seqImages = int(defined($attr{$name}{snapshots}) ? $attr{$name}{snapshots} : 1); $seqImages = int(defined($attr{$name}{snapshots}) ? $attr{$name}{snapshots} : 1);
$seqDelay = int(defined($attr{$name}{delay}) ? $attr{$name}{delay} : 0); $seqDelay = int(defined($attr{$name}{delay}) ? $attr{$name}{delay} : 0);
$seqWait = 0; $seqWait = 0;
@@ -162,14 +174,18 @@ IPCAM_getSnapshot($) {
my $lastSnapshot; my $lastSnapshot;
my $snapshot; my $snapshot;
my $dateTime; my $dateTime;
my $seqImages = int(defined($attr{$name}{snapshots}) ? $attr{$name}{snapshots} : 1); my $modpath = $attr{global}{modpath};
my $seq = int(defined($hash->{SEQ}) ? $hash->{SEQ} : 0); my $seq = int(defined($hash->{SEQ}) ? $hash->{SEQ} : 0);
my $storage = (defined($attr{$name}{storage}) ? $attr{$name}{storage} : ""); my $seqImages = int(defined($attr{$name}{snapshots}) ? $attr{$name}{snapshots} : 1);
my $seqF;
my $seqL = length($seqImages);
my $storage = (defined($attr{$name}{storage}) ? $attr{$name}{storage} : "$modpath/www/snapshots");
my $timestamp;
if(!$storage) { #if(!$storage) {
RemoveInternalTimer($hash); # RemoveInternalTimer($hash);
return "Attribute 'storage' is missing. Please add this attribute first!"; # return "Attribute 'storage' is missing. Please add this attribute first!";
} #}
$camPath = $attr{$name}{path}; $camPath = $attr{$name}{path};
$camQuery = $attr{$name}{query} $camQuery = $attr{$name}{query}
@@ -196,6 +212,9 @@ IPCAM_getSnapshot($) {
} }
$dateTime = TimeNow(); $dateTime = TimeNow();
$timestamp = $dateTime;
$timestamp =~ s/ /_/g;
$timestamp =~ s/(:|-)//g;
$snapshot = GetFileFromURLQuiet($camURI); $snapshot = GetFileFromURLQuiet($camURI);
@@ -214,9 +233,15 @@ IPCAM_getSnapshot($) {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
if($seq < $seqImages) { if($seq < $seqImages) {
$seq++; $seq++;
$seqF = sprintf("%0${seqL}d",$seq);
$imageFormat = "JPG" if($imageFormat eq "JPEG"); $imageFormat = "JPG" if($imageFormat eq "JPEG");
$lastSnapshot = $name."_snapshot.".lc($imageFormat); $lastSnapshot = $name."_snapshot.".lc($imageFormat);
$imageFile = $name."_snapshot".$seq.".".lc($imageFormat); if(defined($attr{$name}{timestamp}) && $attr{$name}{timestamp} == 1) {
$imageFile = $name."_".$timestamp.".".lc($imageFormat);
} else {
$imageFile = $name."_snapshot_".$seqF.".".lc($imageFormat);
}
if(!open(FH, ">$storage/$lastSnapshot")) { if(!open(FH, ">$storage/$lastSnapshot")) {
Log 1, "IPCAM $name Can't write $storage/$lastSnapshot: $!"; Log 1, "IPCAM $name Can't write $storage/$lastSnapshot: $!";
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
@@ -237,8 +262,8 @@ IPCAM_getSnapshot($) {
Log 5, "IPCAM $name snapshot $storage/$imageFile written."; Log 5, "IPCAM $name snapshot $storage/$imageFile written.";
readingsUpdate($hash,"last",$lastSnapshot); readingsUpdate($hash,"last",$lastSnapshot);
$hash->{STATE} = "last: $dateTime"; $hash->{STATE} = "last: $dateTime";
$hash->{READINGS}{"snapshot$seq"}{TIME} = $dateTime; $hash->{READINGS}{"snapshot$seqF"}{TIME} = $dateTime;
$hash->{READINGS}{"snapshot$seq"}{VAL} = $imageFile; $hash->{READINGS}{"snapshot$seqF"}{VAL} = $imageFile;
} }
Log GetLogLevel($name,4), "IPCAM $name image: $imageFile"; Log GetLogLevel($name,4), "IPCAM $name image: $imageFile";

View File

@@ -8626,18 +8626,27 @@ This module supports Samsung TV devices with few commands. It's developed and te
Defines the total number of snapshots to be taken with the <code>get &lt;name&gt; image</code> command. Defines the total number of snapshots to be taken with the <code>get &lt;name&gt; image</code> command.
If this attribute is not defined, then the default value is 1.<br> If this attribute is not defined, then the default value is 1.<br>
The snapshots are stored in the given path of the attribute <code>storage</code> and are The snapshots are stored in the given path of the attribute <code>storage</code> and are
numbered sequentially (starts with 1) like <code>snapshot1</code>, <code>snapshot2</code>, etc. numbered sequentially (starts with 1) like <code>snapshot_01</code>, <code>snapshot_02</code>, etc.
Furthermore, an additional file <code>last</code> will be saved, which is identical with Furthermore, an additional file <code>last</code> will be saved, which is identical with
the last snapshot-image. The module checks the imagetype and stores all these files with the last snapshot-image. The module checks the imagetype and stores all these files with
the correct extension, e.g. <code>snapshot1.jpeg</code>.<br> the devicename and a correct extension, e.g. <code>&lt;devicename&gt;_snapshot_01.jpg</code>.<br>
All files are overwritten on every <code>get &lt;name&gt; image</code> command.<br> If you like a timestamp instead a sequentially number, take a look at the attribute <code>timestamp</code>.<br>
All files are overwritten on every <code>get &lt;name&gt; image</code> command (except: snapshots
with a timestamp. So, keep an eye on your diskspace if you use a timestamp extension!).<br>
Example: <code>attr ipcam3 snapshots 5</code> Example: <code>attr ipcam3 snapshots 5</code>
</li> </li>
<li> <li>
storage<br> storage<br>
Defines the location for the file storage of the snapshots.<br> Defines the location for the file storage of the snapshots. Default: <code>$modpath/www/snapshots</code><br>
Example: <code>attr ipcam3 storage /srv/share/surveillance/snapshots</code> Example: <code>attr ipcam3 storage /srv/share/surveillance/snapshots</code>
</li> </li>
<li>
timestamp<br>
If this attribute is unset or set to 0, snapshots are stored with a sequentially number
like <code>&lt;devicename&gt;_snapshot_01.jpg</code>, <code>&lt;devicename&gt;_snapshot_02.jpg</code>, etc.<br>
If you like filenames with a timestamp postfix, e.g. <code>&lt;devicename&gt;_20121023_002602.jpg</code>,
set this attribute to 1.
</li>
</ul> </ul>
<br> <br>