RaspberryTV


Home Page | Comments | Articles | Faq | Documents | Search | Archive | Tales from the Machine Room | Contribute | Login/Register

Good morning mr. Sysadmin, your mission is, if you want to accept it (by the way is not that you can refuse it, this is just for show you know how it is), to have a number of big screen around the office display a sequence of graphs and statistical data and more or less wathever we think about during the day in a continouse loop. Just to annoy everybody without providing any useful information. We've already ordered the screens, those are "smart" tv. Off you go then.

Raspberry PI

And with this extremely detailed task description I was sent to the merry chase of a solution. Of course since the screens were already purchased and would have been installed in the next few days, I was on a short timetable.

I quickly considered the alternatives: since those are supposed to be 'smart' tv, I could simply use a vnc viewer application and connect to a vnc server in the office where to run a dumb browser with a simple "rotate" plugin to show all the different tab in a sequence.

Another alternative was to use something like a Raspberry Pi connected to the screen and running the browser directly. In any case, it seems that I needed a vnc server at least, so I started with that.

I had a couple of old desktops (Dell Precision I think), so grabbed one and started by installing a standard CentOS 7 distribution.

Nothing fancy, a fixed IP address that was outside the DHCP range in the office and I didn't installed a graphic environment.

After that, I had to do something to run VNCServer and a Browser.

I started with installing the Xorg FrameBuffer driver, firefox, xfwm4, vncserver and X11vnc for the libraries. The framebuffer brought with it all the required libraries to run a barebone version of X. Xfwm4 was necessary because without a window manager, Firefox couldn't be set "full screen" and couldn't handle tabs.

In short the process was:

yum install -y xorg-x11-drv-fbdev
yum install -y firefox
yum install -y xfwm4
yum install -y vncserver
yum install -y x11vnc

(change this to suit your distribution eventually)

After this I had to handle the configuration. Let's start with Xvfb, the virtual frame buffer that runs the "screen". It is designed to work on headless machines so it is perfect because I didn't wanted anybody to login in the server itself anyway. Xvfb require a few parameter do "simulate" the screen on the command line:

/bin/Xvfb $DISPLAY -screen 0 1920x1080x16

The $DISPLAY parameter specify which "display" the driver must manage. Since this parameter has to be repeated multiple time, the best thing is to define a global variable:

export DISPLAY=:0

The resolution "1920x1080x16" is HD with 16 color depth. That should be more than enough for what I needed.

Now is time to handle the window manager, connecting it to the "display":

/bin/xfwm4 --display $DISPLAY --daemon

After this, I could start Firefox and VNC on the same display.

/bin/firefox --display $DISPLAY &
/bin/x11vnc -bg -shared -forever -display $DISPLAY -noipv6 -rfbport 5901 -passwdfile /home/vncserver/.vnc/passfile

The passwdfile parameter is used to specify the password for "read and write" and "readonly" for VNC. The password file is a basic text file that can be edited with any editor. The shared and forever parameters are to allow multiple clients to connect and keep the server running when the last client disconnect.

I wanted everything to run at boot up automatically, and possibly keep running. So I made a special 'user' to run everything and a script that start all the required application in the correct order:

#!/bin/bash
# start X and a VNC session
 
DISPLAY=:0
export DISPLAY=$DISPLAY
 
# start X with a virtual display 1920x1080 16 colours (HD)
x=`/bin/ps -aux | /bin/grep -c Xvfb`
if [ $x -lt 2 ] ; then
        echo "starting xvfg"
        /bin/Xvfb $DISPLAY -screen 0 1920x1080x16 &
else
        echo "Xvfb already running ($x)"
fi
 
# start fwm4 on top of the display
x=`/bin/ps -aux | /bin/grep -c xfwm4`
if [ $x -lt 2 ] ; then
        echo "starting xfwm4"
        /bin/xfwm4 --display $DISPLAY --daemon
else
        echo "Xfwm4 already running ($x)"
fi
 
# start Firefox
x=`/bin/ps -aux | /bin/grep -c firefox`
if [ $x -lt 2 ] ; then
        echo "starting firefox"
        /bin/firefox --display $DISPLAY &
else
        echo "Firefox already running ($x)"
fi
 
# start vnc
x=`/bin/ps -aux | /bin/grep -c x11vnc`
if [ $x -lt 2 ] ; then
        echo "starting vnc"
        /bin/x11vnc -bg -shared -forever -display $DISPLAY -noipv6 -rfbport 5901 -passwdfile /home/vncserver/.vnc/passfile
else
        echo "x11vnc already running ($x)"
fi
 
exit 0

This was added to Cron to run every 5 minutes, if one of the services is down, it will be restarted. The script write a logfile to notify if something is wrong.

Once this was done I could connect using vncviewer from my machine and add the required plugins in Firefox.

In firefox I installed the TabRotator Plugin to do the display and then created a "preferred" list with all the site we need to display. This way, if firefox is closed it is only a matter of "open all the url" and restart the rotator.

