Building a Secure and Customizable Raspberry Pi Security Camera: A Comprehensive Guide

Building a Secure and Customizable Raspberry Pi Security Camera: A Comprehensive Guide

Aug 22, 2024

Raspberry Pi Security Camera

Using a Raspberry Pi for a security camera offers several advantages making it an affordable surveillance solution for home or small business.

The Raspberry Pi is cost-effective, allowing you to build a fully functional security system without the high price tag associated with commercial options DVR/NVR systems. Its flexibility and customizability mean you can tailor the setup to your specific needs, whether you want to use multiple cameras, integrate motion detection, or connect it to other smart home devices. Additionally, the wide range of software options, such as MotionEyeOS or the `motion` software on Raspberry Pi OS, allows for easy setup and management, giving you control over features like streaming, recording, and alerts.

We can choose to store video footage locally on an SD card, external hard drive, or network-attached storage (NAS), ensuring that your data remains under your control. Also, we can integrate cloud storage solutions like Google Drive, Dropbox, or custom servers for remote access and backup.

Implementation Raspberry Pi Security Camera

图片2.png__PID:4ffbdfa6-6d48-4503-a8f5-39a3282c3b86

Components

Raspberry Pi (any model with a camera interface, e.g., Raspberry Pi 3, 4 or Zero W)
https://github.com/motioneye-project/motioneyeos/wiki/Supported-Devices
● Raspberry Pi Camera Module v2.1 (or a USB webcam)
● MicroSD Card (with at least 16GB storage, pre-installed with MotionEyeOS)
● External USB Hard Drive (with a least 500GB for video storage)
● High Quality Power Supply 5v

Steps to Set Up the Raspberry Pi Security Camera

1. Install Raspberry Pi Imager to a computer with an SD card reader. Put the SD card that you will use with your Raspberry Pi into the reader and launch Raspberry Pi Imager.
2. Select the Raspberry Pi 4 as Device
3. Choose OS and select Use Custom. Browse the MotionEyesOS image and flash the Raspberry Pi 4

图片3.png__PID:5503a8f5-39a3-482c-bb86-238761d7f5fb

4. Complete your custom setting (WiFi Setttings)
5. Put SD Card in Raspberry PI and power on.

MotionEye on Raspberry Pi

This is an online interface of the software motion, a video surveillance application with motion sensor.

图片4.png__PID:8761d7f5-fbb7-4189-bb1d-edb546b3d745

Features

Easy and friendly user interface for internet verses, mobile and tablets.
● It supports most USB cameras and also is compatible with Raspberry PI camera modules.
● Here we find support for IP cameras (network).
● Camera detection with alerts via email and functional days.
For still images using the JPEG format and for videos using AVI format.
● Timelapse movies
● It worked with your local Area Network through the use of ethernet cables or through wireless connections.
● File storing to the device ‘s local SD card, USB drive or SMB share of the local network
● Sharing of videos and pictures on social platforms (Facebook, Instagram), storing of files in cloud services such as Google drive and Dropbox.
● By default, media files are accessible in the local network as SMB shares.
● Media files can also be managed with the help of FTP server which is already installed in PIM, or SFTP server

Installation

1.Install Python dependencies
sudo apt install python3-dev libcurl4-openssl-dev libssl-dev

2.Install PIP Python Manager
sudo apt install python3-pip

3.Download MotionEYE
sudo pip3 install 'https://github.com/motioneye-project/motioneye/archive/dev.tar.gz' --break-system-packages

4.Init installation script
sudo motioneye_init

5.Install libcamera package
sudo apt install libcamera-v4l2

6.Open a web browser on any device in the network and Access
 http://raspberry_pi_IP:8765 Login: admin Password: (empty)

图片5.png__PID:d7458d2e-72d4-442a-afb4-ad0bb1edda4a

Configuration

1.Add a Camera

图片6.png__PID:e42a6fb4-ad0b-41ed-9a4a-fee37b58316f

