1

I'm setting my Rasbery Pi up to run as a kisok mode, I know their are several guides on how to do this but before I attempt it I have a question.

All of the guides I have looked at require you to hard code in the URL. For the situation I am intending their will be 12 teams using their own Pi's, as well as this the URL is subject to change often for project changes/updates. In a ideal world the scrum masters could just amend this themselves...but they aren't remotely technical. The solution I would like is to have a text file on the desktop that they can just update when needed. Then on boot it would get the URL from this file.

I've been looking at this guide for kiosk https://github.com/elalemanyo/raspberry-pi-kiosk-screen

the line is

@chromium --noerrdialogs --kiosk [URL] 

I've tried several derivatives of passing the contents into a variable and then using that as the URL.

URL=$(</home/pi/Desktop/URL)
URL="$(cat /home/pi/Desktop/URL)"
URL='cat /home/pi/Desktop/URL'
@chromium --noerrdialogs --kiosk $URL

Above are a few of the ways I have tried. Anyone know a way of doing this?

Ghost

  • Took a trawl through the docs for that configuration method and I can't see anything that suggests you're allowed variables. How about using the autostart file to launch a bash or Python script to read the text file into Chromium's flags? – goobering Feb 24 '16 at 0:34
  • Yea if that would work, I don't mind how its done. Not sure how I would go about this though? – ghost3h Feb 24 '16 at 7:45
0

Similar approach to @patthoyts, but using Python rather than bash. Excuse my almost certainly sub-optimal Python.

import os
import urllib.request as req
import urllib.parse as p

#Construct the path to the text file containing your URL
url_path = os.path.join('/home/pi/myUrlFolder/myUrl.txt')

#Check if the path is valid
if os.path.exists(url_path):
    #File exists  
    #Open the file for reading
    my_url_file = open(url_path)
    #Read the file contents
    my_url = my_url_file.read()

    #Try to verify that URL is valid by making a request against it
    request = req.Request(my_url)
    try:
        response = req.urlopen(request)

        #File contained a valid URL so start Chromium
        chromium_cmd = 'chromium --noerrdialogs --user-data-dir --kiosk ' + my_url
        os.system(chromium_cmd)
    except:
        #File didn't contain a valid URL
        print ('Invalid URL. Please make sure your text file at ' + url_path + ' contains a valid URL.')

elif os.access(os.path.dirname(url_path), os.W_OK):
    #File doesn't exist but write privileges are given for our folder
    #Create an empty file at our path
    my_url_file = open(url_path)
    #Write a default URL into the empty file
    my_url_file.write('http://raspberrypi.stackexchange.com')
    my_url_file.close()
else:
    #File doesn't exist, can not write there
    print('No file found and folder is write protected. Please create a valid text file at ' + url_path)
  • Create the folder /home/pi/myUrlFolder (or alter the above Python to use a different one).
  • Create the file myUrl.txt in myUrlFolder.
  • Type your URL into myUrl.txt and save it.
  • For demo purposes I've just dumped my Python script in there as well. You may have a more sensible alternative. In any event, pick a folder and save the above code in there as startchromium.py
  • Use chmod +x startchromium.py to make it executable
  • Create/edit ~/.config/lxsession/LXDE-pi/autostart to include @/usr/bin/python3 /home/pi/myUrlFolder/startchromium.py
  • Reboot
  • If everything's gone according to plan there are only small fires and, hopefully, a running instance of Chromium.
1

I use a file that can be sourced into the kiosk script to set a variable. eg:

KIOSK_URL=http://machine/path/

Then in the launching script we set a default value then source the local configuration file in the same way the init scripts in /etc/init.d and /etc/default work.

#!/bin/bash
KIOSK_URL=http://machine/default
[ -r /etc/default/kiosk ] && . /etc/default/kiosk
/usr/bin/chromium --kiosk --incognito --start-maximized $KIOSK_URL

So that checks to see if the file exists and is readable then sources it into the current script which overrides the default variable value. If you want to stick with /home/pi/Desktop/URL then change /etc/default/kiosk but be aware the person editing the URL file can inject script commands in that case.

I actually use the following script as this allows the browser to be defined per-system as some of the kiosk displays we use have chromium, chromium-browser or ephiphany-browser. This allows a local configuration file to override the chromium default as we as select a specific url. This uses ratpoison to get a tiling window manager so that the browser is maximised and unclutter to remove the mouse pointer from the screen.

kiosk.sh

#!/bin/bash
#
# epiphany-browser is part of the Raspbian Jesse distribution but has less kiosk-friendly features
# than chromium. chromium uses slightly less CPU and memory for our Jenkins  status screens too
# but is unavailable for Raspbian Jesse at the moment.

# Create an /etc/default/kiosk file and declare the url there
KIOSK_URL=http://spd-jenkins/view/StatusCore/
KIOSK_BROWSER=/usr/bin/chromium
KIOSK_ARGS='%s --kiosk --incognito --start-maximized'

[ -r /etc/default/kiosk ] && . /etc/default/kiosk