At this point, the server was basically ready to do its job. The only question were the clients. The tv were delivered and installed and I started messing around with them.

It turned out quickly that the only vncviewer application available on their 'android' OS was a piece of garbage that didn't worked very well and it was also requiring a license to run. So I ditched it immediately and reached out for a couple of Raspberry.

A couple of tests told me that the available browser in Raspbian was... lacking in term of plugins, so I went for the vnc all the way.

First thing, I wanted these thing to boot up and immediately start vncviewer and to do this, I wanted them to connect to the wifi network.

In /etc/wpa_supplicant I edited the wpa_supplicant.conf file and added:

network={
 ssid="TheSSIDofTheNetwork"
 psk="##the_password##"
 scan_ssid=1
}

I noticed that the network was quite slow to start and connect, I decided to simply add a delay to the start of vncviewer. I prepared a small script for that:

sleep 60
/usr/bin/vncviewer -config /home/pi/vncserver.vnc

And now is matter of putting it in autostart. In /home/pi/.config/lxsession/LXDE-pi there is an 'autostart' file, first of all, I had to remove all call to xscreensaver to avoid the PI to go in screensaver mode and then added:

@sh /home/pi/vncviewer.sh

Also added the following:

@xset s noblank
@xset s off 
@xset -dpms

to completely disable all type of screensavers.

Then in /etc/xdg/autostart I removed the pprompt.desktop file, otherwise the PI would have kept reminding that SSH was enabled.

Now it's time to create the vncclient config file, for that there are 2 way to do it: manually or automatically. Automatically is a matter of connecting to the vncserver, checking the 'remember password' box and then "exporting" the connection to the file /home/pi/vncserver.vnc (the same specified in the autostart script).

The "manual" way consist in writing the very same 'vncserver.vnc' file that contains something like the following:

ClientCutText=0
ConnTime=2018-02-28T11:06:13.703Z
EnableChat=0
FriendlyName=vncserver
FullScreen=1
Host=:
Password=
Quality=High
RelativePtr=0
SendKeyEvents=0
SendPointerEvents=0
ServerCutText=0
ShareFiles=0
Uuid=9ad542a9-8b9e-4def-58dd-92b1614dee9b

The password ash is the only complicated bit and can be obtained using crypt, however I noticed that sometimes the hash isn't the correct one, so I went with the 'automatic' way that was foolproof.

After this, I noticed that the PI still went into screensaver sometimes, so I also edited /etc/lightdm/lightdm.conf file and in the section [Seat:*] uncommented and changed the line xserver-command=X with the following:

xserver-command=X -s 0 -dpms

In /boot/config.txt add the following lines:

hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=82

This will force the PI to go to full-screen and maximum resolution, I discovered that the HDMI isn't good at figuring out which resolution is the right one. Note that all the other "hdmi" lines in the file should be commented out.

After a reboot I noticed that everything was working fine and the PI simply connected to vncserver without asking anything.

At this point I made a copy of the SD card and went to clone this for every other PI I needed.

I also decided to add an automatic-shutdown of all the PIs in the evening, to turn them off "clean" at 5pm so they can restart the next morning when the TVs are switched on again (the PIs are attached to the USB port in the back of the tv for power, turning on the tv also turn on the PI).

In order to shutdown the PIs I needed to SSH in them and run 'shutdown', this is easy to do if you put your ssh key on the PI. For this I simply made a script running on the same 'vncserver' machine with the IPs of all the PIs.

And with this I was done. Another succesfull missions accomplished.


Comments are added when and more important if I have the time to review them and after removing Spam, Crap, Phishing and the like. So don't hold your breath. And if your comment doesn't appear, is probably becuase it wasn't worth it.

11 messages post new
Anonymous coward By Anonymous coward - posted 08/03/2019 11:01 - reply

Davide, scusa la domanda stupida (chiaramente mancano molti dettagli per poter capire bene tutto) ma quale è il vantaggio di aprire una sessione vnc per poter usare un firefox su uno schermo "emulato" piuttosto che installare firefox con i relativi plugin sulle singole raspberry ? Letta così sembra che il vncserver sia li solo per permettere di usare un firefox... 

--
Anonymous coward


Davide Bianchi@ Anonymous coward By Davide Bianchi - posted 11/03/2019 08:38 - reply

installare firefox con i relativi plugin sulle singole raspberry ?

Come detto nell'articolo, la versione di firefox disponibile in Raspbian e' a dir poco "mutilata" e nessuno dei plugin che mi servivano era disponibile o sembrava voler funzionare in modo accettabile. Ecco perche' sono passato alla soluzione VNC.

 

--
Davide Bianchi


Anonymous coward@ Davide Bianchi By Anonymous coward - posted 08/04/2019 14:37 - reply

Ecco, a proposito della versione di firefox mutilata, e' verissimo. Quello che non capisco e' il perche'. Ormai gli ultimi PI hanno buoni livelli prestazionali.

--
Anonymous coward


