Technical Blog

Here at Severn Delta, we had a need for some CCTV cameras, due to damages out in the factory. I was asked by our Managing Director, if a solution using Raspberry Pis could be implemented. After some research, I stumbled across MotionPie.

This blog post will show how I set up a Raspberry Pi to act as a CCTV camera.

First off, we need a parts list for this project. I found some great CCTV oriented Pi cases over at ModMyPi. Unfortunately, the company that makes these cases would appear to have gone out of business, so I managed to find some on another site, coming from somewhere in the EU. While these cases are, frankly a pain to put together, they have all the features that I was after, they have wide angle lenses, and included mounts for attaching to walls.

MicroSD Card – Any that are compatible with the Pi can be found here – The image for MotionPie is around 150MB. Obviously if you want to use the MicroSD for storage of video clips, go ahead and order a larger card.

WiFi Adaptor – I used a TP Link TL-WN823N. This is because I really wasn’t happy buying an off brand ‘Nano USB Wireless N adaptor’. They just look horrific, and for a production environment, I doubt they’d last. They are compatible with the Pi out of the box and can be found here on Amazon

Some form of Wireless Access Point – We now use Ubiquiti Unifi access points. I’d really recommend them, apart from the Web admin software only runs on Windows (Really?!), but as long as you have a windows box somewhere you’ll be fine. They seem to be very highly regarded in the industry, and I can see why. You can find them here on Amazon.

A Linux computer. No, really. Windows will make this a lot harder for you, as you can’t use the included script to do all of the heavy lifting for you!

Preparing the SD Card

Firstly, we need to prepare the SD card, and image it with MotionPie. You will need a network with DHCP enabled, so that the Pi receives an IP. This is because all of the configuration is done via the browser, or SSH. Normal home routers already have DHCP servers. It’s important to get the networking right, because there is no GUI given out by MotionPie, it doesn’t even have graphics drivers.

Firstly, we will need to get the latest copy of MotionPie: Navigate your browser to this page, and click ‘Download motionPiexxxxxx.img.gz’.

Now, this archive needs to be extracted, and you will end up with a .img file. The next step is to download the script that allows the easy install of the image to the SD card. You can find it here.

Place the extracted img file and the downloaded script into the same directory, and insert your SD card into the computer. I use a PoundLand adaptor, which while made of imitation cheese, seems to do the job fine. Next you’ll want to open that directory with a terminal emulator. Now, run df -h in the terminal, and you’ll get a lovely output of all available disks. As you can see in the screenshot, my SD card is recognised as /dev/sdd, this being the actual disk, not the partition.

Once you’ve worked out which disk you are going to image, you can begin to flash the image to the SD card. This is done using the writeimage.sh script. I followed the instructions on the Github page for MotionPie. There are many different arguments you can give to the script. You can view them here.

The basics of the command are:

./writeimage.sh -d /dev/DEVICE/ -i motionPie-xxxx.img

The above will simply dd the image over to the SD card. Now, if you want to connect straight to a wireless network, like I did, then you need to specify the SSID and key, using the -n (For network) argument. In my case it was:

I used quotes, as I spent a long time troubleshooting this, and apparently quotes makes this work? Because of the spacing I assume.

‘But wait, what about the -w argument?’ I hear you ask. If you take a look at the github page, you’ll see that it disables rebooting when WiFi is lost. Now, ideally this sounds like a great idea, because, say for example, the adaptor fails, the Pi will reboot, and hopefully the IT-Crowd solution will work. However, for me, it seemed to take longer than the set time to actually connect to the WiFi network, causing a reboot loop. Whether I did something wrong, I don’t know. But I do know that using the -w argument actually allowed me to access the Pi, as it wasn’t constantly rebooting all the time. Below you can see the output of my terminal, and the lovely progress report from the script.

Fantastic! Now we have a fully imaged SD card with MotionPie on it. The next step is to insert it into the Pi, connect the camera and power it on, obviously while it is attached to the network, or connected via WiFi. It’s a good idea to set a static IP for the Pi, do this on your DHCP server, or router once connected. As we use LTSP here, I just edited the /etc/ltsp/dhcpd.conf file and restarted the DHCP server.

Configuration

Now that you know the IP for the Pi, you can go ahead and enter it into a web browser of your choosing. You will be presented with a login dialogue. The default user is admin, and there is no default password. Once you’ve logged in here, you can click on the menu on the top left of the page to edit settings, including the wireless network. There is a huge amount that can be configured here, such as the storage location. I have it storing all video files to a specific folder on a NAS share.

Conclusion

