Create A Multi-Camera CCTV System With Raspberry Pi and motionEyeOS

DIY




While there are countless commercial CCTV home security systems on the market, building your own to DIY version with a Raspberry Pi (or other single-board computer) offers the advantage of customizability to suit your exact purposes.

A special Linux distro called motionEyeOS makes it easy to set up your security system with one or more cameras. It can then detect motion from the camera view and send alerts via email or push notification. We’ll show you how to get everything up and running.
What You Will Need to Set Up a CCTV System A Raspberry Pi: any model will work, including Pi Zero and Compute Module A USB webcam, Raspberry Pi Camera Module, or the High Quality Camera module
Related: Raspberry Pi, Pico, Arduino, and Other Single-board Computers and Microcontrollers
1. Install motionEyeOS
Rather than being an application, motionEyeOS is a self-contained operating system, one of many Raspberry Pi OSes. First, you need to find the correct version for your Raspberry Pi model. Go to the list of supported devices and click on the latest version for your board to download the disk image as a .xz file.

There are two main ways of installing motionEyeOS on Raspberry Pi. The motionEyeOS website offers an image-writing utility for Linux and macOS computers to write the disk image to a microSD card to use in your Raspberry Pi. This offers the optional setup of a wireless network connection and setting a static IP address. For more details, see the installation guide.

The second method – which we will use here, since it also works on Windows machines – is to write the disk image using the standard Raspberry Pi Imager tool, downloadable from the Raspberry Pi website.

Using a built-in card reader or USB adaptor, insert your microSD card to mount it on your computer and open Raspberry Pi Imager. Click on Choose OS, then scroll to the bottom of the list to select Use custom.

Browse to the motionEyeOS.xz file you downloaded earlier. Now click on Choose SD Card and select your inserted microSD card, probably called something like Generic Storage Device Media.

Finally, click on Write to write the image to the card.
2. Preconfigure Your Wireless Connection
Before using the microSD card in your Raspberry Pi, you will want to preconfigure the wireless network credentials.

Open a plain text editor (such as Text Editor on macOS or Notepad on Windows) and enter the following lines, replacing the ssid and psk values with the SSID (name) and password for your own wireless router. You should also change the country code to the one where the device will be operating.
country=US
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
scan_ssid=1
ssid="MyWiFiSSID"
psk="MyWiFiPassword"
}
Save the file as wpa_supplicant.conf to the root of your microSD card, where you should see other files such as bootcode.bin and kernel.img. If the file saves with a .txt suffix, remove that so it’s just called wpa_supplicant.conf.
3. Camera Setup
If you are using a Raspberry Pi Camera Module or High Quality Camera, connect it to the Raspberry Pi's Camera port. If using a webcam, connect to a USB port on the Raspberry Pi.

Insert the microSD card in your Raspberry Pi and power it up. If connected to a monitor, you will see a list of commands being run. Once your wpa_supplicant.conf file is successfully read, it will then connect to your network and show the Raspberry Pi’s IP address after Interface wlan0 has IP address:.

Alternatively, if your Raspberry Pi is not connected to a monitor, you could always discover the IP address by visiting your wireless router’s settings page in a web browser on another device and looking for a device with a name starting with meye-.
4. Access the Web Interface
In a web browser on another computer or device, enter the Raspberry Pi’s IP address and you should see a login screen. Just enter admin as the username, without a password.

If you have a Raspberry Pi Camera Module or High Quality Camera connected, it should be detected automatically and you’ll see the camera view from it in the web interface. If using a USB camera, in the Add Camera menu that appears, select Local V4L2 Camera for Camera Type, and USB2.0 Camera: USB2.0 Camera for Camera.

For a multi-camera setup, it’s possible to connect more than one camera to one Raspberry Pi, although the model used needs to be powerful enough to handle all the streams.

Alternatively, you can use multiple Raspberry Pi boards, each with a camera, and designate another Raspberry Pi as a hub to handle their streams. This is useful if you want to position cameras in different rooms.

