The Self-Sufficient Homestead
May 18, 2013, 11:28:07 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The Straw-Bosses will be adding & reorganizing the message boards, so be patient. Johnny MAX
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: DIY security cameras  (Read 1168 times)
jakematic
Plantation Owner
*****
Offline Offline

Posts: 1240



View Profile
« on: October 19, 2012, 09:58:39 AM »

I can't bring myself to pay monthly for an alarm service, and every one I trialed never worked the way it should.
After seeing some network cameras on closeout at BestBuy I picked a couple of them up.
Over the years I've added more including one in the garage.



Looked at different software solutions on the internet but didn't like most of them and BOY were they expensive.
So I made my own.

On the cameras you can tell them to save files and do things if either motion is detected or the body heat sensor goes off.
My Linux machine has a web server on it so the lightbulb went off.
Basically they are set to save pictures to the Linux machine every time a sensor gets activated.




Taking this a bit farther I decided I wanted full video with audio.
So the trigger issues an HTTP notification that in turn runs a CGI script on my "server".



The script then calls ffmpeg to record 60 seconds of video to the webserver.
The next natural progression was to add alerts - kind of like setting an alarm to Away mode.

So I added the functionality to text me an alert telling me which camera went off along with the first picture it captures.
It then emails the video to my work and mobile email so I can see what is going on.

Code:
#!/bin/bash
#This is /var/www/cgi-bin/Loop.cgi
Eye=$1
IP=$(echo " ${Eye} + 209 " | bc)
Dir="/Fedora/Eye${Eye}"
Out="/Fedora/Eyes"
Now=$(/bin/date +%Y_%m_%d_%H%M%S)
Num=$(ps -ef | grep "var/www/cgi-bin/Loop.cgi ${Eye}" | grep -v grep | wc -l)
if [ ${Num} -gt 2 ]
then
/bin/sleep 1
else
# Alert me ANY time there is motion in the garage
if [ "${Eye}" = "4" ];then
echo "** AUDICAM ** Sensor at $(/bin/date)." | /usr/local/bin/email -s "** AUDICAM ALERT **" user@email
fi
# Record with audio
/usr/local/bin/ffmpeg -y -t 60 -i "rtsp://userid:password@192.168.0.${IP}/nphMpeg4/g726-640x480" ${Out}/Eye${Eye}_${Now}_Loop.mpg > /dev/null 2>&1 &
/bin/sleep 60
if [ ! -z "$(ls ${Dir}/*.jpg 2>/dev/null)" ]
then
TrigPic=$(/bin/ls -tr ${Dir} | /bin/grep -v archive | /usr/bin/head -1)
if [ -f /Fedora/00_NOBODYHOME.txt ];then
# Text the trigger picture
echo "Sensor ${Eye} at $(/bin/date)." | /usr/local/bin/email -s "Camera ALERT" -attach ${Dir}/${TrigPic} user@email
# Email the movie
echo "Sensor ${Eye} at $(/bin/date)." | /usr/local/bin/email -s "Camera ALERT" -attach ${Out}/Eye${Eye}_${Now}_Loop.mp4 user@email,user2@email
fi
                # Cleanup links and move individual snaps to archive
