Building a Raspberry pi kiosk

One thing many people want to achieve with a Raspberry Pi is a functioning simple web kiosk. Combined with a touchscreen, it could potentially replace ATM machines. Yes, it’s high time we switched to low cost, secure ATM kiosks based on easily available commodity hardware. ATM machines and Kiosks mostly run a Windows XP (!?) on a machine that’s configured to launch only one application and in the event the application crashes, the system shuts down and sends an alert to the bank staff. This can easily be done with a Raspberry Pi. The system should have no problem delivering the complete set of functionality, should be fairly easy to deploy, maintain and secure on a large scale and hey, Raspberry Pi is so tiny, we’ll be spoilt for space inside the ATM machine. (More cash, Yay!). I’m not even going to elaborate on the savings on electricity (go figure!).

RPi awesomeness
By Chris Sheppard on Flickr

The idea of this exercise is simple. You start the system and you get dumped onto a web browser with a specific site loaded. That’s it. Nothing more, nothing less. If the web browser crashes, the system attempts to restart the browser or dies trying >:D

We also need this kiosk thing to be gentle on system resources. So we’ll use lightweight (albeit effective and powerful) applications. The ingredient list is as follows:

  1. Auto Log-in: nodm
  2. Auto X start: we use a simple .xsession file
  3. Window Manager: We’ll be using the full awesomeness of matchbox
  4. Browser: uzbl. Haven’t heard of it? You should totally check it out.
  5. Splash screen: fbi. Yea I know how that sounds. 😛

Let’s see how to set each one of these babies up

Logging in automatically:

This is optional. You can have a simple username/password prompt or nothing at all. But we’ll discuss automatically logging in without username and password. For this, we need nodm, which is a tool that does just that.

sudo apt-get install nodm -y

Now we need to start nodm at boot and configure the user that nodm will log in as. Edit /etc/default/nodm file

NODM_ENABLED=true
NODM_USER=pi

It’s all self explanatory. First one says enable nodm at boot. Second one says log in as ‘pi’ user. Simple enough.

Installing the Window Manager

Window managers, well, manage windows. They take care of size, positioning and tiling of window objects on the screen. We’ll be using matchbox to get our kiosk web browser to open in a full screen window.

sudo apt-get install -y matchbox-window-manager

This will install the Matchbox window manager, which is a specialized window manager written for resource restricted hardware like – you guessed it – Raspberry Pi. It’s fast, it’s lightweight, it’s effective and it does its job without complaining. Perfect.

Installing the Web Browser

The most important part of the kiosk is the web browser. It makes our kiosk, a kiosk. And we are going to load only a single website. Therefore it’s wise to stick to something lightweight. Chromium-browser and Firefox are overkills for this kind of job since they devour a ton of system resources. Hence we use a browser called uzbl ( pronounced “usable”. Naming skills, yea? ). This little beast is very versatile and extremely configurable. It is also super lightweight and very forgiving towards system resources. So let’s install it:

sudo apt-get -y install uzbl

Putting it all together

Now we need to make sure 1. The system boots and pi user logs in automatically (we’ve done that already), 2. The Window manager starts and 3. The web browser starts in full screen. We’ll be using an xsession file to do that.

Note: You must have xinit installed. If not, install it

sudo apt-get -y install xinit

Create a new file ‘.xsession’ in the home directory /home/pi. That’s .xsession with a dot in the beginning (A hidden file in the UNIX world). Put the following content in it.

#!/bin/bash
uzbl -u http://google.com/ -c /home/pi/uzbl.conf &
exec matchbox-window-manager  -use_titlebar no

That’s it. Save and close the file. What we have done is to start the uzbl browser during boot along with the Matchbox window-manager. The u stands for uri and the c stands for configuration file. uzbl  uses the configuration file to lookup settings and apply them to itself. We are now going to create a configuration file to try and force uzbl to do two things 1. Not display it’s status bar and 2. Open in a maximized window.

Go ahead and create /home/pi/uzbl.conf and put the following content in it:

set show_status=0
set geometry=maximized

Save it and close it. If you need help with uzbl, check this out: https://wiki.archlinux.org/index.php/UZBL-Browser

To make the browser restart automatically if it crashes (it shouldn’t), put this in the .xsession file:

#!/bin/bash
while true; do
  uzbl -u http://google.com/ -c /home/pi/uzbl.conf &;
  exec matchbox-window-manager  -use_titlebar no;
  sleep 2s;
done

The -use_titlebar no part is to make Matchbox window manager hide the titlebar.

Reboot and check if everything is working as it should. If you get stuck in the terminal, you’ve messed up with the .xsession file. Recheck it. Type ‘startx‘ to start the X Window to see if it works.

Splash screen

How can it be complete without a splash screen? So get a nice splash screen image – preferably in PNG fomat – and put it under /etc/ directory. Let’s call it mycoolimage.png. Then install fbi

sudo apt-get install -y fbi

Fbi is a FrameBuffer Image viewer. Basically it’s something that let’s you view images even before the nuts and bolts of the operating system that enables you to view images are actually loaded. So it’s kindofacoolthing. Now create a new file called ‘aaa‘ under /etc/init.d directory as root. (use sudo) We want it to begin with ‘a‘ so that it can load early on (no kidding). Put the following content in it.

#! /bin/sh

do_start () {
    /usr/bin/fbi -T 1 -noverbose -a /etc/mycoolimage.png    
    exit 0
}

case "$1" in
  start)
    do_start
    ;;
  restart|reload|force-reload)
    echo "You can't do that" >&2
    exit 3No-op
    ;;
  stop)
    # Nothing here. Move on.
    ;;
  status)
    exit 0
    ;;
  *)
    echo "Script to show splash screen " >&2
    exit 3
    ;;
esac

:

Make the file executable and make the system recognize it as an init script

sudo chmod a+x /etc/init.d/aaa
sudo insserv /etc/init.d/aaa

We’re done. Check everything and reboot. Does it work? Sweet!

 Bonus tips: You can get rid of the crazy log tsunami that you get when you load the Pi for the first time. You can also make the fruit disappear. (Fruit lovers, please forgive). Open /boot/cmdline.txt and do the following changes: (without the quotes of course)

  1. Locate the section that says “console=tty1″ and make it “console=tty“. This pushes the logs to the fourth virtual terminal

  2. Add a space in the end and add “loglevel=3“. This sets the severity of the logging level to “warning and above”.

  3. Add a space in the end of the line and add “logo.nologo“. That’s logonologo that – you guessed it – hides the little raspberry fruit logo.

  4. Set the following directives in the file /etc/kbd/config (This prevents the screen from going to sleep)

BLANK_TIME=0
POWERDOWN_TIME=0

Neat, isn’t it?

Advertisements

2 thoughts on “Building a Raspberry pi kiosk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s