Close

Snapshot of motion detection

Learn how to turn an Android phone into an IP camera security system with Sighthound, download automation scripts & more.

Moderator: Staff

no avatar
mrmisi
 
Posts: 12
Joined: Tue Apr 22, 2014 9:55 am

Snapshot of motion detection

by mrmisi » Tue Sep 15, 2015 1:21 pm

Ok, I've posted it in the wrong section:

There is a way to get locally the snapshot that the program send by email when the camera detect a motion (not the clip)?
I'm trying to send it by pushbullet using a Perl script and the link for the snapshot of D-Link camera (cause I'm too lazy to open e-mail and in this way it appear in the notification bar), but the "run the command" option is too slow and when it takes the picture is too late.

(Sorry for my bad english, I'm italian)

thx,
Matteo.

User avatar
ryan
 
Posts: 1015
Joined: Wed Aug 25, 2010 2:52 pm
Location: Palo Alto, California

Re: Snapshot of motion detection

by ryan » Mon Sep 21, 2015 3:52 pm

Hi Matteo,

There isn't a way to do this at the moment, but it's something we would like to support in the future.

Best,
- ryan
Learn more about Sighthound Video in our support pages - Reference Guide | All Articles
Are you a developer? Check out our cloud APIs - Demo | Docs

no avatar
mrmisi
 
Posts: 12
Joined: Tue Apr 22, 2014 9:55 am

Re: Snapshot of motion detection

by mrmisi » Tue Nov 03, 2015 7:23 am

Ok, I've spent a little bit of time to write a script to do that. It's in Perl and I post here if there is someone interested.

It work like that: Sighthound send the email with the snapshot, the script download the attachment and send it through Pushbullet, and finally delete the file. (N.B. The emails will be deleted!!)
It work better if there are a dedicated email address just for that.

Here's the script (I've called it "Pushound" :D ). Be sure that you've installed the cpan module first!

Bye, Matteo.

Code: Select all
use strict;
use warnings;
use LWP::Simple;
use JSON;
use Mail::POP3Client;
use Email::MIME;
use Email::MIME::Attachment::Stripper;



# Sighthound Video Settings

   my $camera =      'camera';         #Your camera's name in Sighthound

# POP3 Email settings

   my $popuser =      'your.email@address.com';       #The e-mail address where Sighthound send the snapshot
   my $poppassword =   'password';                     #Password of e-mail address where Sighthound send the snapshot
   my $popserver =      'pop.gmail.com';                #POP3 Server e-mail address where Sighthound send the snapshot
   my $popSSL =      'true';                           #SSL Authentication, true or false

# Pushbullet settings

   my $api_key  =      'PUSHBULLETAPI';   #Your Pushbullet's API
   my $password =       'PUSHBULLETPASSWORD';   #Your Pushbullet's password
   my $device   =       'PUSHBULLETDEVICE';   #Your Pushbullet's device ID
   

   my $pop = new Mail::POP3Client(
             USER      => $popuser,
             PASSWORD  => $poppassword,
             HOST      => $popserver,
             USESSL    => $popSSL,
             );

   if ($pop->Count())

      {

       my $mail=$pop->HeadAndBody(1);
      my $parsed = Email::MIME->new($mail);
      my $stripper = Email::MIME::Attachment::Stripper->new($parsed);
      my @attachments = $stripper->attachments;
 
      foreach my $att ( @attachments )

                {

         open (FILE, ">>" . $att->{filename});
         binmode FILE;
                print FILE $att->{payload};
                close (FILE);

         }     


      $pop->Close();

      }


   my $file_name = $camera.'.jpg';
   my $file_type = $camera.'/jpg';

   my $user_agent = LWP::UserAgent->new();
   $user_agent->agent('My File Pusher v1.0');

   my $request_response =  $user_agent->post('https://api.pushbullet.com/v2/upload-request',
      'Authorization' => 'Bearer '.$api_key,
                'Content'       => ['file_name' => $file_name,
                'file_type' => $file_type]);

   if ($request_response->is_success)

   {

      my $json = from_json($request_response->content);
      if ($json->{'upload_url'})
   
      {

         my @data;
             foreach my $item ('awsaccesskeyid', 'acl', 'key', 'signature', 'policy', 'content-type')

         {

                  push(@data, $item => $json->{'data'}->{$item})
         }

          push(@data, 'file' => [ $file_name ]);
          my $upload_response = $user_agent->post($json->{'upload_url'},
                                            'Content_Type' => 'form-data',
                                            'Content'      => \@data);

          if ($upload_response->is_success)

      {

               my $push_response = $user_agent->post('https://api.pushbullet.com/v2/pushes',
            'Authorization' => 'Bearer '.$api_key,
            'Content-Type'  => 'application/json',
            'Content'       => to_json({'device_iden' => $device,
            'type'        => 'file',
            'file_name'   => $json->{'file_name'},
            'file_type'   => $json->{'file_type'},
            'file_url'    => $json->{'file_url'}}));

           }
   }

   
   unlink($camera.'.jpg');


}





no avatar
habari
 
Posts: 16
Joined: Sat Sep 13, 2014 5:40 pm

Re: Snapshot of motion detection

