A person working on a cellphone, representing the raspberry pi blog post.
Building Rock-Solid Dashboards With a Raspberry Pi
A person working on a cellphone, representing the raspberry pi blog post.

Building Rock-Solid Dashboards With a Raspberry Pi

When away from the everlasting quest of crafting software you don’t want to punch in the face, Ronan, Senior Backend Developer at Unito, builds dashboards. Nobody knows why. Maybe compensating for never having owned a car and smiling over bringing to life the dimly-lit orange dashboard of an old Civic? Maybe he fancies pretty colorful lines? Who knows! We’d ask him, but he left for a run.

So, you built a glorious dashboard, proudly running on a happy Raspberry Pi tacked to the back of the office TV. Great! Orrrr… is it? See, there are a few potential problems with that setup:

  • What’s going to happen when it inevitably crashes and restarts?
  • Aren’t you going to be annoyed by stuff showing up on top of your nice dashboard? Like browser update prompts or the mouse cursor?
  • Did you know that an always-on dashboard will kill your SD card in a matter of weeks?
  • Isn’t your dashboard, running by itself all night, a little sad?

This post will guide you through “hardening” your Raspberry Pi dashboard, so that it stays running basically forever. It’s been refined and battle-tested through years of continued use at Unito, and we dare say it’s extremely stable. So here it is!

Caveat: software changes over time. In a few months or years, the precise steps highlighted in this guide will inevitably be outdated. But the high-level goals and suggestions will remain! Even with out-of-date precise steps, this guide should keep its main merit: to inform you about various shenanigans, letting you monkey around and find a solution working with the $software_du_jour 🙂.

First: Order, assembly, installation

Before we go into the dashboard itself, let’s cover acquiring your Raspberry Pi and making sure it’s ready to go.

  1. Order a Pi! Always get as much RAM as you can. The web eats RAM at breakfast, lunch, dinner, and for snacks too. Order the “Starter Kit.” It has everything you need.
  2. Assemble: shove the SD card in the reader, stick the fans on, put the Pi the case, plug it into a power source and a screen. Here’s the full guide on doing that.
  3. Install Raspbian: Download the “desktop” edition. The more bloated “desktop and recommended software” edition is unnecessary for a dashboard. The only important installation-time configurations are Keyboard and WiFi. All the rest can stay at defaults.

Basic configuration

In Menu → Preferences → Raspberry Pi Configuration:

  • Tab “System”: Hostname = pi{dev,sales,...}. Having an easy-to-remember name will enable the next point…
  • Tab “Interfaces”: Enable VNC. This will let you perform remote maintenance, using RealVNC Viewer.

And you should perform an initial upgrade. In a terminal, run:

sudo apt update && sudo apt remove -y apt-listchanges && sudo apt full-upgrade -y && sudo apt install -y fonts-noto-color-emoji xdotool && sudo apt autoremove -y && sudo apt autoclean

Note: we install emojis if needed in dashboards, and xdotool for later purposes.

Hardening dashboards and mitigating shenanigans 

Okay, time for the meat of this guide. If you just stop here and simply open Chromium at your dashboard page, you’ll be happy today, but probably sad tomorrow.

Accidents can and will happen with time, your Pi will reboot, displaying a sad empty desktop, and demanding your time to fix it. If that happens enough times, it might lead to an abandoned dashboard 😕.

Shenanigan #1: force resolution to your TV native resolution

Doing maintenance over VNC from a high-res “Retina” screen will cause your dashboard to automatically switch resolution, making it unreadable or maybe stop displaying at all on your office TV.

Solution? You should force the resolution to the native resolution of your TV (e.g. 1080p):

sudo raspi-config , then Display OptionsResolution1920x1080x60Hz.

Shenanigan #2: don’t let excessive writes kill your SD card

SD cards have a limited number of write cycles, especially the cheap ones you get with a Pi.

An ever-running dashboard will cause tons of writes. Early dashboards at Unito grilled several SD cards in a few months.

To fix this, limit writes as much as possible. You can configure this manually, but an easy turnkey solution for this is to install the excellent log2ram.

Shenanigan #3: limit web bloat

Pis are great little machines, but they’re also not super beefy for heavy web dashboards.

Analytics and tracking code commonly used by webapps adds extra weight and unnecessary noise to your dashboard, like user satisfaction surveys or support widgets. The fix?

In Chromium, install uBlock Origin, and activate all its lists to block analytics & tracking resource-consuming bloat

Shenanigan #4: TV settings

Set TV settings for power savings, but not a full power off, so that no turning on is necessary in the morning.

Shenanigan #5: automate morning / evening routine

We want our Pi to be maximally stateless, and perform consistently through years of use. So, we’re going to make it perform specific tasks automatically every morning, evening, and everytime it boots.

We’re not going to hope for stability. We assume things will crash and behave unexpectedly, and we force the Pi to do what must be done without human intervention.

→ Declare two cron scheduler jobs to perform start/end of day tasks (e.g. 7AM – 7PM, Monday to Friday). Launch crontab -e , and add:

0   19  *   *   1-5 /home/pi/routine-du-soir

0   7   *   *   1-5 /home/pi/routine-du-matin

→ Declare a startup script: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart and add at the end:

@/home/pi/routine-du-boot

Write the morning script below to /home/pi/routine-du-matin (don’t forget to make it executable!):

#!/usr/bin/env sh

# A daily upgrade is good hygiene. Yes it's safe, Raspbian sits on top of Debian,

# which is very conservative / stable. Your Pi will *not* be toasted by an upgrade.

sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt autoclean

# A daily restart mitigates browser memory leaks, and forces the screen to turn on

sudo reboot now

Write the evening script below to /home/pi/routine-du-soir (don’t forget to make it executable!):

#!/usr/bin/env sh

# Shutdown screen, to save the planet

DISPLAY=:0 xset dpms force off

# Don't consume dashboard resources off office hours, to save the planet

pkill chromium

Write the boot script below to /home/pi/routine-du-matin (don’t forget to make it executable!):

#!/usr/bin/env sh

# Disable screensaver. Varies across Pi models & Raspbian versions; might be outdated.

# Google "raspberry disable suspend screensaver" for help

xset s off

xset -dpms

xset s noblank

# Move the mouse cursor out of the way!

xdotool mousemove 0 0

# Avoid "Chrome didn't shutdown correctly" notification on unclean shutdown

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State'

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences

# Start Chromium, in fullscreen "kiosk" mode, and disabling update notifications

chromium-browser --kiosk --check-for-update-interval=31536000 'https://your-dashboard-url.com'

And that’s it! Reboot and enjoy a rock-solid dashboard you can trust. Was that helpful? Do you have any extra useful tidbits to suggest?

As a final note, the good, lazy developers among you might shout“Why isn’t this automated?! Gimme a bash script! An Ansible book ”! Fair, but the answer is that we don’t set up new dashboards everyday here at Unito, and when we do there’s usually a bit of tweaking to do anyway. Thus, we intentionally did not automate these steps. But maybe you can! Tell us if you do, and also tell us what you added!