There’s also the option of using a regular Linux computer as a central server.
5. Configure Custom Settings
In the web interface, click the three vertical lines icon at the top left to open up the settings panel. In the Preferences menu, change the Layout Columns option to 1 if using a single camera, so the view fills the screen.

The Video Device menu lets you change the resolution, rotation, and frame rate for the currently selected camera. You can also rename the camera to something descriptive, such as the room it’s in. After changing any menu settings, click the Apply button to apply them.

For your security camera setup, you will want to detect motion from the camera view. Open the Motion Detection menu and turn it to on. Other options enable you to set the Frame Change Threshold required to detect motion. Setting it too low may result in too many false positives. The Motion Gap option is the delay before seeking to detect motion again after it has been triggered.

To view movies captured from motion detection, click on a live camera view and then select the triangular play button icon. It’s also possible to view still images captured by the camera – either manually or by setting the Capture Mode in the Still Images menu to Motion Triggered.
7. Send Email Notifications
The Motion Notifications menu enables you to send yourself an email whenever motion is detected. After turning it on, enter the Email Address you want to send the notification to. You will need to enter the other settings for your account.

If using Gmail, set the SMTP Server to smtp.gmail.com, the SMTP Port to 587, and the SMTP Account to the first part of your email address (i.e. without @gmail.com). The SMTP Password is the one you use to log in to your Gmail account. The From Address can be left blank or set to a custom address. Set TLS to on.

In another browser tab, visit the Security menu for your Google account and set Less secure app access to on – after receiving a security alert, confirm that it was you who changed it. Note that this is done at your own risk. We set up a dedicated new Gmail account for this purpose.

You should now be able to send a Test Email from motionEyeOS without triggering a Google security alert. Note that if using multiple cameras, you need to set up email notifications for each one separately.

To receive an image with your email notification, you’re advised to set the Attached Pictures Time Span option to between 5 and 30. You also need to set Capture Mode to Motion Triggered in the Still Images menu.
8. Add Push Notifications
You can also send push notifications using the Run A Command option in the Motion Notifications menu. For instance, to use the Pushover service – which offers apps for Android, iOS, and desktop – you need to create a short Python script for it to run.

Sign up for Pushover. Keep in mind that after a 30-day free trial, you’ll need to make a one-off $5 in-app purchase to continue using it.

After that, click on Create an Application/API Token. Note down the API Token/Key given for it, along with your User Key from the dashboard.

Download: Pushover for iOS | Android (Free trial available)

Using the boilerplate code from the Pushover website, you can create your Python script:
import httplib, urllib
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": "abc123",
"user": "user123",
"title": "CCTV alert"
"message": "Motion detected on camera 1!",
"url": "http://IP.ADD.RE.SS",
"url_title": "View live stream",
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
Replace abc123 with your app’s API Token, and user123 with your User Key. Replace IP.ADD.RE.SS with your motionEyeOS setup’s IP address.

To place this on your motionEyeOS system, you need to SSH in from another computer using the Terminal application (or WinSCP on Windows), by entering:
ssh admin@&IP_ADDRESS
Replace IP_ADDRESS with the IP address of your motionEyeOS system. Now enter:
cd /data
Now you are in the data directory, create a new file called pushover.py:
nano pushover.py
Paste or type your Python script into it and save with Ctrl + X, followed by Y. Now make it executable with:
chmod +x pushover.py
Alternatively, in WinSCP on Windows, press F9, set the permissions to 0775, and press OK.

Test the script by running:
python pushover.py
You should receive a notification, with audible alert, from motionEyeOS in your Pushover app.

Back in the motionEyeOS web interface Motion Notifications menu, turn on the Run A Command option and type python /data/pushover.py into the Command field to tell it to run your Python script.

Click the Apply button. Note that you can apply a different Run A Command script for each camera in your setup, so you could create multiple Python scripts, each saying which camera has been detected motion.
Making Your Own DIY Security Camera System
Congratulations, you have now set up your own customisable CCTV security system using Raspberry Pi, complete with email and push notifications to alert you to the presence of any intruders detected on camera.
#DIY
DIY



Older Post Newer Post