Intro: Budget CCTV With Android and Rpi
This project is for an expandable CCTV system that you may be able to build out of things you have lying around space.
If you are have a RaspberryPi 2 or an old laptop spare then I recommend that you look at using zoneminder. Zoneminder is a bit much for the original RaspberryPi so here's a simple alternative if you are using an original RaspberryPi.
For this project you will need.
- Old android phone (any smartphone is probably usable)
You may need:
- Usb pen drive
- Command 3m sticky pads
Install the IP Webcam app on your phone.
Set IP Webcam to start on boot.
Click on start server to make sure that IP Webcam is working.
Stick your phone where it has a good view of whatever it is that you want to keep an eye on. I'm using 3M command sticky pads but use whatever works for you.
You'll probably want to leave your phone plugged into a charger as well.
Install your OS of choice on your Raspberry, I'm using Raspbian.
Copy the cctv.py and cameras.conf files to the home directory of your Raspberry.
Make sure that you edit the cameras.conf file to replace:
with the actual ip address of your camera as shown in IP Webcam.
The cameras.conf file allows you to specify the cameras in your CCTV network and should be kept in the same folder as cctv.py.
The cctv.py program can be configured to work with most network cameras, the parameters are as follows:
- rootpath - This controls where the imagery from the cameras will be saved.
- url - This should be set to whatever URL will return an image from the camera, in the case of IP Webcam this will be in the format http://[IP ADDRESS]/shot.jpg
- every - This controls how often the program will try to save an image from the camera, this is measured in seconds. By default images will be saved at 20fps.
- keep - How long to keep the images, this is measured in days. By default images will be saved for 31 days.
- username and password - This feature only works if both parameters are set but should be used when the camera is password protected.
- filetype - The image type that is returned by the camera, in the case of IP Webcam these are jpgs. By default jpg is assumed.
Look in example_cameras.conf for an example of how to configure multiple cameras.
Depeding on the number of cameras, how often you save an image and how long you want to keep the images you may need a significant amount of storage space to save the images.
Your results may vary but in my experience, 1 camera at 3fps for 31 days is approximately 15GB of space. I strongly recommend plugging a suitably sized USB pen drive into your RPi and setting the rootpath parameter to save on the pendrive instead.
Now that you've configued your cameras.conf file it's time to set your RPi to run the CCTV program automatically.
Open your crontab by typing:
into your terminal and add the following line to the end:
@reboot cd /home/pi && python3 cctv.py
save your crontab and reboot your RPi.
If everything is set up correctly then the folder your specified in your cameras.conf file will start to fill up with images from your camera. The images will be deleted after 31 days or whatever you specified using the keep parameter in your cameras.conf file.
The final step is to try and hide your RPi or at leave leave it somewhere unobtrusive.