Anonymous coward@ Anonymous coward By Anonymous coward - posted 12/03/2019 22:53 - reply

 

Davide, scusa la domanda stupida (chiaramente mancano molti dettagli per poter capire bene tutto) ma quale è il vantaggio di aprire una sessione vnc per poter usare un firefox su uno schermo "emulato" piuttosto che installare firefox con i relativi plugin sulle singole raspberry ? Letta così sembra che il vncserver sia li solo per permettere di usare un firefox... 

Credo che un vantaggio sia che se si fa una modifica sul server (nuove tab o similari) questa si propaghi a tutti i monitor senza dover riconfigurare tutti i raspberry a manina, sia che siano 2 o 20, ricordiamoci della “pigrizia” degli informatici ;-\)

Marco

 

 

--
Anonymous coward


Davide Bianchi@ Anonymous coward By Davide Bianchi - posted 13/03/2019 09:34 - reply

Credo che un vantaggio sia che se si fa una modifica sul server (nuove tab o similari) questa si propaghi a tutti i monitor senza dover riconfigurare tutti i raspberry a manina, sia che siano 2 o 20, ricordiamoci della “pigrizia” degli informatici ;-\)

Anche.

 

 

--
Davide Bianchi


Anonymous coward By Anonymous coward - posted 08/04/2019 14:28 - reply

Mi stupisce una cosa: tu dici che i PI attaccati all' USB del televisore si accendono insieme a quello tuttavia se non erro i PI si aspettano 5V e 3A, di solito le TV ne forniscono di meno, il meno possibile. Sbaglio? Bellissima comunque l' idea di usare i PI.

--
Anonymous coward


Davide Bianchi@ Anonymous coward By Davide Bianchi - posted 09/04/2019 08:10 - reply

se non erro i PI si aspettano 5V e 3A, di solito le TV ne forniscono di meno, il meno possibile.

Non ho idea di cosa si aspetti la Raspberry, ma si accendevano tranquillamente e funzionavano uguale quindi...

--
Davide Bianchi


Massimo M.@ Davide Bianchi By Massimo M. - posted 20/05/2019 11:30 - reply

> Non ho idea di cosa si aspetti la Raspberry, ma si accendevano tranquillamente e funzionavano uguale quindi...

 

Per quanto ne so leggiucchiando in rete (io avevo il raspberry 1B), il raspi e' piuttosto pretenzioso sugli alimentatori, chiede almeno 2.5A per andare al 100% di cpu.

Un consiglio che posso darti e' questo: il primo modello aveva la spiacevole tendenza a corrompere fisicamente le sd (mi e' capitato 3 volte, con sd di marche diverse, e sotto ups, quindi era trattato con i guanti), e molti riportano la stessa cosa anche sul 3. Alcuni avevano risolto usando sd industriali, ma mi sembra eccessivo.

Io ho risolto mettendo su sd solo la partizione di boot, con la root su usb, e, appena possibile, la partizione di boot veniva smontata, in modo da usare il meno possibile la sd. In questa maniera non ho mai piu' avuto problemi.

--
Massimo M.


Manuel By Manuel - posted 11/04/2019 21:40 - reply

Beh, 5V sicuro, e di solito fra 1 e 2A. Magari non sono dei PI3B, ma dei modelli più economici.

 

--
::: meksONE :::


Anonymous paranoid By Anonymous paranoid - posted 15/04/2019 19:04 - reply

Molto interessante. Avendo fatto un progetto simile (raspberry che mostra una pagina web) avrei un piccolo suggerimento: è meglio disattivare il logging per evitare di ritrovarsi con la scheda SD formato groviera dopo qualche mese. Io avevo creato una partizione tmpfs in cui riversavo tutta la robaccia. Purtroppo non ricordo esattamente tutti i dettagli ma se ti interessa sradico il pannello e vedo che cosa ho fatto.

--
Anonymous paranoid


Davide Bianchi@ Anonymous paranoid By Davide Bianchi - posted 16/04/2019 08:14 - reply

Molto interessante. Avendo fatto un progetto simile (raspberry che mostra una pagina web) avrei un piccolo suggerimento: è meglio disattivare il logging per evitare di ritrovarsi con la scheda SD formato groviera

Hai ragione: non ho citato il logging. Quello che ho fatto io e' stato configurare rsyslog per mandare tutto al nostro server di logging remoto. Solo che non l'ho scritto perche' non e' "strettamente" relativo al progetto.

 

--
Davide Bianchi


11 messages post new

Previous

Davide Bianchi, works as Unix/Linux administrator for an hosting provider in The Netherlands.

Do you want to contribute? read how.  
 


This site is made by me with blood, sweat and gunpowder, if you want to republish or redistribute any part of it, please drop me (or the author of the article if is not me) a mail.


This site was composed with VIM, now is composed with VIM and the (in)famous CMS FdT.

This site isn't optimized for vision with any specific browser, nor it requires special fonts or resolution.
You're free to see it as you wish.

Web Interoperability Pleadge Support This Project
Powered By Gojira