Have you ever heard of Raspberry Pi? It's a low-cost micro-computer that is able to run Linux and has endless extension possibilities. It cost only about US$35 and opens up endless possibilities of what you can build with it. The official website can be found at http://www.raspberrypi.org/
We need some hardware for this project. This is a list of the major things we need:
At first, you should install the OS and software to the Raspberry Pi before mounting it all together. An OS is the basic operating system software that tells the Raspberry hardware what to do. Linux is perfect for this. We have chosen Raspbian, as it's one of the most advanced OS for the Raspberry with loads of help and tutorials on the internet.
You need to prepare the SD card to be able to run Raspbian on the Raspberry: this excellent tutorial from Adafruit will explain the necessary steps.
Now temporarily connect your Raspberry Pi board to LAN cable, a monitor (HDMI TV works out of the box, but a HDMI-to-DVI cable like this will do the job as well) and a USB keyboard for the basic setup.
Insert the prepared SD card with the Raspbian installer on it and attach the power supply.
The Raspberry should boot up and guide you through the setup process as explained in this Adafruit tutorial. After this, you should have a basic Raspbian OS running.
Be sure to enable SSH in Raspbian so that you are able to control the Raspberry device also when there is no monitor and keyboard attached. And you should also enable the camera from the Raspbian setup menu so that we can use it for motion detection.
Now make sure your RPI is up to date:
sudo apt-get install rpi-update sudo rpi-update
And also update all packages:
sudo apt-get update sudo apt-get upgrade
Now that the basic setup is done, you should connect to your Raspberry device from your computer. You can connect to Linux console from any computer in your local network and control it like you where sitting directly in front of it. This is very important as once mounted far away from your desktop, you need to be able to make updates and change the configuration of this camera any time later without the need to detaching it from the wall and bringing it back to your desk.
Remember that this cam is not just a dump cam device but a very powerful computer with Linux OS running on it. It's not limited to what we explain in this article now; it will follow any development in software so that you will be able to install updated software and more modules any time later.
First, you need a software to connect to the Linux console on the Raspberry. For Windows, you will need the extra (free) software PuTTY. Download it from the PuTTY website, install it and connect to your Raspberry Pi device:
From now on, you don't need any monitor and keyboard attached to the Raspberry anymore.
sudo nano /etc/network/interfacesNow add these lines at the end of the file (or change existing lines to match these):
allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "YOUR NETWORK SSID" wpa-psk "WIFI PASSWORD"(Fill in the SSID and password for your WiFi network)
sudo apt-get install motionSome packages will be installed in the installation process; just type "y" to proceed with the installation.
cd /tmp sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gzAnd now you need to unpack the downloaded file to the /tmp directory:
tar zxvf motion-mmal.tar.gzAfter this unzipping, you now need to update your installed motion with the downloaded build:
sudo mv motion /usr/bin/motion sudo mv motion-mmalcam.conf /etc/motion.confYou also need to enable the motion daemon so that motion will always run:
sudo nano /etc/default/motionand change the line to:
start_motion_daemon=yesWe're pretty sure that the official build of motion will shortly also support the Raspberry camera module as well.
sudo nano /etc/motion.confNote: in the standard motion installation, the motion.conf is in /etc/motion/, but in the special motion-mmal build from dropbox-url (see above) it's in /etc/. If you follow this tutorial with all steps, this is no problem at all.
sudo chmod 664 /etc/motion.conf sudo chmod 755 /usr/bin/motion sudo touch /tmp/motion.log sudo chmod 775 /tmp/motion.logWe've made some changes to the motion.conf file to fit our needs. Our current motion.conf file can be downloaded here. Just download, unzip and copy the containing motion.conf to /etc/motion.conf if you would like to use the exact config options we describe below.
We want to store the logfile in /tmp instead (otherwise autostart user won't be able to acces it in /home/pi/ folder):
logfile /tmp/motion.logAs we want to use a high quality surveillance video, we've set the resolution to 1280x720:
width 1280 height 720We don't need real-time video, 2 pictures per second are totally ok for our needs:
framerate 2This is a very handy feature of the motion software: record some (2 in our configuration) frames before and after the motion in the image was detected:
pre_capture 2 post_capture 2We don't want endless movies. Instead, we want to have max. 10 minutes slices of the motion videos. This config option was renamed from max_movie_time to max_mpeg_time in motion. If you use the motion-mmal build, this one will work. If you get an error 'Unknown config option "max_mpeg_time"' either change this one to max_movie_time or make sure to really use the motion-mmal build as shown above.
max_mpeg_time 600As some media players like VLC are unable to play the recorded movies, we've changed the codec to msmpeg4. Then, the movies play correctly in all players:
ffmpeg_video_codec msmpeg4Enable access to the live stream from anywhere. Otherwise only localhost (= the Raspberry device) would be allowed to access the live stream:
stream_localhost offIf you want to protect the live stream with a username and password, you should enable this:
stream_auth_method 2 stream_authentication SOMEUSERNAME:SOMEPASSWORDAll configuration parameters are explained in detail in the motion config documentation.
sudo rebootAfter the reboot, the red light of the camera module should be turned on, which shows that motion currently is using the camera to detect any movement.
sudo nano /etc/fstabNow add an extra line with the configuration of your Windows network shared folder:
//YOURSERVERNAME/YOURSHAREDFOLDERNAME /mnt/camshare cifs username=YOURSHAREDFOLDERUSERNAME,password=YOURSHAREDFOLDERPASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0Be sure that the user has the correct permissions to save files to that shared folder.
target_dir /mnt/camshareso that motion saves all movies to the shared folder on the Windows machine.
sudo nano /etc/init.d/motionand add the line
sleep 30to the start-sequence.
Now you can access the live stream from the camera from any browser via the url http://IPADDRESSOFRASPBERRY:8080
Where 8080 is the port that we've configured for our stream in the motion.conf file. See your own configuration setting "stream_port" in motion.conf for the port.
We've found out that Google Chrome 30 (not even on iOS) wasn't able to play this stream directly due to a bug in the underlying Chromium project.
A workaround for this is to create a simple html file that contains one large image with the stream-url of the camera. See the file cam.html from raspberry_surveillance_cam_scavix.zip. This way, Chrome can show the live stream as well. Let's hope that Chrome will fix this issue in their browser.
But other browsers like FireFox, Safari and even VLC media player was able to show the live stream of the camera.
We were not able to make the live stream work in Internet Explorer as it doesn't support Motion JPEG. Kenneth Lavrsen (the maker of motion) has described workaround for live stream in Internet Explorer here.
To make the live stream accessible from anywhere, you will need to enable some kind of dynamic domain services to your local network. This will enable you to always be able to connect to your local IP address from the outside even if your local IP address changes (over here in Germany, every private DSL ip address changes every 24 hours).
Such a (free) service enables you to access your Raspberry from anywhere even if your ip address changes. A very good service we're using for some years now is dyn.com. They have some free services and are integrated in many routers.
Once you have set up the dynamic ip url, you can access the camera stream from anywhere in your browser (i.e. http://YOURDYNAMICDOMAIN:8080).
And this also works from the browser on your mobile device.
There are a thousand things you can do with such a surveillance cam basic setup now. How about sending Growl notifications when some motion was detected? This guide explains how to add this functionality easily.
Or you could easily add a temperature-sensor to the cam. It's only a few bucks and can be integrated very easily.
We're currently working on integrating the live stream into MediaPortal server so that we can switch to a TV channel to see the live stream from the cam in our office.
If you want extra security, you could also add a battery pack to the camera. Be sure to buy one that is able to charge simultaneously while powering the Raspberry. This would enable you to detect if some bad guy cuts the power strips of your camera and send some alert messages to you (i.e. SMS or email) including the video of the disturber.
What are you going to add? Let us know!