Putting Raspbian on a diet!

Are you having problems with storage space on your Raspberry Pi? Me too!

I was recently attempting to compile OpenCV on a Raspberry Pi 3 with an 8GB SD card when it crapped out complaining of a lack of disk space. Now, OpenCV does need a lot of room to compile, but come on 8GB? Err, no. As it turns out, as the Pi has become more popular and Raspbian has evolved its picked up quite a lot of (very good) default application along the way. This is great for the Pi’s primary purpose of education, but for those of us with more advanced ambitions and aspirations it can become a problem.

Fear not dear reader, there is a solution!

You can reclaim >1.1GB of your SD Card simply by removing a whole host of programs and associated packages that are installed by default and that you probably never use. For example I run the following commands from the console:

$ sudo apt-get purge wolfram-engine libreoffice libreoffice-* nodered \
  bluej greenfoot scratch sonic-pi minecraft-pi -yq
$ sudo apt-get autoremove -yq

This removes all of LibreOffice, all of the Java IDE’s (Java? When you have Python?!), Wolfram (over 600MB!), Scratch, Sonic Pi and Minecraft. And, Voila! I can now compile OpenCV and get on with taking over the world!

Setting Up Digital Signage with a Raspberry Pi

Introduction

For a while now I’ve had some Raspberry Pi‘s (Version1, Model B) running as 3 digital signage installations. They are basically mounted on the back of two 55″ and one 32″ LG TV’s and use the USB socket on said TV’s for power and are connected via HDMI. Nice, easy and simple. Recently I decided it would be good to replace the Pi’s with the new Model 3 to take advantage of the far more powerful CPU and the integrated WiFi. This post is simply a log (mostly for myself) of how to set them up.

Method

1. Install Raspbian Jessie via NOOBS

I bought three SanDisk 8GB Class 10 Micro SD Cards from a high street retailer (they were on offer!). I then downloaded the latest version (1.9) of the NOOBS offline installer from the Raspberry Pi website, unzipped the archive and copied the contents to each of the SD Cards after the had been named and formatted using the SD Formatter 4.0 tool (I did this bit on a MacBook Pro). I then connected then connected each Pi in turn to its TV along with a keyboard and mouse, fired it up and let NOOBS do its thing WRT to installing Raspbian.

2. Setup the WiFi

The first thing I would usually do when installing a Linux system for the first time is update it, however, as I didn’t yet have a network connection, I had to setup the WiFi first. Just to make things more amusing, the available WiFi network uses a security method (PEAP-MSCHAPV2) not (yet?) automatically supported by the Pi’s WiFi utility, so I had to set this up manually. If you’re connecting to a home network you can probably just connect using the GUI utility by putting your password in.

Anywho, I had to enter the following into /etc/wpa_supplicant/wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
    ssid="<SSID>"
    priority=1
    proto=RSN
    key_mgmt=WPA-EAP
    pairwise=CCMP
    auth_alg=OPEN
    eap=PEAP
    identity="<USERNAME>"
    password=hash:<PASSWORD HASH>
    phase1="peaplabel=0"
    phase2="auth=MSCHAPV2"
}

Just replace <SSID> with your network name, <USERNAME> with your username and <PASSWORD HASH> with the hash string generated using the following command:

echo -n '<PASSWORD>' | iconv -t utf16le | openssl md4 > hash.txt

Replacing <PASSWORD> with your actual password. The hash string will be saved in a file called hash.txt.

Now reboot you Pi and when it comes up, it should automatically connect to your network.

3. Update and Upgrade

Now its time for the afore mentioned updating and upgrading which I achieved using the following commands:

sudo apt-get update -y
sudo apt-get dist-upgrade -y
sudo reboot

4. Install the Unclutter package

I’ll use the unclutter package later to auto-hide the mouse pointer when its not moved (i.e. almost always). We simply install the package as follows:

sudo apt-get install unclutter -y

5. Set the Hostname

The only way I’ll be able to interact with my Pi’s once they are installed is via SSH over WiFi. On my network I have a dynamic DNS which allows me to find them via nice URL rather than IP address. For this to work, I needed to give my Pi’s a unique hostname which I did using the raspi-config tool (sudo raspi-config). Select to option 9 ‘Advanced Options’, then select option ‘A2 Hostname’, OK the resulting dialog and then enter the desired hostname. The select ‘OK’, ‘Finish’ and when asked if you’d like to do so, reboot the Pi.

6. Auto-starting the Digital Signage Application

Note: I performed the rest of these steps over SSH now that I had a hostname to contact.

My Digital Signage Application is actually just a website so what I want to do is start a web browser automatically when the Pi boots and point it at the desired page. This is done by creating an autostart desktop entry for LXDE (the window manager). First we create the necessary directory as follows:

mkdir -p ~/.config/autostart/

And then we create the file ~/.config/autostart/epiphany-browser.desktop and add the following content:

[Desktop Entry]
Name=epiphany-browser
Exec=epiphany-browser -a --profile /home/pi/.config http://www.google.co.uk
Type=application

This will launch the Epiphany Web Browser in kiosk mode and point to Google (just as an example).

7. Disable the Screensaver and Hide the Mouse Pointer

We don’t want our application going to sleep on us or the screen saver kicking in after a few minutes. Also we don’t want to see the mouse pointer sitting in the middle of our beautiful web page! So we edit the /etc/xdg/lxsession/LXDE/autostart file to read as follows:

@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash
@unclutter -idle 0.1 -root
@xset s noblank
@xset s off
@xset -dpms

Edit: I also seem to need to modify /etc/lightdm/lightdm.conf to stop the screen blanking as follows:

...
[SeatDefaults]
xserver-command=X -s 0 -dpms
...

8. Auto-hide the Panel

the final thing we want to do is hide the task bar, or Panel as its referred to, at the top of the screen. This is simply done by right-clicking on the panel and selecting Panel Settings. In the resulting dialog, select the Advanced tab, navigate down to the Automatic hiding section and check the ‘Minimise panel when not in use’ option. Also, set the  ‘Size when minimising’ option to 0. Ok the dialog and reboot the Pi.

Conclusion

You should not have a Pi that when booted automatically connects to WiFi, opens a web browser and points it at your favourite web page, all the while decluttering the screen and stopping the screen saver from kicking in.

Hope this useful to someone, like and share 🙂