Poor-Man’s Raspberry Pi Web based Digital Signage


Written by

There’s lots of Raspberry Pi Digital Signage software suites available but most of them expect you to pay or are really out-dated.

This is a short guide on how to setup a small fleet of Raspberry Pis (Although most of the content applies to any Linux based system).

Simple Steps:

  • Image your System – Raspberry Pi OS or Other Linux.
  • Make sure your system displays correctly on your screen.
  • Install Chromium or Google-Chrome.
  • Run Chrome in Kiosk Mode.
  • Restart Chrome every x minutes.
  • Physically install your screen and pi.

I intend to run multiple systems to display different information signs with some of the systems being out of reach so they needed to be fairly robust stand-alone setup; if I wanted to change the content being displayed, then I needed a way to reconfigure this without having to re-image the raspberry pi or remove the signs.

The Signage Script

The signage bash script will try to detect the system mac address of the two possible system interfaces on a Raspberry Pi (feel free to add/edit these). The start url loads the web server php scripts below to allow changing of content at a later date. It will also detect google-chrome or chromium on the system and use which ever it finds.

The script runs in a loop, showing the web page for 30minutes (can be configured to anything else) and then restarts the browser; this means if there is an issue with network connectivity then you dont need to restart the entire system, it will be back in 30minutes or less.

#!/bin/bash
#
# Horrible Digital Signage Startup Script
# 2021 - Adam Boutcher - aboutcher.co.uk
#

STARTURL="http://my-server/tv/manager.php"
REFRESH=30 #Minutes
INTERFACES=(eth0 wlan0)

# Function to check that a binary exists
function check_bin() {
  which $1 1>/dev/null 2>&1
  if [[ $? -ne 0 ]]; then
    echo "$1 cannot be found. Please install it or add it to the path. Exiting."
    exit 1
  fi
}

check_bin which
check_bin cat
check_bin awk
check_bin sleep
check_bin kill
check_bin echo
check_bin ethtool

# Looping through listed interfaces
for INT in ${INTERFACES[@]}; do
  if [[ $(cat /sys/class/net/$INT/operstate 2>/dev/null) == "up" ]]; then
    MAC=$(/usr/sbin/ethtool -P $INT | awk '{print $3}');
    break
  fi
done

if [ -z $MAC ]; then
  echo "No MAC address found"
  exit 1
fi

echo 
echo Poor-Mans Digital Signage
echo Adam Boutcher - www.aboutcher.co.uk
echo 
echo System MAC: $MAC
echo Starting URL: $STARTURL
echo Refresh in: $REFRESH Minutes

BROWSERS=("google-chrome" "chromium")
for BROWSER in ${BROWSERS[@]}; do
  which $BROWSER >/dev/null 2>&1
  if [ $? -eq 0 ]; then
    echo Found Browser: $BROWSER
    break;
  fi
done;

while true; do
  echo 
  $BROWSER --new-window --kiosk --ingognito $STARTURL?mac=$MAC >/dev/null 2>&1 &
  if [ -z $WEBPID ]; then
    WEBPID=$!
    echo "First Start"
  else
    NEWPID=$!
    sleep 0.5
    kill -9 $WEBPID 2>/dev/null
    WEBPID=$NEWPID
  fi
  echo Running on PID: $WEBPID
  echo "Sleeping..."
  sleep $((REFRESH*60))
  echo "Restarting"
done

The Web Server Script

This a simple php logic script to redirect the system to your actual web content. This means that upon restart of the web browser, it will re-check this web server script for its content location.

<?php

// This array is key = mac, dest = value
$CLIENTS = array (
                "dc:a6:32:zz:yy:xx" => "https://example.com",
                "dc:a6:32:xy:zx:yz" => "https://aboutcher.co.uk",
        );
if ( isset($CLIENTS[$_GET['mac']]) ) {
  header("HTTP/1.1 302 Found");
  header('Location: '.$CLIENTS[$_GET['mac']]);
} else {
  echo "System not recognised.<br/>";
  if ( !empty($_GET['mac']) ) {
    echo $_GET['mac'];
  } else {
    echo "No mac";
  }
}

?>

Raspberry Pi Auto Start:

Save this file in /home/pi/.config/autostart/signage.desktop

[Desktop Entry]
Type=Application
Name=Digital Signage
Exec=/home/pi/digitalsignage.sh

Raspberry Pi Tweaks:

You can disable screen blanking in the Raspberry Pi Configuration GUI as well as enable auto-gui and auto-login.

I would also recommend disabling SSH and VNC if remote access isn’t required; you can also enable the filesystem to be read-only which should save the SD card’s life span.

Save the signage script into /home/pi/digitalsignage.sh and then add the autostart script to /home/pi/.config/autostart/signage.desktop, you might need to make the autostart directory.

The raspberry pi is a nice simple solution as they’re easy to get hold of and has a large community to help you get things perfect, there’s also nice features for display rotation and a host of ways to add hacks, so for instance you could add temperature probes and display the temperature results locally.