BROWSER_NAME=$(basename $KIOSK_BROWSER)
KIOSK_PARAMS=$(printf "$KIOSK_ARGS" "$KIOSK_URL")

if [ -x /usr/bin/xset ]
then
  /usr/bin/xset s off
  /usr/bin/xset -dpms
fi

/usr/bin/ratpoison &
[ -x /usr/bin/unclutter ] && /usr/bin/unclutter &

if [ "$BROWSER_NAME" = "epiphany-browser" ]
then
  # Make it forget any previous tabs.
  [ -e "$HOME/.config/epiphany/session-state.xml" ] && rm -f "$HOME/.config/epiphany/session-state.xml"

  # Make the browser fullscreen by faking a F11 key after a suitable delay
  xte 'sleep 15' 'key F11' 2>&1 > /dev/null &
fi

$KIOSK_BROWSER $KIOSK_PARAMS

if [ -x /usr/bin/xset ]
then
  /usr/bin/xset s on
  /usr/bin/xset +dpms
fi

Enabling on startup

To arrange for the kiosk mode display to automatically launch on startup it needs to be added into the X Display Manager which on Raspbian is lightdm. The following lightdm configuration requires a /kiosk/ user account and automatically starts a session as the kiosk user using the session definition in the kiosk.desktop file. This file just calls the script provided above which runs a window manager (ratpoison) and the browser in kiosk mode.

lightdm.config

[LightDM]
minimum-vt=7
seats=seat-0

[GuestAccount]
enabled=false

[SeatDefaults]
pam-service=lightdm-autologin
autologin-user=kiosk
autologin-user-timeout=0
user-session=kiosk
greeter-session=lightdm-gtk-greeter
greeter-hide-users=true
session-wrapper=/etc/X11/Xsession
xserver-command=X -pointer None -allowMouseOpenFail

The user-session=kiosk line here is what causes it to load the session file from /usr/share/xsessions/kiosk.desktop and run the program define in that file as the Exec property.

autologin-user should be set to a valid local account. I created it using sudo adduser --gecos "Kiosk User,,," --disabled-password kiosk.

/usr/share/xsessions/kiosk.desktop

[Desktop Entry]
Encoding=UTF-8
Name=Kiosk Mode
Comment=Chromium Kiosk Mode
Exec=/usr/local/bin/kiosk.sh
Type=Application

Power saving

Finally a useful power saving scheme if these are to be on permanently is to use the DPMS management to power off the screens outside office hours. The following script can be called from cron to control the display (depending on the hardware support)

dpms

#!/bin/bash
#
# This machine operates as a display and is on all day. This script
# disables the DPMS setting on the monitor so that the monitor itself
# will not power off after a period of inactivity. We call this from
# a cron job to turn the monitor off an night and over the weekends.
#
# Initially these settings are handled by the kiosh.sh script which
# disables the screen blanking screensaver capability in the X server and
# disables DPMS when we first start up.

DISPLAY=:0.0; export DISPLAY
COOKIE=/var/run/lightdm/root/\:0

function log()
{
    logger -p local0.notice -t DPMS $*
}

function dpms_force()
{
    xset dpms force $1 && log $1 || log FAILED to set $1
}

if [ $# != 1 ]
then
    echo >&2 "usage: dpms on|standby|off"
    exit 1
fi

[ -r $COOKIE ] && xauth merge $COOKIE

case "$1" in
    on)
        # Turn on and disable the DPMS to keep it on.
        dpms_force on
        xset s reset
        xset -dpms
        ;;
    off|standby|suspend)
        # Allow to turn off and leave DPMS enabled.
        dpms_force $1
        ;;
    *)
        echo >&2 "invalid dpms mode \"$1\": must be on, off, standby or suspend"
        exit 1
        ;;
esac

Suggested /etc/crontab entries (or create a /etc/cron.d/kiosk file):

#
# Kiosk display power management
#
00 07   * * 1,2,3,4,5   root    test -x /usr/local/bin/dpms && /usr/local/bin/dpms on
00 17   * * 1,2,3,4     root    test -x /usr/local/bin/dpms && /usr/local/bin/dpms off
00 16   * * 5           root    test -x /usr/local/bin/dpms && /usr/local/bin/dpms off
  • I think I follow, so you set a default and then the line below you check if the file exists and is readable, if so it passes it into KIOSK_URL ? Does it matter where you save this script, and does it need to be added into the autostart file in ordered to be called on boot? – ghost3h Feb 24 '16 at 12:35
  • It does not matter where the file containing the variable definitions is placed, only that it be readable. To run on boot you need to hook into lightdm really. I define a kiosk.desktop file that calls the above script and configured lightdm (the raspbian graphical login manager) to use the kiosk session as the auto-login session. I can add these files if necessary. – patthoyts Feb 24 '16 at 12:40
  • Yes please if you wouldn't mind. I think im going to keep it simple, and just have it load chromium in kiosk on boot using the URL from the file on the desktop. – ghost3h Feb 24 '16 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.