Set up a Raspberry Pi to run Chromium in kiosk mode
credit: This section is mostly based on https://die-antwort.eu/techblog/2017-12-setup-raspberry-pi-for-kiosk-mode/ with some tweak to work with the auto-refresh section later.
First, start with a fresh install of Raspbian Lite - we don’t want all the bloat because we are only using the Raspberry Pi to display a dashboard
Then, we perform the usual Raspberry Pi setups, including things like updating password or enabling SSH.
sudo raspi-config, in “Boot Options”, Select
“Desktop / CLI” and then “Console Autologin”. We will auto-run
startx later in bash.
Now, install the dependencies - X server, a window manager (we use the lightweight openbox ), Chromium and NodeJS.
A quick note here about
apt - if you are running commands directly
in your terminal,
a much better experience
Edit /etc/xdg/openbox/autostart and replace its content with the following:
We disable screen blanking and power management which doesn’t make sense for our dashboard.
Next, we want to automatically start the X server on login. We can
.bash_profile to include this
Note that we have configure the Pi to log into command line above. Combining with this change it will cause the Pi to start an empty X session on boot.
Now that we are done, we will implement a service to (re)start Chromium on demand.
Create a service to (re)start Chromium
In my experience, running Chromium for a prolonged period of time usually results in the classic ‘aw snap’ crash. A solution here is to restart the browser from time to time, usually at night when the dashboard is not needed.
Also, to iterate changes on the dashboard, it’s better to have some mechanism to restart the browser without having to attach a keyboard to the dashboard display.
Lastly, when we push a new change to the Pi, it’s possible that new code changes can crash the dashboard page, so, we want a way to refresh that doesn’t rely on logics in the web page.
To achieve these, we can implement a service in node.js that provides an end point to restart the Chromium browser. In addition, we will launch Chromium in the ‘kiosk mode’:
The kiosk mode allows chromium to take over the whole screen with only the webpage and no frames or browsers UIs.
Here’s a simple, one-file service in TypeScript with minimum dependencies:
We use an HTTP server, but we can also use websocket or whatever else that’s convenient for the use case.
Lastly, we can set up a new service to make sure that this service
starts running when we reboot the Pi. To do so, we create a new systemd service.
Then, we make sure to start this service on boot:
Finally, to restart the sole chromium browser, your app or script can post