Watching your pets with a Raspberry Pi and a mesh VPN

Good Dog

Article from Issue 271/2023
Author(s):

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:

Figure 1: Installing the camera on a Raspberry Pi.
  1. Shut down your Raspberry Pi if it is already turned on.
  2. Lift (but don't try to detach) the plastic guard that's on top of the camera port.
  3. 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.
  4. 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.

Figure 2: By Default, Raspbian has the camera interface disabled, so don't forget to enable it in order to record video or take pictures.

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
Figure 3: Use an RTSP client (like the VLC media player or QuickTime) on your home computer to test the video from your Raspberry Pi.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • motionEyeOS

    Set up a professional video surveillance system armed with motionEyeOS and a Raspberry Pi.

  • PiCam Surveillance

    The new PiCam camera for the Raspberry Pi delivers image data with very little overhead, making it ideal for video surveillance applications. We find the bumps in the road you'll encounter and show you how to smooth them out with a few Linux commands and pipes.

  • A New Raspberry Pi Board

    The new board packs everything that you get in Raspberry Pi 3B+ in a smaller package.

  • Miniature Photography

    The combination of a web camera, Raspberry Pi, and simple software facilitates miniature tabletop photography.

  • Webcam Rescue

    If your new webcam doesn't work with the default software on your Linux system, try your luck with Guvcview or QtCAM.

comments powered by Disqus
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.

Learn More

News