/bin/rm -f ${Out}/${Eye}_Latest.mpg > /dev/null 2>&1
/bin/rm -f ${Out}/${Eye}_Trigger.jpg > /dev/null 2>&1
/bin/ln -s ${Out}/Eye${Eye}_${Now}_Loop.mpg ${Out}/${Eye}_Latest.mpg
/bin/mv ${Dir}/*.jpg ${Dir}/archive/
/bin/ln -s ${Dir}/archive/${TrigPic} ${Out}/${Eye}_Trigger.jpg
fi
fi
exit 0

Naturally this is all setup so I can access the cameras remotely from my phone, or even one time from a customer's computer.

This is not exactly for the beginner, but I wanted to show everyone what is possible.
If you have any questions or ideas let me know! Thanks-Jake
Logged

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."

“Money is the material shape of the principle that men who wish to deal with one another must deal by trade and give value for value.”
fritz_monroe
Plantation Owner
*****
Offline Offline

Posts: 506


View Profile WWW
« Reply #1 on: October 19, 2012, 01:30:32 PM »

Very cool, thanks for sharing.  I'm no programmer, but I play around with Linux and can do some scripting.  When I'm ready, I'll poke around at the script to see if I can figure out what it is doing.  I have plenty of computer hardware laying around the house, might as well put it to work. 

Care to point to some decent network cameras?  That one you have a picture of sells for over $200 on Amazon.  Way out of my price range at the moment.
Logged

F_M
Check out my blogs at The Homestead Fritz and Camping with Fritz
jakematic
Plantation Owner
*****
Offline Offline

Posts: 1240



View Profile
« Reply #2 on: October 19, 2012, 02:07:27 PM »

I recently helped my brother put these in at his business: http://www.amazon.com/Foscam-FI8910W-Wireless-Network-Camera/dp/B006ZP8UOW/
He's probably one of the few people on the planet cheaper than BoatGuy and me.

They are $85 and very good quality.
Also I like that range of pan/tilt and the night vision feature works very well.

He used the software that came with them, but I'm sure you can do the same kind of thing I did.
I'd avoid USB cameras unless you use just one - lots of history with them and how they tend to over-run the bus.

ZoneMinder is another great alternative that's free and runs on Linux http://www.zoneminder.com/
Logged

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."

“Money is the material shape of the principle that men who wish to deal with one another must deal by trade and give value for value.”
fritz_monroe
Plantation Owner
*****
Offline Offline

Posts: 506


View Profile WWW
« Reply #3 on: October 21, 2012, 08:27:25 AM »

Thanks again for the info.  I had no idea that Zone Minder existed.  When I'm ready I'll certainly check that out.
Logged

F_M
Check out my blogs at The Homestead Fritz and Camping with Fritz
BoatGuy
Straw-Boss
Plantation Owner
*****
Offline Offline

Posts: 2128



View Profile WWW
« Reply #4 on: October 21, 2012, 11:02:42 AM »

You might also want to get a small fire safe or use part of an existing gun safe and bolt it to the floor and wall from the inside. Put the computer and a small ups inside and route all the cameras to it. If power or internet is cut, you still have video for the police.

Just a geeky nerds idea...
Logged

http://concharty.com
http://facebook.com/concharty

I could be wrong. But, I am not wong very often.
Johnny-Max
Big Straw-Boss
Plantation Owner
*****
Offline Offline

Posts: 4499



View Profile
« Reply #5 on: October 22, 2012, 03:56:08 PM »

Way Cool Man! Smiley
Logged

fritz_monroe
Plantation Owner
*****
Offline Offline

Posts: 506


View Profile WWW
« Reply #6 on: October 24, 2012, 01:10:37 PM »

I'd avoid USB cameras unless you use just one - lots of history with them and how they tend to over-run the bus.
So, do you mean that you would stick to a single USB camera?  Or do you mean a single USB on each computer attached to the network?  For instance, I have several old low power desktop systems socked away in the basement.  Would I be able to put several of these on the network with a single USB camera without worrying about over running the bus?
Logged

F_M
Check out my blogs at The Homestead Fritz and Camping with Fritz
jakematic
Plantation Owner
*****
Offline Offline

Posts: 1240



View Profile
« Reply #7 on: October 24, 2012, 04:20:09 PM »

You have to avoid putting more than one camera on each USB controller.
There are some really funky ways around it and I spent about a month working on it for an unrelated project.
That project will hopefully get finished soon and turn into a moneymaker on the side for me.

If you put one on each machine you would have to use a streaming server to get it over the network.
Something like FFserver or VLC.

Depending on the resolution you'd be pushing a TON of network traffic.
When I monitor 4 of them in a browser at 640x480 they push around 1MBps.

Logitech webcams have the best support under UVC http://www.ideasonboard.org/uvc/
Avoid the Microsoft ones - they are hit an miss at best, especially with USB3 ports which may not be an issue on your machines.

I like the networked machine idea, lots of moving parts though
- you'd have to centrally capture via streaming
- or do you store and forward the videos
- setup and configuration of streaming server
- how would you monitor them all in one pane of glass - if that was important
- could be tricky to configure all this to see remote from a phone/tablet/etc

Which reminds me IP Cam Viewer Pro is the hands down best or breed https://itunes.apple.com/us/app/ip-cam-viewer-pro/id402656416?mt=8
It's also available on Android and is well worth the $4 - and I have/had every other available on both platforms.
Logged

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."

“Money is the material shape of the principle that men who wish to deal with one another must deal by trade and give value for value.”
BoatGuy
Straw-Boss
Plantation Owner
*****
Offline Offline

Posts: 2128



View Profile WWW
« Reply #8 on: October 24, 2012, 04:54:34 PM »

Jakematic,

What you need is a usb multiplexer. then, you could feed as many cameras as you want, up to the bandwidth of the usb connection. since full motion video is only 30 frames per second and usb 2.0 is 60 Mbytes/sec, it would seem possible to hook quite a few together... even more if you put the jpeg compression on the front end of the multiplexer, and do it in the hardware (say through an asic... for that matter, you could do the whole multiplexer in an asic, too, and use it for camera control.. it would be perfect for that.), instead of software.

just a thought...
Logged

http://concharty.com
http://facebook.com/concharty

I could be wrong. But, I am not wong very often.
jakematic
Plantation Owner
*****
Offline Offline

Posts: 1240



View Profile
« Reply #9 on: October 24, 2012, 05:11:40 PM »

That would work BG, it would just be a matter of writing the software.
Logged

"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."

“Money is the material shape of the principle that men who wish to deal with one another must deal by trade and give value for value.”
fritz_monroe
Plantation Owner
*****
Offline Offline

Posts: 506


View Profile WWW
« Reply #10 on: October 25, 2012, 08:29:20 AM »

Which reminds me IP Cam Viewer Pro is the hands down best or breed https://itunes.apple.com/us/app/ip-cam-viewer-pro/id402656416?mt=8
It's also available on Android and is well worth the $4 - and I have/had every other available on both platforms.
I don't have this to worry about.  I don't have a smart phone and don't really have any desire for one.

But thanks for the info.  I'm in the research stage of this project.  Eventually I'll move into the planning stage, but not quite yet.  I certainly don't like the prices of some of those network cameras.
Logged

F_M
Check out my blogs at The Homestead Fritz and Camping with Fritz
Ggirl
Straw-Boss
Plantation Owner
*****
Offline Offline

Posts: 2908



View Profile WWW
« Reply #11 on: October 28, 2012, 07:56:48 PM »

That is great jake.  A little - no a lot over my head.  But It sounds great!
Logged

podcast and blog at www.youcanhomestead.com
http://www.facebook.com/gale.dacalio new FB page
http://pinterest.com/ggirl1959/
skype name: galed.honeybee
twitter name: Ucanhomested
RSS: http://feeds.feedburner.com/Youcanhomestead
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!