I found the guide on github a little lacking, so I wrote this. The image below will give you an idea of a finished product. If you found this guide helpful, follow us on Twitter at @harrylavender and @uzerp.

At Severn Delta, we here use Ubuntu 14.04, delivered over LTSP. After our old 10.04 system died unexpectedly when I first joined the company, an upgrade to 14.04 was the obvious thing to do. The issue being with this, is that since 10.04, a lot of graphical changes have been made, and Unity requires quite a lot of grunt to push over LTSP. Also, users were used to the classic Gnome layout, and Unity would probably have caused quite a lot of confusion. We also only had 4GB of RAM to play with, across 10~ users.
So this is the easiest way to install and configure a MATE window manager, with lock-down features, on a vanilla install of Ubuntu 14.04, I ran the following commands:

apt-get install mate-desktop

apt-get install menulibre

Once these had finished installing, I logged out of our administrative account on the system, and into my personal test account. I then opened Menulibre, and the rest is fairly foolproof to be honest, the GUI is really quite nice, and easy to use.
(Image credit: http://smdavis.us/)

Once you have made the changes necessary (I removed the .desktops for items such as terminal emulator, and some games), and pressed save, you can go and grab your newly edited MATE config files in /home/user/.local/share – this is where the configuration files reside. I simply copied the entire folder, and pasted it into the home directories of all the users that I wanted to have that specific menu layout. If you want to go back, simply delete the folder from your test account as a sudoer, and log on again. MATE will recreate your menu files, and you can make another version for another user for example. However, here at Severn Delta, most users have the same requirements, so this wasn’t much of an issue.

There may well be a better solution to this, but I have yet to find it, especially for multiple users!

If you found this guide useful, follow myself and uzERP on twitter for more LTSP/Raspberry Pi updates: http://www.twitter.com/harrylavender and http://www.twitter.com/uzERP

Here at Severn Delta, we have just received some new Raspberry Pi Model B+ units for use in various applications, which will be featuring in this blog in the near future. After attempting to get a few to work with LTSP for a training session today, none of them would boot. Initially, I thought it was due to the fact that I was using my Android phone as a MicroSD adaptor, and that it was tampering with the file system and the partitions. So, I looked around here in Bridgwater for somewhere I could pick up a MicroSD adaptor. £9 at Argos, and £22 at Curry’s. Really?

Fortunately, my colleague gave me a lift into Bridgwater, and I grabbed a Poundland multi-card adaptor!

Anyway, it turned out that my Android phone was doing a fine job, as the Pi’s wouldn’t boot! I checked power supplies, formatted and re-formatted the SD cards, used cp rather than a GUI, and still no luck. Rather annoyed, I turned to the SD card compatibility list on the Pi wiki. To my delight the card was compatible, but this didn’t really help me at all.

The Pi wasn’t outputting any video at all, and the SD card light would light on initial boot, but then would die away. This is understandable as the BerryTerminal image is only 30MB. To get around this, I forced HDMI output from the Pi, by editing the config.txt in the root of the card to include the following line:

hdmi_force_hotplug=1

Once the above line had been added, I got video output from the device. However, it wasn’t the output I was looking for. ‘Waiting for eth0 to become available’ filled the screen.

Like any good sysadmin, I immediately googled the issue, with 0 helpful results. I had a look at GitHub, and some code had been added in 2013 to check if the eth0 device was available. This was where my Pi’s were falling over.

By this time I had reached the raspberrypi IRC channel, where a lovely bloke (or woman, I hdmi_force_hotplug=1don’t know!) called ‘shiftplusone’ asked when it was last updated, and that the firmware patches might not be applied to BerryTerminal.

I then copied from the official raspberry pi Github page, the latest versions of ‘start.elf’, and ‘start_cd.elf’.

Lo and behold! Eth0 was recognized, and I had a LDM logon screen.

Lesson learnt here: Don’t assume that different hardware will work.

If you would like a pre-built version of BerryTerminal for a PiB+, you can download it here.

This blog post will show exactly how to set up an LTSP server, running the latest version of Ubuntu, usable by Raspberry Pi thin clients over an Ethernet network, and manage these thin clients using centrally managed software known as Epoptes. This configuration is currently in use in our company setup.

This guide aims to get LTSP running on a network, with thin client access from a Raspberry Pi, as easily as is possible. Please note: This guide assumes that you can confidently install a server with Ubuntu 14.04LTS.

Requirements

Raspberry Pi (B model works best)

512MB+ SD Card

Hardware to install Ubuntu 14.04 LTS on (Core2Duo+ is recommended, and a typical C2D system with 4GB of RAM will easily support 10 users). Note: This example uses a simple system that does NOT require 2 Network Interface Cards, meaning you can use a simple home PC as an LTSP server.

Copy of 14.04LTS

Network with a non-authoritative DHCP server (The LTSP server needs to be the DHCP Server here)

Keyboard/Mouse/Monitor for the Raspberry Pi, it obviously needs to be networked too.

SD Card Reader/Writer

A copy of BerryTerminal: http://www.berryterminal.com/doku.php

Advantages over Pi-LTSP

Isn’t a fat client.

Can run applications that otherwise could not be run on the Pi (Firefox, LibreOffice), whatever you can get working over LTSP that works on your distro..

You can mix this up with normal x86 or x64 clients, so if you have a few old Pentium 4 machines sitting around that work, you can use them too. (128MB of RAM is plenty for a thin client).

Installing and configuring the Operating System

Firstly, we need to install Ubuntu 14.04LTS. Download whichever flavour you would like, for this example I will be using standard Ubuntu 14.04 LTS Server. Note: if you are using the Server ISO, you will need a 64bit machine, as no 32bit server image is available.

I am using the standard Ubuntu 14.04LTS, as it has the bare minimum you need for this project, and anything extra that is needed, can be installed. I am not a fan of removing loads of unnecessary packages once the system is up and running. Make sure to install SSH during setup.

Once you have a vanilla server setup, or whatever flavour you happen to be using, we need to do the following, to ensure the system is fully up-to-date:

:~$sudo apt-get update

:~$sudo apt-get upgrade

Depending on your connection speed to the internet, that could have taken anywhere up to 10 minutes (Thanks ADSL). Once you’ve drained your coffee mug, we’re onto the next step.

Prepare packages that people need

I don’t know what you’re going to need for your users to use, whether it be OpenOffice or whatever, but I’ve included packages that are useful, and that we use here.

:~$ sudo apt-get install gnome-desktop-environment

The above installs Gnome3, which includes loads of packages, and most importantly a window manager, pretty essential for this project, as end users aren’t going to want to use busybox! This install is around 2GB, so you might need to slam down some more coffee while this does it’s thing. Feel free to install your favourite desktop environment. This obviously isn’t needed if your distro already comes with one.

Once you have saturated your bloodstream with caffeine, we now need to reboot the server. So go ahead and do:

:~$ sudo reboot now

You’ll end up with a GUI now, instead of bash or tty3 or whatever. You can either do everything from the terminal emulator on the server, or via SSH, it really doesn’t matter.

Now, onto the installation of the LTSP server:

:~$ sudo apt-get install ltsp-server-standalone

Once the above is done, we need to build the LTSP image, for deployment to our raspberry Pi’s.

:~$ sudo ltsp-build-client --arch i386

Make sure that the above is set, as this ensures that the images are built for an x86 system. I’m not too sure whether this actually matters, because obviously the Pi is neither x86 or x64, and berryterminal uses RDP. But best to make sure.

Please note, this will take a while, as it has to download the dependencies and libraries for the 32 bit version. It’s probably not a good idea to have any more coffee, or you might end up in hospital, so maybe take a minute out and have a glass of water.

Configuring Networking

That took a while. Now, let’s edit /etc/networking/interfaces, and set the network configuration to static, as I forgot to set it to static during install. If you managed to set it manually, congratulations. If you’re not sure, do the following:

vim (use whatever you want) /etc/networking/interfaces, and change the lines:

Now, we need to go and modify the DHCP configuration file to make sure we are allocating the correct IP addresses.

Below is my dhcp.conf. You can see below that I have added in the MAC address of my Raspberry Pi, and given it an IP. You can use this format, or let it assign the Pi, or whatever device an IP from the specified DHCP range. I find it much easier to use statically assigned IP addresses. Also, if you plan on using this in a multi-server environment, then you must specify the server’s MAC addresses here. LTSP has to be the authoritative DHCP server, else it won’t work. If, for some reason, you cannot have LTSP as your DHCP server, you will have to use LTSP-PNP instead.

As you can see above, I have amended the file to reflect the changes I made to /etc/networking/interfaces. I haven’t bothered to change option routers and the like, as this was setup as a VLAN for this tutorial.

Configuring the Raspberry Pi

Now, we need to sort out our Raspberry Pi. Installation of BerryTerminal is trivial, navigate your favourite browser to http://www.berryterminal.com/doku.php, and grab a copy of the .zip. As you’ll see on the site, all you need to do to install BerryTerminal is copy the contents of the .zip onto a FAT formatted SD card.

As you can see on the site, there are some extra options you can set, like auto login. I have shamelessly pasted them below.

Options

You can add the following special options to the file cmdline.txt located on the SD card:

server=1.2.3.4

Specifies the IP-address of the LTSP server.

KBLAYOUT=fr

Sets the keyboard layout (French in this example)

DM_AUTOLOGIN=True LDM_USERNAME=username12 LDM_PASSWORD=password

Automatically logs in to the server.

NOTE: each Berryterminal needs to have its own username.

LDM_LANGUAGE=fr

Sets the language

The options need to be appended on the same line as the existing options.

Now, as the .zip and it’s contents are only 30MB, you can choose the smallest SD card that will fit 30MB!

Create users and install epoptes

Now, we need some users. You can either use something like NIS, to export the users to the LTSP server, if you have a central file server using NFS for example. That is a lot of work, and if there is interest, I will write another tutorial on how to do this.

For now, I am going to create some local users, and make sure that they can log on, and that they can be managed by epoptes. (I’m sure you can actually add users to a *nix system, but hey!)

:~$ sudo adduser mrblobby

Now, obviously we have a user called mrblobby, once you’ve given him a password and the like.

Epoptes provides lots of nice functionality, like grouping users, remote viewing and control via VNC, along with network booting, message sending and so on. It’s a fantastic piece of software in my opinion.

So, to install this beauty, we need to do the following on our LTSP server:

:~$ sudo apt-get install epoptes-client

This is actually quite confusing, well at least it was for me when I first set this up. The client needs to be on whatever device you are trying to manage, and the epoptes server, called epoptes, needs to be on whatever you are going to manage the LTSP server from. So, in our setup here, at Severn Delta, as the lone sysadmin I have the server package installed on my machine, and the client on the LTSP server, so that I can manage our users. I suppose you could install it onto a server used for managing the LTSP server, or you could install it onto the LTSP server, then manage it from a thin client.

So now we need to install the server:

:~$ sudo apt-get install epoptes

And add a user to the group that is authorised to use the program:

:~$ gpasswd -a username epoptes

Finally, we will need to rebuild the LTSP image, so that it includes epoptes-client.

:~$ sudo ltsp-update-image

Does it work?

Plug your raspberry Pi into the network, attach a keyboard and mouse. Finally, insert the SD card, and insert the power. If all is well, you will see the IP being assigned, and the image being downloaded, followed by you being spat out at a LTSP screen, at which you can log on.

Conclusion

If all is well, you now have amazingly cheap thin clients. I’d recommend looking into VESA mountable cases, which have SD covers on them, so naughty people can’t steal your SD cards when you put these into production environments.

If there is interest, I might write some more tutorials on the following LTSP related topics:

Locking down Gnome3, so that users do not have access to programs such as a terminal emulator, or a restricted program.

As anybody who follows uzERP and Severn Delta will know, I’ve used Linux everywhere (work, home, netbook, laptop) for many years and am a big fan. I’ve been wondering what to do about updating my work machine for a while as I have been running a pretty old distribution, and many installs/uninstalls of tools were taking their toll on the system. With the advent of Gnome3 and Unity, both of which I dislike, I also had some choices to make about desktop environment. Having used XFCE and Gnome (version 2) for many years I also wanted to give LXDE a whirl to see if it was faster and could provide a lightweight business focused desktop for a typical SME ‘power user’ (like me!!).

I need a lean and fast system and have a minimal set of requirements in terms of ‘apps’ because most of what I do at work is web based. I also hate unnecessary clutter, being a ‘retentive-tidy-freak-accountant’* – I therefore decided to start from scratch using Ubuntu 12.04 and LXDE as a base rather than installing a ‘regular’ distribution.

The initial install was done from the Ubuntu Alternate CD – by pressing F4 you get get a minimal install of a command line environment on which you can build. Once this base install completed and I got a command prompt I proceeded as follows:
sudo apt-get install xorg lxde-core lxappearance lxde-icon-theme cups
sudo apt-get install synaptic gdebi gdm chromium-browser leafpad epdfview xarchiver gnome-system-tools

This installs a very basic LXDE desktop environment as follows

X server to run the desktop

lxde-core, lxappearance and icons

cups printing system

package manager

package installer

GDM graphical desktop manager

web browser

leafpad text editor

pdf viewer

lightweight archive manager

system tools (add users, printers etc)

Having got my basic install I just need need a selection of programs and a bit of manual configuration. So….

The above list is not exhaustive, obviously. I’ll play with the system installing things as I go (things like Dia for drawing diagrams, perhaps). But…. I now have all I need for my day to day work at Severn Delta – no clutter, no games, no music players, photo viewers or unneccesary eye-candy. Its blazingly fast and, so far, I’m very happy with what I’ve ended up with.