Jump to content

Network Resource To E-Mail IP Camera Images on Motion


kevkmartin

Recommended Posts

Posted
\n";

print "Executing snapshot.pl\n\n";

print "Capture $image_count images spaced $image_spacing seconds apart:\n";



#Define image capture start and end times

my $startTime = time;

print "\tCapture start time is $startTime\n\n";



#Create new directory for image set

my $new_directory = "$out_dir/$startTime";

print "New Directory: $new_directory\n\n";

mkdir $new_directory;



#Reset image index (counter)

my $index = 0;



#Store the first expected image filename - will be used to determine if camera responded with a valid image

$first_image_file = sprintf("$new_directory/image-%s-00001.jpg", $startTime);
print "\$first_image_file=$first_image_file\n\n";



#Loop for desired image count, capturing and saving camera snapshot images

print "--------------------------------------------------------------------------------\n\n";


while ($index < $image_count)
{

$index++;

print "Time is " . time . "\n";

#Set full image filename

$output = sprintf("$new_directory/image-%s-%05d.jpg", $startTime, $index);

#Retrieve snapshot image from camera

my $result = `/usr/bin/wget -O $output $cam_url`; #Retrieve image from camera and save to file

print "Saved $output\n\n";

print "--------------------------------------------------------------------------------\n\n";

#Wait until next snapshot time

sleep($image_spacing);

}




if ((-e $first_image_file) and (-s $first_image_file)) #check for existence and size of expected camera image file
{

#Since a non-zero sized file was created (from the camera), build e-mail with images attached

#Set up e-mail parameters

$subject = "Driveway Motion Detected...";
$body = "Captured these images:\n";


#Build attachment file list from all file names in the output directory

@files = <$new_directory/*>;

foreach $file (@files)
{
$attachment_files .= "$file,";
}

$attachment_files =~ s/,$//;

print "Sending e-mail...\n";
print "\t\$mail_host=$mail_host\n";
print "\t\$mail_user=$mail_user\n";
print "\t\$mail_pass=$mail_pass\n";
print "\t\$subject=$subject\n";
print "\t\$body=$body\n";
print "\t\$attachment_files=$attachment_files\n";

}

else
{

#No file, or a zero sized file was created. Build FAILURE e-mail
#Set up failure e-mail parameters

$subject = "Driveway Camera FAILED...";
$body = "Camera did not produce requested images.\n";

print "Sending e-mail...\n";
print "\t\$mail_host=$mail_host\n";
print "\t\$mail_user=$mail_user\n";
print "\t\$mail_pass=$mail_pass\n";
print "\t\$subject=$subject\n";
print "\t\$body=$body\n";
print "\t\$attachment_files=$attachment_files\n";

}



#Send e-mail with parameters defined above

my $mail=Email::Send::SMTP::Gmail->new ( -smtp=>$mail_host,
-login=>$mail_user,
-pass=>$mail_pass
);

$mail->send ( -to=>$mail_recipient,
-subject=>$subject,
-verbose=>'1',
-body=>$body,
-attachments=>$attachment_files
);

$mail->bye;



print "
  • 4 weeks later...
Posted

The network resource is just a simple GET to my web server:

 

Server:192.168.xx.yy

Port:zz

 

Resource:

 

/cgi-bin/snapshot.pl

 

 

Sent from my iPad using Tapatalk HD

Posted

I am trying to get my head around network resources. So the simple Get just requests a page from the server, and your page happens to be a perl script that gets run?

 

That being similar in concept to a wget command from the command line.

 

So by theory, we could have any perl script called because the webserver can run it when requested by a page hit.

 

Your server is running Apache, or maybe misterhouse with it's little webserver or ??

 

Always been a bit concerned with security with a webserver running because they just seem to have lots of open vulnerabilities.

Posted

The web server is on my internal network. It in not open to anyone outside the house. You must already be on my network.

 

Yes. You are correct. Any perl script can be kicked off via network resource using this method.

 

My server is running Ubuntu, and apache.

 

 

Sent from my iPad using Tapatalk HD

Guest
This topic is now closed to further replies.

×
×
  • Create New...