I am completely against IP cameras that send video out to the cloud and then back to the end user. I am also against cloud storage that I cannot set up myself or evaluate the security on. If you want to get hot and heavy into file encryption, I will eventually add another post about how to encrypt the files on public clouds. I tend to error on the side of ACLs rather than encryption in the cloud because the security footage should also be remotely accessible to the owner. The path I intend on using for the camera footage is pi zero w --> motion detection server --> my cloud storage. The added benefit of this setup is that using an RTSP feed from the camera to the motion detection server allows the feed to be viewed on other devices, such as an Amazon Echo Show or a Fire TV. Some security will need to be added and skills will need to be configured to allow the Amazon connectivity.
This will be broken into a few posts, since we need to establish the camera hub and cameras prior to building out the skills. This project will require a Raspberry Pi 3 to be used as the hub, and we will connect it over ethernet rather than wifi. This way multiple feeds can be collected, schedules can be set, and all motion can be sent from a central location to cloud storage. Another feature that can be added is a microphone. For the new and expecting parents out there, you should look at the LIFX+ light bulb with IR. With the NoIR cameras for the raspberry pi and a microphone, you can build the equivalent of a high dollar baby monitor system for about 100$, and each additional viewing angle in the room is only going to be the cost of a pi zero kit, camera, and microphone.
Part 1: Hub and Camera Setup
The hub software is MotionEye OS. It is built for single board computers, and works exceptionally well. The types of tuning and tweaking are minimal, but you will want to be able to see the DHCP logs of your router to connect after install. I am not using a camera on the hub, so all processing power is being used to render the network camera feeds. For each network camera, I am using Raspbian Stretch lite. A little warning about the cameras, there are no cases for the cameras with IR lights included and attached. For any specialty camera that you decide to buy you should build or buy a case, or deal with having a system that looks like a small pile of e-waste. Most pi zero cases have room for the heat sink or regular pi camera, but not both.
Small Pile of E-waste
Hub BOM
1. Raspberry Pi 3 - $35
2. Power supply - $7.50
3. 32GB High speed micro SD card - $20
4. Pi Case - $2.00
You can get this as a kit for $70 on Amazon with a couple of bonus parts. An HDMI cable, USB Micro SD reader/writer, and heat sinks. Since this is a headless server, the HDMI is completely unnecessary.
Camera BOM
1. Raspberry Pi Zero W - $10
2. Power supply - $7.50
3. Case - $6
4. Micro SD card - $10
5. Camera - $15
The SD card speed is not a very high priority for the cameras, since they will be streaming live data. The top 4 items can usually be purchased as a kit for a few dollars less.
Build the Hub
The software for the hub has a very simple process to install and configure. Use your favorite software to get the OS image onto the microSD, install it into the pi 3, and boot it up. We are using hard-wired ethernet, so it doesn't matter where it goes in your house, as long as it is plugged into power and network.
Aggregate 1
MotionEye OS
Once the system is up, check the DHCP tables of your router to see what address was leased to the device. You can also dig around on the client list for a motioneye device. Connect through the browser and log in. There should not be much to configure until we build the camera.
Build the Camera
Depending on the case purchased, most of the pieces should snap together fairly easily. I ended up having to break mine down because the top of the case was curved. This led me to believe that the camera was not properly secured, and I pushed it until the ribbon connector directly below the camera disconnected. It led to some fun with checking the pi to camera ribbon about 20 times with a shutdown every 5 minutes to retest. Keep that little connector in mind if you need to troubleshoot.
Check This Connector
This is a typical raspbian install. Add the wpa_supplicant file, touch ssh on the boot partition, go through the raspi-config to change hostname and enable the camera module. To start software things off, update the OS and reboot if necessary. Next up is where things got a little dated for the main blog I used for my build. I work with RHEL professionally, so the whole "install from source using sudo" thing is a little strange to me. You will want to install Live555, and once that is installed, the RTSP server can be installed, and the service configured. The funny thing is that the RTSP install guide references and downloads files from the same location as the Live555 guide.
Aggregate 2
Live555 install instructions are near the bottom
Aggregate 3
V4L2RTSPServer Install and configuration
Once installed, you may want to change some things around. For example, the service should be in /lib/systemd/system/ with a symlink at /etc/systemd/system. I tend to install extra software in /opt (because I'm not a savage), the service will need to point to the correct location of the v4lrtspserver binary. If you installed in /opt, that will be /opt/v4l2rtspserver/v4l2rtspserver. You can also modify the service to work a little better and faster, but the limitations on a pi zero can dictate a few of the changes. I've noticed that changing the framerate (-F at line 11) to 20 is decent, and works well on VLC for testing. I also tend to be a little realistic about what I'm trying to do with the camera, and change the resolution to a lower format. You can probably stream a 30 frame 1080p video, but I've found 20 frame 1280x768 is considerably faster to load. Once you have finished with the service config file, start it up with: "sudo systemctl start v4l2rtspserver" and verify that it works with: "sudo systemctl status v4l2rtspserver" . Enable the service on boot with: "sudo systemctl enable v4l2rtspserver.service" .
Camera in case with SD card for scale
Add the Camera to the Hub
Testing the camera prior to adding it to the hub can be helpful. If you have a computer with VLC installed, open a network stream to rtsp://camera-IP- address:8554/unicast and verify that you get video. A quick warning: stop the feed and end the VLC application prior to setting up the camera on the hub. The port can get locked up on certain builds of the VLC application.
Open the Hub web console and use the drop down menu to add a camera. Select Network Camera in the menu and add the same rtsp address from the VLC test. There should not be any username or password requirement at this stage. Finish adding the camera and verify video is displaying. From within the General Settings menu, turn on advanced settings. This will allow you to change the Timezone and Hostname for the Hub. Expect a refresh or reboot every time you want to save changes.
You can disable whichever services you do not need. I don't really have any Windows systems, so I can shut down Samba without too much concern. The OS is fairly customized, so SSH isn't incredibly helpful either. In the Video Device settings, change the Resolution and Frame Rate to match what you entered into the rtsp service. The stream should speed up once you apply these settings. Further in the menu you can set up the retention of files, the schedule for the cameras, and the file storage (including cloud and custom locations). The options inside of File Storage are the most interesting, since you can have the hub message you if it captures motion and save images/video to a cloud location. These are the high dollar features on most consumer grade security cameras.
Multiple Cameras
For a quick setup and configuration of multiple cameras, you just have to configure one camera. Once you have built your working model, clone the image. I keep a backup of my completed image locally and on my cloud storage. Once you rip it to a new microSD card, just run raspi-config on the new camera to give it a different hostname. Don't forget to change the wpa configuration to a passphrase when you are done.
Aggregate 4
Backup and Restore Pi Image
Aggregate 5
WPA Passphrase Instructions
The next steps after all cameras are configured, fine tuned, and operational is to add TLS so you can reach them remotely if you choose to. Adding TLS to the stream and configuring the skills to view the feed from Amazon FireTV and Echo Show will be covered in the next blog, Pi Zero W Security Cameras Part 2: TLS and Amazon Skills