Skip to content

KPI Screen with a Raspberry PI and Google Data Studio

Websites and all interactions on them can be measured very well. But what do you do with all the collected data? Maybe someone asks for a nice report once a quarter, but after that the report will be quickly forgotten again. How would it be to display the most important key figures on a screen that every employee passes by every day? This can even be achieved with very little effort and cost.

Take the following ingredients:

  • Rasperry Pi
  • A screen (really any one) with HDMI connection
  • Mouse and keyboard
  • Time switch (optional)

Depending on the screen, you can realize the whole thing under 100 €.

Configuration of the Rasperry Pi

First you should install the operating system Raspbian. Then it continues with a first update:

sudo apt-get update && sudo apt-get upgrade

As a basic we need a directory for the automatic start:

mkdir /home/pi/.config/autostart/

In the script we also need two small programs named xdotool and unclutter, so we can execute the following in the terminal:

sudo apt-get install xdotool unclutter

xdotool is a program to execute keyboard commands in the terminal. Unclutter ensures that the mouse pointer is not displayed. All necessary programs are now installed.

Configuration of the automatic login

The Raspberry should be automatically logged in as user “Pi” by default. For safety you can check this with sudo nano /etc/lightdm/lightdm.conf to the terminal. There should be the following:

[SeatDefaults]
autologin-user=pi

Now the script to be built right away also has to be saved when booting the Raspberry Pi. In the terminal we give nano /home/pi/.config/autostart/kiosk.desktop and there the automatic start of the script is set:

[Desktop Entry]
Type=Application
Name=Kiosk
Exec=/home/pi/kiosk.sh
X-GNOME-Autostart-enabled=true

Configuration of the kiosk.sh script

Finally we get to the real script. This is called automatically as soon as the Raspberry starts. In the terminal we give nano /home/pi/kiosk.sh and there the automatic start of the script is deposited:

#!/bin/bash

# Run this script in display 0 - the monitor

export DISPLAY=:0

# Hide the mouse from the display

unclutter &

# If Chrome crashes (usually due to rebooting), clear the crash flag so we don't have the annoying warning bar

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences

sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences

# Run Chromium and DataStudio report, both with a shared URL

/usr/bin/chromium-browser --window-size=1366,768 --kiosk --window-position=0,0 --disable-overlay-scrollbar --noerrdialogs &

# Start the kiosk loop. This keystroke changes the Chromium tab

# To have just anti-idle, use this line instead:

# xdotool keydown ctrl; xdotool keyup ctrl;

# Otherwise, the ctrl+Tab is designed to switch tabs in Chrome

# #

done

This script is used to start Chromium

The script must become a real executable program: chmod +x kiosk.sh

Extensions

Now the start page is defined, in Chromium the DataStudio Report is defined as default.

So chrome://settings/?search=Beim+Start and put a page of the report there:

https://datastudio.google.com/u/0/reporting/1hSOTY3Ea_fMmdylPu5ZVxow4-YkvCDYK/page/KgJb

Install Chromium Extension

In order to display all pages of the report, we need this plugin that automatically switches pages. In addition, you can specify a time period during which the report will be updated. Just open Chromium and open the following URL: https://chrome.google.com/webstore/detail/data-studio-auto-refresh/inkgahcdacjcejipadnndepfllmbgoag

Automatic system shutdown

To allow the screen to take a break at night, the Rasperry is shut down. The following command shuts down the Rasperry at 7:15 pm: sudo nano /etc/crontab

15 19 * * * root shutdown -h now

And then set the timer. At 8:30 pm the power can be cut and in the morning at 7 o’clock the power can be switched on again. Then the Rasperry will start up again.

Restart for missing Internet connection

Sometimes it can happen that the Internet connection is not established properly. Therefore, it makes sense to run your own script to check the connection. The script is created for this purpose: nano /home/pi/checkwifi.sh

ping -c4 google.com > /dev/null
if [ $? != 0 ] 
then
sudo /sbin/shutdown -r now
fi

The script must still be executable chmod +x checkwifi.sh and included in the autostart.

Reload pages automatically

Currently the script starts only once a day, the pages are not updated anymore. Sometimes it can be quite useful to update the page more regularly. There is a new script for this: nano /home/pi/reloade.sh

#!/bin/bash
#
# refresh time in seconds so 3600 = every 60 min

  sleep 3600

  xdotools key = ”ctrl+F5” &

Now this script must become executable chmod +x reloade.sh and let this script load at startup as well

4 thoughts on “KPI Screen with a Raspberry PI and Google Data Studio”

      1. Thanks Eric,

        I tested it, and it works indeed. I only would like the fucntionality of auto forward to the next page.
        In a bash script I have put some xdotools commands, that works. The only problem is, it does not automatically returns to the first page after the last page. So the last step is a page refresh, but this is not a great solution.
        For Chrome there is an extension, Data Studio Refresh, but that one can’t work with Chromium.

        Do you have any ideas what could be solid solution?

        Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

en_GBEnglish