Skip to content

Instantly share code, notes, and snippets.

@cliffrowley
Last active November 8, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffrowley/b7e8db878acc7a6c0b0eb6f41bad177c to your computer and use it in GitHub Desktop.
Save cliffrowley/b7e8db878acc7a6c0b0eb6f41bad177c to your computer and use it in GitHub Desktop.
A Raspberry Pi Desktop Baby Monitor

My Raspberry Pi Desktop Baby Monitor

With the arrival of our little one, I wanted a way to be able to monitor him in his crib while I'm at my desk. I already have a Raspberry Pi with its own 7" monitor and figured I'd put it to work (the Pi, not the baby :P).

Notes

My Pi sits on my desk with a minature keyboard and trackpad nearby, but usually they are stowed away as I access it remotely from my laptop. I also have some commands hooked into Siri so I can start and stop the monitor via voice commands.

This setup assumes that like me, you will also want to start and stop the monitor via some external mechanism. If you keep a keyboard and mouse plugged into your Pi and use it as a desktop, you may just as well skip this setup and simply run VLC with the URL of your camera's RTSP stream.

Prerequisites

You will need:

  • A Raspberry Pi running Raspbian.
  • A monitor of some description.
  • An RTSP capable IP camera.

The camera

If you don't already have an IP camera and are considering buying one please do your research thoroughly as they aren't all created equal and some are really quite poor. For my first attempt I tried a cheap Ebitcam Mini, but within a minute or two of being active it would overheat and drop off the wifi.

You don't need to spend a lot of money though, as even some of the entry level cameras are actually quite good. I'm currently using a Foscam C2 which has been exemplary so far, even after hours of usage at a time.

Whatever you buy, make sure it has RTSP support because it makes everything so much easier. It's also required for this particular setup.

The Raspberry Pi

I have a 4GB Pi 4 model B but that's fairly overkill for this, but I also use it for other things. I suspect you could get away most most models; maybe even a Pi Zero, but I don't have one to test with.

Essentially you only need to be able to run X11 and VLC and to keep it cool enough to operate for long periods.

Setting up

I'll assume that you already have your Pi and its monitor set up, and have got your IP camera connected to your local network. I'll also assume that you are able to access your Pi via SSH from another device.

Start/Stop script

Create a new file at /home/pi/bin/ipcam (you may need to create the bin directory) and add the following to it:

#!/bin/bash

VLC_URL="rtsp://your_cam_stream_url"
VLC_ARGS=""

case $1 in
start)
  export DISPLAY=:0

  /sbin/start-stop-daemon \
    --start \
    --background \
    --pidfile $HOME/.ipcam.pid \
    --make-pidfile \
    --exec /usr/bin/vlc \
    -- $VLC_ARGS --fullscreen $VLC_URL
  ;;
stop)
  /sbin/start-stop-daemon \
    --stop \
    --pidfile $HOME/.ipcam.pid
;;
esac

Change the VLC_URL variable to the RTSP stream of your camera, which you should be able to determine from its documentation.

Then run chmod +x /home/pi/bin/ipcam, and you should be able to run ipcam start and ipcam stop to start and stop the monitor (you may need to restart your terminal or log out and in again via SSH).

Optional: Setting VLC options

The VLC_ARGS variable allows you to tweak some of VLC's options depending on your requirements.

For example, in my case when VLC ran full screen it stopped outputting to my monitor, so I added --mmal-display hdmi-2 to fix it.

Also I found that the audio from my Pi was at such a low level that I couldn't hear it without turning my speakers almost all the way up, so I added --volume 300 --compressor-rms-peak 0.5 --gain 8.0 --alsa-gain 8.0 --equalizer-preamp 10.0 to compensate.

Optional: Running on startup

If you want your monitor to run when the Pi starts up, create a new file at /home/pi/.autostart and add the following to it:

#!/bin/bash

ipcam start

And then run chmod +x /home/pi/.autostart.

Then edit /etc/xdg/lxsession/LXDE-pi/autostart and add the following line at the end:

@sh /home/pi/.autostart

Future enhancements

There are a few things I'm not entirely happy with yet, and will probably do a fair bit of tweaking before I am. For example:

  • I'd like to be able to change the monitor volume via the touch screen.
  • I'd like to be able to also start and stop the monitor via the touch screen.
  • I'd like to be able to boost the audio output without distorting it in software.

I'm sure I'll get around to them. Maybe. Did I mention we have a new baby? xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment