Senior citizen-friendly video telephony system with a Raspberry Pi

Autostart All Services

Processes and programs can be started automatically in different ways on the Raspberry Pi. In this example, I will be using a desktop file that starts a number of processes in parallel in the background. The advantage of this procedure is that the LXDE interface starts up completely in the background, and you end up in the graphical user interface after exiting the web browser by pressing the Ctrl+F4 hotkey.

For this example, enter

sudo nano /etc/xdg/autostart/usr_autostart.desktop

to create the autostart file and add the following content:

[Desktop Entry]
Comment=user defined autostart script
Exec=/bin/bash /home/pi/

The system reads the usr_autostart.desktop file when booting the graphical interface and then executes the command entered in the Exec line. In this case, the system loads the script /home/pi/, which has the startup commands.

Again you have to create this file manually by typing

nano /home/pi/

and adding the content shown in Listing 3. To allow the system to execute the file, adjust the permissions after saving with

chmod +x /home/pi/

Listing 3

01 #!/bin/bash
02 ### Turn off the mouse pointer after 5 seconds of inactivity.
03 unclutter -idle 5
04 ### Turn off the screen saver and power saving functions.
05 xset -dpms
06 xset s off
07 xset s noblank
08 ### Turn on the TV and switch to HDMI.
09 echo 'on 0' | cec-client -s -d 1
10 echo 'as' | cec-client -s -d 1
11 ### Update date and time from Fritzbox for email.
12 sudo rdate -4nu -s <>
13 ### Send email with link that Jitsi has started.
14 sudo echo '<MeetID>#config.prejoinPageEnabled=false&config.disableAP=true&config.noisyMicDetection=false&' | mail -s 'Jitsi Meeting ID is online' <>
15 ### Start Jitsi meeting in Chromium.
16 chromium-browser --noerrdialogs --disable-crash-reporter --kiosk<MeetID>#config.prejoinPageEnabled=false&config.disableAP=true&config.noisyMicDetection=false&
17 exit

The file outsources four tasks:

  • Turning off the mouse pointer and the screen saver (lines 2-7).
  • Turning on the connected TV and switching to the HDMI input (lines 8-10).
  • Sending a notification to a specified email address (lines 11-14).
  • Starting the Jitsi meeting in the Chromium browser (line 16).

The xset command from the x11-xserver-utils package, which can be used to turn off the screen saver, among other things, is part of the default installation. To turn off the mouse pointer, install the unclutter package with:

sudo apt install unclutter

The TV device is controlled by the previously installed cec-client. With a pipe (|), you can forward the command output with an echo to the client. For example,

echo 'on 0'

wakes up the device with device number 0 from standby, and

echo 'as'
echo 'is'

switches the HDMI input of the Raspberry Pi to active and inactive.

You can set the <MeetID> in lines 14 and 16 freely. However, when choosing the ID, make sure that strangers do not hijack the video call. A random alphanumeric string such as that output by the command

xxd -l16 -ps /dev/urandom

would be a good choice. Additionally, you have to adjust the IP address of the wireless router in line 12; the same applies to the email address of the recipient of the notification in line 14.

The call to Jitsi in the web browser in line 16 passes a set of parameters:

  • config.prejoinPageEnabled=false suppresses a prompt for which username to use when joining the meeting. Without a mouse and keyboard, this would be impossible to answer.
  • config.disableAP=true disables audio processing, mainly to reduce the load on the Raspberry Pi CPU.
  • config.noisyMicDetection=false prevents a warning message from appearing as soon as the microphone signal becomes noisy.
  • reduces the video resolution to save the Raspberry Pi's processor.

You will often read on Internet forums that exit at the end of a script that runs all the way through is not good style, but when I tried a script without exit, Chromium failed to start; at the end of the day, the instruction does not do any harm.

Keystroke Shutdown

Now you have established a connection, but a routine is still missing that shuts down the system properly. The grandparents should not have to adjust anything on the Raspberry Pi or the TV.

For this purpose, I drilled a hole in the case for a switch that sits between the processor and the USB ports above the board; some space is available there for the connection cables. After I installed a suitable push button in the housing, I connected it with one cable each to GPIO pins 5 and 9 (GND) to close a circuit when the button is pressed (Figure 2). Connected to pin 5, the button also wakes the Raspberry Pi from sleep mode if the small-board computer is connected to a power supply (Figure 3). This function is integrated at the factory and requires no further configuration [6].

Figure 2: The push button is installed centrally on the top of the housing.
Figure 3: Schematic diagram of the circuit (created with Fritzing).

If the Raspberry Pi is running, the button will initiate a shutdown process that switches the HDMI input of the TV back to inactive, which, in turn, usually causes the TV to switch to the last selected channel. Furthermore, you want the Raspberry Pi to shut down the operating system gracefully, which includes exiting Chromium and thus the video conference.

To do this, the system needs to monitor GPIO pin 5 continuously, as performed by the/home/pi/ script (Listing 4). This script needs to be started before the graphical user interface in the existing /etc/rc.local file with the shutdown entry,

#!/bin/sh -e
python /home/pi/ &
exit 0

Listing 4


01 # Shutdown script
02 # Waits for LOW at pin 5
04 import RPi.GPIO as GPIO
05 import os
07 GPIO.setmode(GPIO.BOARD)
08 # GPIO pin 5 as input with signal HIGH
09 GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
11 try:
12   while True:
13     # Waits for the pin to be connected to GND
14     GPIO.wait_for_edge(5, GPIO.FALLING)
15     # Raspberry Pi signal is turned off at the TV
16     os.system("echo 'is' | cec-client -s -d 1")
17     # os.system("echo 'tx 10:9D:10:00' | cec-client -s -d 1")
18     # Proper shutdown, also of Chromium
19     os.system("shutdown -h now")
21 except:
22   GPIO.cleanup()

which should appear in the penultimate line, before the final exit 0, as shown. Be sure to include the & at the end of the Python program call; otherwise, the system will wait for the script to finish, which would cause the system to freeze.

Finally, you need to make the Python script executable by typing:

sudo chmod +x /home/pi/

You should also take a look at lines 16 and 17 of Listing 4. According to the specification, the CEC call echo 'is' switches the HDMI signal to inactive. In combination with my Sony Bravia TV, however, this command did not do what the doctor ordered. The TV continued to display the picture of the Raspberry Pi system fed in over HDMI. Fortunately, deregistering the signal at the TV with a CEC frame injection by calling echo 'tx 10:9D:10:00' worked.

If you experience issues, try one of the two calls by removing the hash symbol # in one line and adding it to the other line. Unfortunately, every manufacturer does its own thing when it comes to CEC. Often, CEC only really works reliably with newer TV sets.

Input and Output Devices

To guarantee that the system always outputs audio through the TV and records audio from the microphone built into the webcam, you need to enter the audio devices permanently on the system. To do this, display the input and output devices detected by Raspberry Pi OS with aplay -l and arecord -l (Listing 5).

Listing 5

Detected Devices

$ aplay -l
   List of hardware devices (PLAYBACK)
Card 0: b1 [bcm2835 HDMI 1], Device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1].
  Sub devices: 4/4
Card 1: Headphones [bcm2835 Headphones], Device 0: bcm2835 Headphones [bcm2835 Headphones].
  Sub devices: 4/4
$ arecord -l
   List of hardware devices (CAPTURE)
Card 2: C920 [HD Pro Webcam C920], Device 0: USB Audio [USB Audio].
  Sub devices: 1/1
  Sub-device #0: subdevice #0

The important parts of this output are the device names that follow the card numbers; in this example, b1 is the HDMI output, Headphones the analog headphone jack on the Raspberry Pi, and C920 the Logitech webcam used in the setup.

Now create the appropriate settings file by typing

sudo nano /etc/asound.conf

and pasting the content from Listing 6. Usually, you will only need to adjust the device name of the webcam microphone in line 9. After a restart, the correct devices should now be selected automatically.

Listing 6


01 pcm.!default {
02   type asym
03   capture.pcm "mic
04   playback.pcm "speaker
05 }
06 pcm.mic {
07   type plug
08   slave {
09     pcm "hw:<C920>"
10   }
11 }
12 pcm.speaker {
13   type plug
14   slave {
15     pcm "hw:b1"
16   }
17 }

The WebRTC test page [7] should then report no errors, and the audio and video test for WebRTC [8] should output image and sound from the webcam (Figure 4).

Figure 4: The WebRTC test indicates that everything is OK: To be on the safe side, use the volume slider context menu to check that the system is using the correct input and output devices.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Pi OS 2020-12-02

    The Raspberry Pi Foundation regularly adds new features to the official operating system, Raspberry Pi OS. The December 2020 update added the PulseAudio sound server and a print manager.

  • Jitsi

    If you are looking for an alternative to commercial videoconferencing platforms, Jitsi offers an open source solution that lets you build and deploy online videoconferences.

  • A New Raspberry Pi Board

    The new board packs everything that you get in Raspberry Pi 3B+ in a smaller package.

  • Real-World Raspberry Pi

    The single-circuit-board Raspberry Pi computer, only as big as a credit card, makes it easy to gain experience with embedded Linux systems. We'll show you some hands-on examples of how to use the Raspberry Pi in an everyday environment.

  • New Raspberry Pi Adds Two USB Ports

    New B+ board lets you build cool things without the complication of a powered USB hub.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More