Tag Archives: PoE

raspberry pi model B surveillance camera

How to turn your Raspberry Pi into a video streaming surveillance webcam and take simultaneously time lapse snapshots?

I want to make a time lapse video of our garden a whole year around and at the same time have a video stream that shows what is going on. I did quite a bit of reading and testing and this is what I ended up with:

– live streaming via a website

– taking a snapshot every minute

– save the files in a folder as jpg

– create a folder for every single day

– create files incl. date & time in the file name

– access the files via Mac OSx / AFP

Hardware:

– Raspberry PI v2

Raspberry Pi model B

Raspberry Pi model B

– Raspicam module

Raspberry Pi Camera Module

Raspberry Pi Camera Module

– Dummy Surveillance Camera (optional)

Dummy surveilance camera

Dummy surveilance camera

– Passive POE injector & splitter (optional)

passive PoE injector & splitter

passive PoE injector & splitter

– 5V USB charger (make sure it is a good quality one, otherwise you might experience that the Raspberry hangs occasionally, like I had)

USB charger

USB charger

– class 10 SD Card, the larger it is, the more storage space you have for the images.

16 GB SD Card

16 GB SD Card

– some m3 bolts & nuts

m3 nuts and bolts

First I hacked together the hardware like this:

1) cut the micro USB cable in two and insert the DC Plug & DC Socket in between (5.5mm x 2.1mm fits the Digitus passive POE connectors)

USB cable with power connector in between

USB cable with power connector in between

PoE injector & splitter combined with the modified USB cable

PoE injector & splitter combined with the modified USB cable

I took apart the dummy camera and removed the battery holder. Leave the leads on the LED, as they will be reconnected to raspberry pi. Drill two holes in the metal plate to which the battery holder was fixed. The holes must line up with the mounting holes of the RPI. Make sure to leave enough space for the SD card which faces the fake lens. In the holes, I mounted M3 brass hex spacers to attach the RPI to the board with m3 screws.

I made connectors to the leads of the LED and attached them directly to the 3.3V and ground on the GPIO of the Raspberry. I cut a hole in the fake lens and taped the Raspi cam with double sided tape behind the hole. It is not a problem that the camera is mounted upside down, because in the software you can flip the image 180 degrees.

The result can be seen in the images below.

Raspberry Pi with camera mounted on base plate

Raspberry Pi with camera mounted on base plate

Raspberry Pi with camera mounted on base plate

Raspberry Pi with camera mounted on base plate

 

There is quite a bit of space in the dummy camera to fit everything in.

View inside the camera housing

View inside the camera housing

I made a separate short network cable that goes through housing. Just screw the housing together and the hardware is ready.

 raspi cam apart raspi cam finished

But……before you put everything inside the housing, you want to be sure that the software is properly setup.

The steps I took to get the software up and running:

Perform the Raspberry Pi basic setup

install the lastest version of Raspbian Wheezy

connect via SSH (user: pi password: raspberry)

then update all OS files and firmware

sudo apt-get update

sudo apt-get dist-upgrade

sudo rpi-update

sudo reboot

sudo raspi-config

and make the following config changes

– expand the file system

– enable the camera

– enable ssh

– set time-zone

sudo reboot

From this point onwards is where the additional software is installed:

Installing motion software

sudo apt-get install motion

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

Download the necessary Pi Cam driver

wget https://www.dropbox.com/s/pl9sqpwwotm8eak/motion-mmal.tar.gz

or use the mirror on google drive (in case dropbox has suspended my account again):

wget https://drive.google.com/uc?export=download&id=0B92GGEMLt5yZQkZXa2JyWFRvUGM

Download the configuration file with my preset configuration

wget https://www.dropbox.com/s/smubr3qtsbs2c2n/motion.conf

or use the mirror on google drive (in case dropbox has suspended my account again):

wget https://drive.google.com/uc?export=download&id=0B92GGEMLt5yZWktxSVVVek9DTlU

Unpack and move the downloaded files

tar zxvf motion-mmal.tar.gz

sudo mv motion /usr/bin/motion

sudo mv motion.conf /etc/motion.conf

Turn on motion deamon by default

sudo nano /etc/default/motion

and make the following change

start_motion_daemon=yes

ctrl-x, Y and enter to save

create necessary folder for storing the files and set the appropriate access rights

sudo chmod 664 /etc/motion.conf

sudo chmod 755 /usr/bin/motion

sudo touch /tmp/motion.log

sudo chmod 775 /tmp/motion.log

cd /home/pi

mkdir motion

sudo su

chmod 777 motion

The montion.conf that I included in this instruction works out of the box. In case you want to modify the motion.conf you can type:

sudo nano /etc/motion.conf

the major changes that I made:

deamon on

logfile /tmp/motion.log

rotate 180 (necessary as I mounted the camera upside down)

width 1280

height 720

framerate 10

threshold 0 (effectively turns of motion detection, as I just want the stream & the snapshots every minute)

ffmpeg_video_codec msmpeg4 (necessary to stream to windows based pc’s)

snapshot_interval 60 (every minute one snapshot)

text_left CAMERA %t (CAMERA can be any name you like and will appear on the image)

The following commands create file locations: a folder per day, per camera, per capture type. File names show camera #, image number, date & time

snapshot_filename %Y%m%d/camera-%t/snapshots/camera-%t-%v-%Y%m%d%H%M%S

picture_filename %Y%m%d/camera-%t/motions/camera-%t-%v-%Y%m%d%H%M%S-%q

movie_filename %Y%m%d/camera-%t/movies/camera-%t-%v-%Y%m%d%H%M%S-movie

timelapse_filename %Y%m%d/camera-%t/timelapses/camera-%t-%Y%m%d-timelapse

stream_port 8081

stream_localhost off

ctrl-x, Y and enter to save

You have to restart motion in order to apply the changes

sudo /etc/init.d/motion restart

Adding network access

Last step is to add netatalk for easy access to the images via Mac OSx finder, Windows users should consider installing Samba or mount a NAS / network drive on the Raspberry Pi as described here.

sudo apt-get install netatalk

sudo reboot

The video stream is directly visible via the Safari browser:

http://IP-ADDRESS-OF-RASPBERRY:8081

If you want to access the snapshots via Finder, in the SHARED section of Finder you will find the RASPBERRY. Connect to your RASPBERRY using user:pi password:raspberry.  After that you can browse the folders like any other. The images are roughly 100kB each.

Enjoy!

Advertisements