We looked at the motionEyeOS last week and
I was not too happy with the quality of the
video due to its low resolution and frame
rate. So today, we are going to start with
a mini-series that will teach you how to build
your own home surveillance system, mainly
using raspberry PIs. In this video, we will
configure a raspberry Pi zero to act like
an IP camera. It will stream video over a
network, using RTSP and we will view this
on a remote device. So let’s dive in.
Let’s start with the components that we
need. We would need a raspberry PI zero W,
a microSD card for the operating system. A
camera module, a cable to connect the camera
module to the pi zero and finally, we need
a suitable power source for the pi zero. You
will also need a way to connect the microSD
card to your computer and you can use a USB
card reader like this one. I’ve selected
the PI zero here because it is compact and
much cheaper than the other boards but you
can also use any other board version.
Before we can do anything, we need to download
a suitable operating system for the raspberry
PI. Head over to the raspberry pi website,
the downloads section, Raspbian and then download
the lite version of the OS. Wait for it to
complete. The lite version is the minimal
version of the Raspbian image which means
that there is less software installed on it
and it lacks the main user interface.
The next step is to download this image to
the microSD card, and for that, we will be
using etcher. So download and install it to
your system. Then, use the card reader to
connect the microSD card to your computer.
Open etcher, select the image you just downloaded,
make sure you have selected the microSD card
and then hit the flash button. Wait for it
to complete.
Before we use the microSD card to boot the
raspberry pi, we need to do two things. First,
we need to provide our network credentials,
so that the board can connect to our WiFi
network. To do this, you need to place a file
with a particular name and contents to the
boot drive. It is recommended to use a text
editing application like notepad++ or sublime
to create or edit this file. I will be using
sublime. Also, you can download the template
file from the project page and update it with
your details. You will need to update the
country code, network name and password. Once
done, simply copy this to the boot drive.
The next thing we need to do is enable something
called Secure Shell or SSH. Doing this allows
us to control the raspberry pi zero over the
network, and this is sometimes called a headless
setup. If you do not enable SSH, then you
will have to connect a keyboard and monitor
to access the terminal interface, which will
allow you to control the raspberry pi. Enabling
SSH is extremely simple. Simply create a new
file using a text editor and then save it
to the boot drive with the name ssh. You don’t
need to add any extension to the file. Once
done, eject the microSD card and insert it
into the raspberry pi.
Before we power it ON, let’s connect the
camera module. To do this, simply slide the
connector tab gently and insert the cable.
Be careful with the connector tabs as they
are delicate and can break easily. Once done,
plug in the microUSB cable and power ON the
board. The board will take about a minute
to boot completely so do give it sometime.
In order to communicate with the board, we
need to obtain it’s IP address. To do this,
download and install angryIP scanner. You
can use the legacy version which is old, but
does not require any installation. Enter the
IP address range like so, hit the start button
and wait for it to detect the board. Once
it shows up, you can stop the scan and keep
a note of the IP address. Next, we need to
open up the command prompt and to do this,
simply open up the start menu and type in
cmd. Then type ssh pi@ whatever IP address
was shown earlier. type in yes and then hit
enter. It will ask you for a password and
the default is raspberry, so type that in
and press enter. You have successfully logged
into the raspberry pi and you can now control
it remotely.
We need to execute a few commands in order
to get everything up and running. We will
quickly walk over the steps in this video,
and you can use either of the written posts
to obtain the commands – these will be available
on instructables, hackster and our own website.
In summary, here’s what we will be doing:
We will be creating an RTSP video stream that
will acquire video from the raspberry pi camera.
To do this, we will use raspivid to create
a stream and then use vlc to make this available
over the network. In order to configure the
stream, we will need to create a script. We
will then first run this script manually to
make sure everything is working as it should.
We will then configure the script to run on
startup as that way, the raspberry pi will
boot and activate the stream for us every
time it is powered ON. All this sounds much
more complicated than it actually is, so let’s
just get it done.
The first thing we need to do is enable the
camera. This is done by running the raspi-config
tool. We navigate to the camera option and
enable it. You will have to reboot the board
so select yes and wait for it to reboot. We
then ssh back into the board like before.
Then, we need to check for any updates and
upgrade the operating system as this is a
new installation. Even though this step takes
a bit of time, it is recommended that you
do this before installing any software. Raspivid
is already installed by default, so we simply
need to install VLC. We then create a script
file and configure the stream. You can update
the resolution, frame rate and bit rate to
suit your requirements and there is documentation
available for this online. We then execute
the script to check if it is working as expected.
In order to view the stream, we will be using
VLC on our computer. So download and install
that if you do not already have it. Then open
up the network option from the file menu and
enter the following URL. Remember to use the
IP address corresponding to your raspberry
pi. Open the stream and you will be able to
view the camera output. It’s easy to tell
that the video is of a much higher quality
compared to the previous version and also
compared to the ESP32-CAM projects. You can
even lower the resolution and adjust the bitrate
by updating the script file to suit your requirements.
Remember that the final video quality will
also depend on your WiFi network so make sure
you have good WiFi coverage.
Before we automate the script, let’s check
the load on the CPU and memory. We can do
this by opening up a new command prompt window,
logging into the board and then running the
top command. As can be seen, CPU usage is
around 20-25% and memory usage is below 15
%. This is at full HD, that’s 1080p video
at 30 frames per second. The bitrate was set
to 2Mbps but you can update this as needed.
What this means is that there is a lot more
headroom for us to use here. And since this
is a custom implementation, we do not sacrifice
any functionality compared to using the motioneyeOS.
We can even run other scripts to make this
more than just an IP camera.
Now that we know that the stream works, we
simply need to configure it to run on startup.
There are many ways to do this but we will
be using the systemd startup script method.
For that, we simply create a service and then
enable it. You can manually start, stop or
view the status of this service as needed
but once it is enabled, it will automatically
run after the board boots up. So let’s reboot
the board and test this. Give the board a
minute to power ON. Then, open up VLC to check
the stream and it should work as before.
And that’s how you can use the Raspberry
pi zero as a simple, wireless, IP camera.
If this is the first time you are using the
raspberry pi, then running the scripts might
feel a little tricky but it’s also a very
good learning experience. In the next video
in this series, we will look at creating an
NVR to view and store the videos from multiple
cameras. There will be a separate playlist
for this so that you can follow along later.
And that’s it for this video. Don’t forget
to like, share and subscribe if you haven’t
already. Thank you for watching, and I will
see you in the next one.
