49_IPCAM: added 'get imageWithCallback'

git-svn-id: https://svn.fhem.de/fhem/trunk@23913 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
delmar 2021-03-08 21:59:55 +00:00
parent 2e6fa0bf8b
commit d0b0d18091
2 changed files with 62 additions and 11 deletions

View File

@ -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: added 'get imageWithCallback'
- change: 49_IPCAM: now unblocking and removed attribute 'loglevel'
- change: 76_SMAInverter: change the etoday management
- change: 48_MieleAtHome: add readings to show token-refresh-count

View File

@ -57,6 +57,7 @@ use GPUtils qw(:all);
my %gets = (
"image" => "",
"imageWithCallback" => "",
"last" => "",
"snapshots" => "",
);
@ -90,6 +91,7 @@ BEGIN {
SetExtensions
AttrTemplate_Set
urlEncode
AnalyzeCommand
))
};
@ -311,7 +313,7 @@ Get($@) {
# check syntax
return "argument is missing @a"
if(int(@a) != 2);
if(int(@a) < 2);
# check argument
return "Unknown argument $a[1], choose one of ".join(" ", sort keys %gets)
if(!defined($gets{$a[1]}));
@ -337,7 +339,8 @@ Get($@) {
}
# get argument
my $arg = $a[1];
shift @a;
my $arg = shift @a;
if($arg eq "image") {
@ -363,6 +366,23 @@ Get($@) {
}
return undef;
} elsif($arg eq "imageWithCallback") {
my $callbackCommand = join(" ", @a);
Log3 $name, 0, "IPCAM ($name) - imageWithCallback command: $callbackCommand";
my $error = AnalyzeCommand(undef, $callbackCommand);
if (defined $error) {
Log3 $name, 0, "IPCAM ($name) - imageWithCallback command invalid: $error";
return undef;
}
my $camUri = getSnapshot($hash, 1);
Log3 $name, 0, "IPCAM ($name) - imageWithCallback camUri: $camUri";
RequestSnapshotWithCallback($hash, $camUri, $callbackCommand);
return undef;
} elsif(defined($hash->{READINGS}{$arg})) {
if(defined($hash->{READINGS}{$arg}{VAL})) {
@ -377,8 +397,8 @@ Get($@) {
#####################################
sub
getSnapshot($) {
my ($hash) = @_;
getSnapshot($$) {
my ($hash, $skipRequest) = @_;
my $name = $hash->{NAME};
my $camAuth = $hash->{AUTHORITY};
my $camURI;
@ -428,28 +448,39 @@ getSnapshot($) {
# Log3 $name, 3, "IPCAM ($name) - found reading: $1";
# }
GetSnapshot($hash, $camURI);
if (defined $skipRequest) {
return $camURI;
} else {
RequestSnapshot($hash, $camURI);
}
# Log3 $name, 5, "IPCAM ($name) - getSnapshot snapshot: $snapshot";
return undef;
}
sub GetSnapshot {
sub RequestSnapshot {
my ($hash, $camUrl) = @_;
return RequestSnapshotWithCallback($hash, $camUrl, undef);
}
sub RequestSnapshotWithCallback {
my ($hash, $camUrl, $callbackCommand) = @_;
my $name = $hash->{NAME};
my $apiParam = {
url => $camUrl,
method => "GET",
callback => \&IPCAM::GetSnapshot_Callback,
hash => $hash
callback => \&IPCAM::RequestSnapshot_Callback,
hash => $hash,
callbackCommand => $callbackCommand
};
HttpUtils_NonblockingGet($apiParam);
return undef;
}
sub GetSnapshot_Callback {
sub RequestSnapshot_Callback {
my ($param, $err, $snapshot) = @_;
my $hash = $param->{hash};
my $name = $hash->{NAME};
@ -527,7 +558,6 @@ sub GetSnapshot_Callback {
Log3 $name, 4, "IPCAM ($name) - image: $imageFile";
}
if($seq == $seqImages) {
readingsBulkUpdate($hash, "snapshots", $seq, 1);
$seq = 0;
@ -535,6 +565,11 @@ sub GetSnapshot_Callback {
readingsEndUpdate($hash, defined($hash->{LOCAL} ? 0 : 1));
$hash->{SEQ} = $seq;
}
my $callbackCommand = $param->{callbackCommand};
if (defined $callbackCommand) {
Log3 $name, 0, "IPCAM ($name) - RequestSnapshotWithCallback would execute $callbackCommand";
}
}
@ -742,6 +777,15 @@ DetailFn {
and the time interval between images can be specified using the<br>
attributes <code>snapshots</code> and <code>delay</code>.
</li>
<li><code>imageWithCallback</code><br>
Like <code>get image</code>, but allows you to provide a command<br>
that's executed as soon as the picture is taken.<br>
This is one-time trigger only, not for intervals and more images.<br>
Allows you to eg send pictures immediately and <br>
without creating a dedicated notify.<br>
Example:<br>
<code>get ipcam3 imageWithCallback set pushmsg msg Frontdoor Ding Dong! expire=3600 attachment='www/snapshot/ipcam3_snapshot.jpg'</code>
</li>
<li><code>last</code><br>
Show the name of the last snapshot.
</li>
@ -852,6 +896,12 @@ DetailFn {
Example:<br>
<code>attr ipcam3 pathPanTilt decoder_control.cgi?user={USERNAME}&amp;pwd={PASSWORD}</code>
</li>
<li>
query<br>
query string parameters that will be attached to all commands. Without leading ? or &amp;<br>
Example:<br>
<code>attr ipcam3 query user={USERNAME}&amp;pwd={PASSWORD}</code>
</li>
<li><a href="#showtime">showtime</a></li>
<li>
scheme<br>