Watching your pets with a Raspberry Pi and a mesh VPN
Good Dog
A Raspberry Pi, a Pi-compatible camera, and a mesh VPN are all you need to watch your pets from afar.
You have a pet, but you need to be away from home for a day. Is it really worth paying for a kennel when all you want is to keep an eye on your pet while you're away? Of course, you could use a video doorbell service (like Ring or Arlo) and simply locate the camera device inside your home, but it seems like overkill to pay for a monthly service for something that you only need occasionally. Also, for privacy reasons, some people might not want to invite a streaming video service into their home when they don't have control over how the video is processed and stored.
On the other hand, if you have a Raspberry Pi, an Internet connection, and a Pi-compatible camera, it is actually pretty simple to set up your own remote access pet cam with a mesh VPN. Years ago, in order to get something like this to work, you'd need to open a port on your home router/firewall and enable port forwarding in order to allow incoming connections. That's a risky undertaking, because you're opening the door for anyone who port scans your router to find an entrance to your home network. Thankfully, there are free services available that allow you to host your own VPN using your Internet connection at home.
Setting Up a Camera on Your Raspberry Pi
The first step is to set up a Pi-compatible camera for your Raspberry Pi. I say, "Pi-compatible" because there's no single camera model that works with the Raspberry Pi. Therefore, feel free to find any camera that works with your version of the Raspberry Pi and fits within your budget. I tested my setup with the Pi Camera Module 2 [1], which has an 8MP image sensor and only cost about $10 online. In case you've forgotten, the Raspberry Pi includes a dedicated camera port directly on the board that is used exclusively for any of the Pi-compatible cameras (Figure 1). Therefore, installing the camera is a four-step process:
- Shut down your Raspberry Pi if it is already turned on.
- Lift (but don't try to detach) the plastic guard that's on top of the camera port.
- Insert the ribbon cable for your Pi-compatible camera into the camera port, and ensure that the blue strip on the ribbon is facing towards the USB and Ethernet ports.
- Push down and close the plastic guard on the camera port to lock everything in place.
Now that you've got your camera installed, the next step is to ensure that your Raspberry Pi recognizes the camera. Go to Preferences | Raspberry Pi Configuration to access the Preferences Configuration screen for your Raspberry Pi.
Click on the Interfaces tab and make sure that you select the option that enables the camera (Figure 2). To save the settings, click the OK button, and then reboot your Raspberry Pi.
Taking a Still Photo
Now that you've gotten your camera installed and configured, you need to make sure that the drivers work properly and can recognize the camera. Therefore, take a simple still photo (no need to try out streaming video yet) to make sure that the camera is recognized by your Raspberry Pi. Execute the following command at the terminal:
$ raspistill -o petcam1.jpg
By default, the raspistill
utility waits for five seconds before taking a photo, so be sure to wait the appropriate time, and check your local directory to verify that the picture was taken.
Live Streaming on the Local Network
Now that you know the Pi is able to use the camera, the next steps are to use the camera in video mode, open a port on the network interface, and serve the video feed to anyone who knows the local IP address and port of your Raspberry Pi.
These steps require both the raspivid
command and the open source VLC media player. If you don't already have the VLC player installed on your Raspberry Pi, execute the following command to install it:
$ sudo apt install -y vlc
Next, create an 800x600 H264 video feed at 12 frames/sec and open port 3141 on the Raspberry Pi to serve the video as a livestream using the Real Time Streaming Protocol (RTSP) with:
raspivid -o - -t 0 -w 800 -h 600 -fps 12 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:3141/}' :demux=h264
You might be more familiar with common TCP-based protocols such as HTTP and FTP, but RTSP is an alternative protocol used exclusively for streaming video and audio [2]. Because web browsers don't support RTSP, you need to use video tools such as VLC or QuickTime in order to view an RTSP video stream. To view the video stream within your home network, you need to install an RTSP client on your desktop or laptop computer.
If you're using VLC, navigate to Media | Open Network Stream in order to open a dialog window that enables you to type in the IP address and port number for your video stream (Figure 3). The URL for the video stream must be in the following format:
rtsp://ip_address:port_number
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.