Event detection

My house alarm system is coupled to a webcam which on an alarm event uploads pictures to my linux server. What I would like to do is have the server notify me by e-mail and/or SMS message whenever the webcam uploads pictures. What is the best way to achieve this; some sort of cron-job that runs very frequently; or is there another way?
SteveHodgeAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sunnycoderConnect With a Mentor Commented:
Hi Steve,

In that case, you can use some readymade code to solve your problem ... The code will monitor the directory in which images are uploaded and as soon as it senses a change in the directory listing, it will generate a mail/message

You can use either PHP (dont script much in PHP myself but was able to find something very useful in the manual)
http://www.linuxforum.com/phpmanual/ref.fam.html
http://www.linuxforum.com/phpmanual/function.fam-monitor-collection.html

Or C++ code
http://www.linuxquestions.org/questions/showthread.php?threadid=22105

Or you can download and use a utility like dnotify
http://linux.tcpip.com.cn/download/showdown.php?pa=2337

or a simple script like

#!/bin/bash

ls /path/to/my_dir > out1.txt
d=`diff out1.txt out2.txt`
if [ -n "$d" ]
then
       mail "alert" someone@something.com //or whatever your mailing /smsing command line
fi
mv -f out1.txt out2.txt

you can run this as a cron job every minute .... ofcourse for first execution, you will have to create an out2.txt yourself ...

cheers
sunnycoder
0
 
sunnycoderCommented:
Hi SteveHodge,

>What I would like to do is have the server notify me by e-mail and/or SMS message whenever the webcam uploads pictures.
There might be several options here ...

One you could write a small stub in the kernel, to be more specific in the IRQ handler for webcam ... If webcam is not running on linux, then how are the pictures uploaded (ftp/tftp etc.) ... You can edit the code for that server to check for this specific instance and generate a mail when you need to be notified ....

Both these approaches will make your notifications event based and hence will be fast (in terms of delay) and less resource consuming (in terms of cycles wasted polling) ...

Still another way out is what you suggested ... writing a daemon program which will scan the directory in which pictures are uploaded and as soon as it finds a change in the directory listing, it shall generate a mail/message ... Obvious drawback is the processing time spent polling the directory ....

Let me know which approach suits you the most and we can discuss that further ....

cheers
sunnycoder
0
 
SteveHodgeAuthor Commented:
The webcam does run on Linux, it is an Axis 2100, but I would rather not mess around with the code in it (proprietary code, upgrades come every now and again etc). It uploads via ftp to the linux server. I am not too worried about the processing load on the linux server, it is very under-loaded indeed, so a solution that is easy to implement even if expensive on processor cycles would be my preferred direction, especially since I am really not at all proficient at at writing scripts and so on

Steve
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
SadrulCommented:
you can use `fcntl' function. you'll set fd to the directory where the images get uploaded, cmd to F_NOTIFY and arg to DN_CREATE. you'll get a SIGIO whenever a file is created in the directory. look into the man page for more details.

(PS: you'll have to define _GNU_SOURCE before you #include <fcntl.h>)

-- Adil
0
 
SteveHodgeAuthor Commented:
Many thanks sunnycoder - I am sure I can get this working. Thanks also Adil, but I have given the points to sunnycoder as he was first, and also his solution works on my level of linux proficiency.

I am going to post another question now on whether anyone knows how to send an SMS from a linux box. Meanwhile I'll get it working with email

Steve
0
 
SadrulCommented:
no problemo :-)

-- Adil
0
 
ddddCommented:
SteveHodge:

i face same probleum like you.
did you found the solution? if yes can you email to me: <email -id removed by sunnycoder, Page Editor>
coz the solution you accept cannot go in : http://linux.tcpip.com.cn/download/showdown.php?pa=2337

thanks
0
 
ddddCommented:
sunnycoder
>http://linux.tcpip.com.cn/download/showdown.php?pa=2337
the link above is removed, can you provide another link if you have?
thanks
0
 
sunnycoderCommented:
Posted in your question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.