wiki:RaspberryPiSurveillanceMonitor

I have 2 FOSCAM HD IP camera and 1 UBNT airVision (old model) IP camera which are used for surveillance monitoring. Storage of images is done on the camera's itself, so I only needed something to view the live feeds of the camera's combined an a single screen. I had an old HDMI screen laying around and the Raspberry Pi 3 is yet the perfect (inexpesive fit) for this purpose.

Getting started

Install the standard debian Raspberry Pi and make sure to select console mode. We do need any GUI, since we will be using omxplayer to display the camera feeds. Also find out your RTSP streaming URLs.

Display camera images

I use the daemontools framework, since it provides me with logging, monitoring, restarting out-of-the-box. I also like the way his way of thinking, to avoid reinventing the wheel everytime you need to write an deamon.

file:/etc/motd:

WWW: http://rickvanderzwet.nl - webcampi @ rustdam

/etc/service/camera1 	=	Hooiberg (via 'Rustdam Stal') - Main View
/etc/service/camera2	=	Receptie (via wired and proxied on rustdam2.gw) - Left bottom
/etc/service/camera3	=	Stal	(wireless connected to rustdam.wleiden.net - rdr at rustdam2.gw) 

file:/etc/service/camera1/run:

#!/bin/sh
exec 2>&1
exec omxplayer --threshold 0 --win 0,0,1280,720 --live 'rtsp://USER:PASSWORD@IP:PORT/videoMain'

file:/etc/service/camera2/run:

#!/bin/sh
exec 2>&1
exec omxplayer --threshold 0 --win 739,720,1280,1024 --layer 10 --live 'rtsp://USER:PASSWORD@IP:PORT/videoMain'

file:/etc/service/camera3/run:

#!/bin/sh
exec 2>&1
exec omxplayer --threshold 0 --win 0,720,540,1024 --layer 10 --live 'rtsp://USER:PASSWORD@IP:PORT/videoMain'

Monitoring of camera feeds

file:/root/kill_stuck_omxplayer.sh:

#!/bin/sh
#
# Quick to deal with omxplayers which are in deadloop,
# detection based on low-CPU usage
#
for PID in `pgrep omxplayer.bin`; do
  PCPU=`ps -p $PID -o pcpu=`
  if echo $PCPU 2.0 | awk '{exit $1<$2?0:1}'; then
    echo "Lets kill pid $PID"
    kill -KILL $PID
  fi
done

file:/etc/crontab:

*  *    * * *   root    /root/kill_stuck_omxplayer.sh | logger

Rsyslog issues

My log was flooding with messages like this:

Jun  5 10:08:31 raspberrypi rsyslogd-2007: action 'action 17' suspended, next retry is Mon Jun  5 10:10:01 2017 [try http://www.rsyslog.com/e/2007 ]

Looking at the RaspberryPi Forum it was caused by messages not being read from file:/dev/xconsole To fix this edit file:/etc/rsyslog.conf and comment out the block sending the entries:

daemon.*;mail.*;\
        news.err;\
        *.=debug;*.=info;\
        *.=notice;*.=warn       |/dev/xconsole

Remote monitoring of screen output

For debugging I remotely need to be able to look at the screen to see what is displayed. This is done by using raspi2png to grep the output of the display and present then using Apache.

Compile and install raspi2png

$ mkdir src; cd src $ git clone https://github.com/AndrewFromMelbourne/raspi2png.git $ cd raspi2png $ sudo make install

Install webserver

$ sudo apt-get install apache2 $ sudo chown -R pi:pi /var/www/html

Generate display content

file:/var/www/html:

<html>
<head>
 <meta charset="UTF-8"> 
 <meta http-equiv="refresh" content="10">
</head>

<body>
<img src="snapshot.png" width="100%" height="100%">
</body>
</html>

Include screen capture

file:/etc/crontab:

*	*	*	*	*	pi /usr/bin/raspi2png -p /var/www/html/snapshot.png 2>&1 | logger -t raspi2png

Result

Open your browser and look at http://raspberrypi/

Last modified 8 years ago Last modified on Jun 5, 2017, 8:26:35 AM
Note: See TracWiki for help on using the wiki.