by habari » Sun Nov 15, 2015 10:31 am

mrmisi, that is great!

I use a 2010 mac mini for my Indigo based home automation system, and a separate i5 2013 iMac for Sighthound, given the intensive processor requirements. Currently, I have Indigo condition based triggers that fire when motion is detected or the doorbell rings, if we are away or the alarm is set. This trigger executes the script below (thanks berkinet at www.IndigoDomo.com forums) and captures the images from my cameras directly onto my home automation Mac mini. The images are stored in ~/var/"your folder" (use multiple repeats of the script/folders for multiple cameras) and then can be sent via email.

My issue is that I bought an RTSP camera that does not have scriptable HTTP image capture, and thus this script cannot grab an image from that camera. So I need to grab an image directly from Sighthound. It looks like your script might do that. However, since in my situation Sighthound exists on a separate mac and SH does not allow multiple clients, do you think your script could be modified to grab the image from Sighthound and store in a folder on a my home automation computer? That way I could send a single email with all the pictures.

Hope this is clear!

thanks,

Ham



Code: Select all
#!/bin/ksh

# Set a few static options
PIC_FOLDER=/Var/Photos_SideDoor_Motion
URL=http://10.0.1.xx/live/0/jpeg.jpg
DELAY_TO_START=0
INTERVAL=1
MAX_PIC=1
USERNAME=XXXXXX
PASSWORD=XXXXX

# ----- Do not change anything below this line -----
#DATE=`date +"%y-%m-%d-%H_%M_%S"`
#TARGET_DIR=${PIC_FOLDER}
#mkdir  $TARGET_DIR

sleep $DELAY_TO_START

for i in {1..$MAX_PIC}
do
#FNAME=${PIC_FOLDER}/PIC-${i}.jpg
FNAME=${PIC_FOLDER}/PIC.jpg
curl -s -u ${USERNAME}:${PASSWORD} $URL >$FNAME
sleep $INTERVAL
done


no avatar
stevieby1
 
Posts: 6
Joined: Thu Apr 07, 2016 3:50 pm

Re: Snapshot of motion detection

by stevieby1 » Fri Apr 08, 2016 2:27 pm

For Windows I've also done something, although I have a fake SMTP Server which takes the image and saves it. Working well as Sighthound does not know any different

no avatar
habari
 
Posts: 16
Joined: Sat Sep 13, 2014 5:40 pm

Re: Snapshot of motion detection

by habari » Fri Apr 08, 2016 11:07 pm

Thanks for the post. Could you paste your script? Maybe it's adaptable to something UNIX-like.

no avatar
stevieby1
 
Posts: 6
Joined: Thu Apr 07, 2016 3:50 pm

Re: Snapshot of motion detection

by stevieby1 » Fri Apr 15, 2016 1:02 pm

It's not a script but some .NET code which uses some packages for SMTP and Pushbullet, but maybe in future could get it running on Mono perhaps?

no avatar
whmoorejr
 
Posts: 7
Joined: Mon Aug 22, 2016 11:07 am

Re: Snapshot of motion detection

by whmoorejr » Mon Aug 22, 2016 2:22 pm

habari wrote:RTSP camera that does not have scriptable HTTP image capture[/code]


For URL, use the following:
H264 Cameras:
Code: Select all
http://10.0.6.182:8082/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=master&pwd=donkey

replace "10.0.6.182:8082" with URL of your camera
replace "master" with your username for camera
replace "donkey" with your password for camera


MJPEG Cameras:
Code: Select all
http://10.0.6.122:82/snapshot.cgi?user=master&pwd=donkey

replace "10/0/6/122:82" with URL of your camera
replace "master" with your username for camera
replace "donkey" with your password for camera

no avatar
BernieCyr
 
Posts: 12
Joined: Mon Sep 05, 2016 7:24 am

Re: Snapshot of motion detection

by BernieCyr » Thu Oct 18, 2018 3:15 pm

I use a rule to "take action" sending an email with attachment in full resolution.
My email then sorts all my sighthound email into a single folder.

Using windows outlook 2010 I have a script that I run to save all attachments of all emails highlighted to a folder. executed from within outlook via alt-f8

This export all attachments from my email to a folder. Although manual this works but the attachment contains the bounding box around the detected object. I have suggested as a `feature request` to save image to a folder (such as "dropbox/googledrive/amazon drive/onedrive" that auto upload to cloud) as part of the rules within sighthound under the feature request forum as follows:

Do a google search for "mAttachmentSaver.bas" you can find out more on how to install within outlook alt-f11 and run alt-f8

My feature request request:
a) Creation of a rule to save image to folder in full resolution on trigger of event.
b) Export photo option similar to right click and export of video current feature.

User avatar
teladog01
 
Posts: 13
Joined: Mon Jun 20, 2016 9:47 am

Re: Snapshot of motion detection

by teladog01 » Tue Feb 26, 2019 9:26 pm

Hi Matteo,

There isn't a way to do this at the moment, but it's something we would like to support in the future.

Best,
- ryan


Three and a half years on now...any chance this "Save Snapshot" functionality is being worked on? Sure would be nice to have...


Return to Hacker's Corner
cron