/rpicam

Raspberry PI Surveillance Automation

Primary LanguageShell

Automated Raspberry PI Camera Surveillance Setup

cam The picture above is my setup with an RPI 3 with camera and nightvision added. It's in a (relativly) water proof box and has a small fan to circulate the air inside the box to lower the temperature about 10 degrees celcius.

About

This is a Ansible scripted automated setup of an Raspberry PI with an attached camera.

After running the script the raspberry will have the surveillance software "motion" running with cronjobs and scripts setup to make it run after reboot. It will record files as avi and save to the tmpfs mounted directory /home/pi/Dropbox/<rpi_hostname>.

The reason for saving recordings to a tmpfs filesystem is that the memory card will otherwise be trashed after a while with too many read/writes.

The dropbox_uploader script is used to upload the files to Dropbox since there is currently no Dropbox client for ARM. Hence, an Dropbox app is required that will receive the files. It will end up in a path such as "Dropbox/Apps/<app_name>/".

There will also be a cronjob installed that removes recordings after 7 days from the raspberry.

When an alarm is triggered an email will be sent (in this case using gmail through postfix) with an snapshot from the recorded movie to the specified email address including recorded timestamp and from which host.

Alarm Email Example

Subject: rpi_cam2: Motion detection
ALERT: Motion detection(2017-08-24 07:56:08), CAMERA: rpi_cam2
Image Preview

Prerequisites

  • Raspberry PI (v3 tested) with an camera attached to the camera slot.
  • Host with ansible 1.2+ installed.
  • Raspian installed on the memory card.
  • To make Dropbox upload work, create an application in Dropbox.
  • Enable SSH on the raspberry (raspi-config -> interface -> enable ssh)
  • Enable Camera on the raspberry (raspi-config -> interface -> enable Camera)
  • Copy SSH key to the raspberry (default password is "raspberry" in the raspian image, please do change!) (see below)
  • TP-cable to connect raspberry with first time (before wifi is setup through the ansible script)

Commands

# Write raspian image to disk
$ sudo dd bs=1m if=<unzipped_image>.img of=/dev/<sd_card_disk> conv=sync
# Copy ssh key
$ ssh-copy-id pi@<ip>
# Enable camera and ssh
$ sudo raspi-config

Configure

Configure all settings in configure_me.yml. This is the main configuration file for settings such as email, dropbox upload etc.

Hosts are configured one per line in hosts file. Only thing to specify here is IP and preferred hostname.

Usage

ansible-playbook playbook.yml

The script will finish by rebooting the raspberry. The motion software will be running inside a screen and you can watch the process with 'screen -r motion' logged in as user 'pi'.

You will also be able to live view the camera using the credentials you configured in configure_me.yml.

http://<ip>:8080/

NOTE

This has only been tested on Raspberry PI 3. Should be working with at least v2 as well (otherwise adjust RAM for tmpfs).