Select "Local V4L2 Camera" if you are using the Raspberry Pi Camera Module or a USB webcam. Configure the camera settings as needed.

图片7.png__PID:6fb4ad0b-b1ed-4a4a-bee3-7b58316f8885

2.Set Up Motion Detection
Go to the Motion Detection tab:

图片8.png__PID:b1edda4a-fee3-4b58-b16f-8885075e7c62

Enable motion detection and configure the sensitivity, detection zones, and other preferences.

3.Configure Storage
Go to the File Storage tab.

图片9.png__PID:fee37b58-316f-4885-875e-7c627764dc33

Set up the directory where we want to store recorded videos and images.
We ou can also configure cloud storage options like Google Drive or Dropbox.

图片11.png__PID:8885075e-7c62-4764-9c33-054b9987ecab

4.Secure MotionEye
The default port is 8765 used by MotionEye for its web interface. If this port is accessible from the internet without proper security measures (like HTTPS and strong passwords), our camera system could be vulnerable.

● Setting up a VPN allows you to access the Raspberry Pi remotely without exposing ports directly to the internet. This is one of the most secure methods for remote access.

● Change the admin password by going to General Settings > User Accounts.

图片12.png__PID:dc33054b-9987-4cab-ab86-86ca1cfe8b09

● Consider changing the default ports used by MotionEye to non-standard ones, making it harder for potential attackers to find our service.

Alternative Installation - MotionEyesOS

MotionEyeOS is a Linux distribution that allows one to convert the single board computer into a surveillance system.

1.Download and install Raspberry Pi Imager to a computer with an SD card reader. Put the SD card that you will use with your Raspberry Pi into the reader and launch Raspberry Pi Imager.
2.Download the last stable versión (v.20200606) of MotionEyesOS https://github.com/motioneye-project/motioneyeos/releases
3.Select the Raspberry Pi Device.
4.Choose a Use Custom image and flash your Raspberry Pi.

图片13.png__PID:1cfe8b09-b5b0-4381-b7fc-e411b4fa032b

5.Put SD Card in Raspberry PI and power on.
6.Continue with previous Configuration

Additional Configurations

Set up notifications via email or webhooks. Configure the system to send alerts when motion is detected.

图片14.png__PID:b7fce411-b4fa-432b-b994-d606c9de403f

Troubleshooting

Cannot Access the MotionEye Web Interface
We can't reach the MotionEye web interface at http://raspberry_pi_IP:8765.

1.Run the following command to see if the service is running:
sudo systemctl status motioneye

If it's not running, try restarting it:
sudo systemctl restart motioneye

2.If you have a firewall enabled, ensure that port 8765 is open:
sudo ufw allow 8765/tcp

Camera Not Detected or No Video Feed
1.Ensure that the camera module or USB webcam is properly connected. For the Raspberry Pi Camera Module, double-check the ribbon cable is seated correctly in the CSI slot.

2.Test the Camera:
Use the raspistill command to take a test photo:
raspistill -o test.jpg
If this doesn’t work, the camera may not be properly connected or could be faulty.

3.Verify Camera Interface is Enabled:
Ensure the camera interface is enabled in raspi-config:
sudo raspi-config
Go to Interfacing Options > Camera and make sure it's enabled.


Low Performance or High CPU Usage
Reducing the camera resolution or frame rate can significantly reduce CPU usage. Adjust these settings in the MotionEye interface under Video Device.

Storage Issues (e.g., Not Enough Space or Cannot Save Videos)
Configure MotionEye to automatically delete old files after a certain period or when storage space is low.
Go to Videos Section and set the Movies Lifetime, example: 15 days

图片16.png__PID:5a9cd366-b55a-43f1-acc8-be0761b65cca

Official MotionEye Documentation: https://github.com/motioneye-project/motioneye

Raspberry Pi Update: Essential Steps for a Secure and Optimized System Back to News How to Set Up and Optimize a Raspberry Pi Minecraft Server: A Comprehensive Guide