Web kiosk application with Raspberry-pi

Raspberry PI – Photo by Jeff Loucks on Unsplash

tl;dr – install basic raspberry-pi + optimize rw + full web app on launch + maintenance (shutdown – reboot).

Note: I did everything from within a linux computer with the user: sbw

This note is to keep track of all the step I went through to make a kiosk application on the raspberry-pi.

Headless raspberry pi setup with ssh & wifi and every IO intensive in memory to prevent SDCard multiple read write

Of course the first step is to install the raspbian OS and this is well documented everywhere, however as this could serve as a step by step guide, I’ll keep track of all the steps anyway.

If you have played a lot with the raspberry pi, one issue people often come through is the SD card lifetime that could go wrong, sometimes after only a few days. The main issue there is the log files that are written on the SD card. While this can be necessary for this case I’ll choose not to have them on the SD card to improve it’s lifetime.

Finally I’ll focus on the kiosk web application in a recent and decent browser.

But let start with the installation.

Install the raspbian OS on an SD card

In Terminal

sbw@sbw-pc:~/temp/$ wget https://downloads.raspberrypi.org/raspbian_latest
sbw@sbw-pc:~/temp/$ unzip -p raspbian_latest | sudo dd of=/dev/mmcblk0 bs=4M conv=fsync
sbw@sbw-pc:~/temp/$ rm raspbian_latest
sbw@sbw-pc:~/temp/$ sync

Don’t unmount we will have to add some stuff to win some time later on.

Source: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md

On the boot partition activate the ssh + wifi directly.

To enable ssh it’s quite easy, simply add an empty ssh file on the boot partition

sbw@sbw-pc:~/temp/$ touch /media/sbw/boot/ssh

Note that here my user is sbw, you may have a different user on your personal computer.

The next step is to configure the wifi

First of all you need your wifi SSID + Passphrase, for the purpose of the document I’ll have the following SSID & Passphrase: MY_HOME_WIFI – letmeinplease2019

sbw@sbw-pc:~/temp/$ wpa_passphrase MY_HOME_WIFI
> reading passphrase from stdin
> network={

You’ll want to remove the non hashed passphrase (#psk= »letme…) line from the config before storing it on the raspberry pi.

Let’s create the file that will store the network connection information.

sbw@sbw-pc:~/temp/$ vim /media/sbw/boot/wpa_supplicant.conf

And fill it with all we need for the first boot.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

Don’t forget to write and quit (with vim ESC :wq + enter). We will end up with a raspberry pi with ssh and wifi ready.

Sources: https://hackernoon.com/raspberry-pi-headless-install-462ccabd75d0; https://desertbot.io/blog/headless-raspberry-pi-3-bplus-ssh-wifi-setup; https://raspberrypi.stackexchange.com/questions/10251/prepare-sd-card-for-wifi-on-headless-pi

It’s time to unmount and to test.

sbw@sbw-pc:~/temp/$ umount /dev/mmcblk0p1

You’ll need your raspberry-pi ip address ( for this fake case), the easiest way for me was to get it from the router.

sbw@sbw-pc:~/temp/$ ssh pi@
> pi@'s password: 
pi@raspberrypi:~ $ 

raspberry is the default password for the raspberry user.

Let change it asap with something much more complex.

pi@raspberrypi:~ $ passwd
Changing password for pi.
Current password: 
New password: 
Retype new password: 
passwd: password updated successfully

Ideally put your public ssh key in the ~/.ssh/allowed file.

pi@raspberrypi:~ $ mkdir .ssh
pi@raspberrypi:~ $ vim .ssh/authorized_keys

And copy paste your public key.

Now let’s try it: logoff and logon, it should use your ssh keys from now on.

Ok, so we have SSH + Wifi … great!

Now the real business start, first of all remove the logs from the SD card.

Remove the swap and log to ram instead of SD

We need to think about the SD lifetime. Get rid of all the SD access to ensure that the SD will live long and prosper.

To remove the swap (and avoir SD card issue) simply deactivate then remove the swap service.

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove

Then we will create a temporary in memory /var/log.

To do this, simply add the following line in /etc/fstab

none        /var/log        tmpfs   size=1M,noatime         00

And after the reboot you should see something like:

pi@raspberrypi:/var/log $ mount
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
none on /var/log type tmpfs (rw,noatime,size=1024k)

Note that the /run and /run/lock are already in tmpfs volatile RAM file system

Sources: https://github.com/azlux/log2ram; https://raspberrypi.stackexchange.com/questions/62533/how-can-i-reduce-the-writing-to-log-files; https://mcuoneclipse.com/2019/04/01/log2ram-extending-sd-card-lifetime-for-raspberry-pi-lorawan-gateway/; http://ideaheap.com/2013/07/stopping-sd-card-corruption-on-a-raspberry-pi/

Now it’s time to boot in full screen

First of all install the very lastpackage.

sudo apt-get install -y ttf-mscorefonts-installer unclutter x11-xserver-utils

Setting locales

While we are at it, we can directly change the locale to reflect the country & language issues.

sudo vim /etc/locale.gen

Uncomment the one that match your need and then run

sudo locale-gen

Update: ssh and wifi could be done inside raspbian_latest.img

check where the boot partition start with parted

parted raspbian_latest.img
WARNING: You are not superuser.  Watch out for permissions.
GNU Parted 3.3
Using /home/sbw/Downloads/raspbian_latest.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) u
Unit?  [compact]? B                                                       
(parted) print                                                             
Model:  (file)
Disk /home/sbw/Downloads/raspbian_latest.img: 1866465280B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start       End          Size         Type     File system  Flags
 1      4194304B    272629759B   268435456B   primary  fat32        lba
 2      272629760B  1866465279B  1593835520B  primary  ext4

(parted) q Code language: PHP (php)

Note the Start of the fat32 boot partition:

<span class="has-inline-color has-primary-color"><em><strong>4194304</strong></em></span>BCode language: HTML, XML (xml)

And use it to create a temporary local mount of the image before copying it to the SDCard

sudo mount -o loop,offset=<span class="has-inline-color has-primary-color"><em><strong>4194304</strong></em></span> raspbian_latest.img /media/sbw/kano/Code language: HTML, XML (xml)

now putting the file ssh & wpa_supplicant.conf is even easier

touch /media/sbw/kano/ssh
vim /media/sbw/kano/wpa_supplicant.conf

Then the copy to the SDCard

sudo dd if=/home/sbw/Downloads/raspbian_latest.img of=/dev/mmcblk0 bs=4M conv=fsyncCode language: JavaScript (javascript)

Inspiration: https://blog.gordonturner.com/2017/12/10/raspberry-pi-full-screen-browser-raspbian-december-2017/


Leave a comment

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *