Tag Archives: Raspberry Pi

Logging footfall counts with a Raspberry Pi and camera – ethical considerations

Here at Cranfield University we are putting in place plans related to the new ‘Living Laboratory’ project, part of our ‘Urban Observatory’. This project sits within the wider UKCRIC initiative, across a number of universities. Of the many experiments in development, we are exploring machine vision as a means to provide  footfall counts of pedestrian traffic in parts of the campus. This blog provides summarises some of the ethical considerations relating to this work.

An important early part of this project involves preparing, submitting and securing ethical approval for the planned work. In the first instance we are running an experiment in a particular campus office area. Before commencing any technical work, a full approval case has to be prepared and submitted for assessment.

In the case of this experiment, we are intending to log only a count of pedestrian movements, with no personally identifiable imagery captured. Informed written consent is obtained from all residents of the office area, and signage put up for visitors, see below. The case outlining these intentions is drawn up and submitted.

These matters are raised here as a precursor to the technical description to follow, as IoT projects require careful consideration of privacy matters.

Note, image above is shown with the specific details removed

Connecting a Raspberry Pi to eduroam wifi

Raspberry Pi connected to eduroam wifi

Connecting to eduroam

One of the things we want to do here at Cranfield University, is to connect Raspberry Pi computers to the University WiFi network – called ‘Eduroam’. The Eduroam system is used by all universities in the UK. However, the built in WiFi on board the new Raspberry Pi 3 doesn’t seem to connect to the Eduroam WiFi network on campus, out of the box. Clicking on the WiFi icon in the top right of the Pi’s desktop shows the eduroam network as a greyed out option. On the Cranfield campus, the local networks ‘Cranfield Web’ and ‘Cranfield Setup’ are both available to join. Here are some instructions on how to connect the Pi to the Eduroam WiFi network.

Select Cranfield Web/Setup, open a browser and go to the web address http://cat.eduroam.org. You may be prompted for a username and password, your Cranfield University username and password should be supplied here.

Once at cat.eduroam.org, select Cranfield University from the list of institutions when prompted and then press the button titled ‘Linux’. This should download a small script which you should run. You can either run this by clicking the file once it has downloaded at the bottom of your browser or navigating to its location within your filesystem and running it from there.

If the script does not initially run (but simply opens in a text editor), you may need to add executable permissions to the downloaded script. Navigate to the location of your script in a terminal window and run the command:

sudo chmod u+x <filename>

When the scripts runs it will prompt you with some dialogue boxes that ask for your eduroam username and password. Your eduroam username should take the form <username>@cranfield.ac.uk (where <username> is your regular Cranfield username) and you should use your regular Cranfield password.

The script will eventually tell you that it was unable to update your network settings, however the important config we need will be stored in a .cat_installer folder in your home directory. Using a terminal window, navigate to this folder:

cd .cat_installer

 You will see a file cat_installer.conf. The contents of this file need to be copied and pasted into the file wpa_supplicant.conf which resides in /etc/wpa_supplicant/. Navigate to this folder:

cd /etc/wpa_supplicant

You will need to edit the wpa_supplicant.conf file using superuser permissions. You can edit this file using the text editor nano:

sudo nano wpa_supplicant.conf

Using your right mouse button (ctrl+v doesn’t work here), paste in the config that you copied earlier at the bottom of the file.

Save this file (in nano, press ctrl+O), then exit (ctrl+x).

You will now need to restart the system:

sudo shutdown –r now

When the system boots back up to desktop again, you should now be connected to eduroam. Note, clicking on the wifi icon in the top right of the screen will show that you are connected to eduroam, but it will still be greyed out. This is fine.

Be aware that this configuration will have your password stored in plaintext in the wifi configuration file. It is, therefore, essential that access to your Pi is configured with a secure password as anyone able to the sudo command on the Pi will be able to read this file. If you are planning for several people to have access to a terminal/ssh on your Pi, it is recommended you connect the device to the network via a wired ethernet connection.

This tutorial is one of the following set of related Raspberry Pi tutorials, in order:
1. Unboxing the Raspberry Pi 3 – Pi Society
2. Raspberry Pi 3: Hello World – Pi Society
3. Raspberry Pi 3: Operating LEDs – Pi Society
4. Making the Raspberry Pi work, the next steps – Pi Society
5. Connecting a Raspberry Pi to eduroam wifi

Making the Raspberry Pi work, the next steps – Pi Society

There is a lot of interest in the amazing Raspberry Pi 3 computer here at Cranfield University. Once you have the basics for the Raspberry Pi in place, there are a few tips and tricks you can follow to make the Pi work better for you, explained below. The assumption here is that you already have the Pi connected up to a monitor, and have a keyboard and mouse plugged in and are running Jessie Raspian (if not, see our earlier Pi tutorials). the topics covered here are:
Setting a system password | Getting WiFi running | Accessing the Pi from another computer | Moving files to and from the Pi from another computer – scp | Installing and updating software on the Pi | Setting aliases | Learning Python

Setting a system password

The default account on the Pi is in fact username ‘pi’, and there is no password for the account by default. It is good practice to set a password, particularly once you activate WiFi for the Pi. To do this, Select Menu > Preferences > Raspberry Pi Configuration > System. Select the password option and enter in a secure password.

While you are at this dialogue box, you can explore the other options there – for example, under ‘Localisation’ you can set the Pi’s timezone appropriately.

Getting WiFi running

WiFi on the Pi is very straight forward if you have a home router running WPA security. At the graphical interface, in the op right corner of the screen is the WiFi icon. Right mouse click the WiFi icon and select the first ‘WiFi Networks Settings’ option. In the Network Settings dialogue, in the ‘configure’ drop-down, select ‘SSID’ and search for your router, select it and press OK. If there is a WiFi password required, select the WiFi icon again, locate the connection you just made in the list and double click – a dialogue appears for you to enter in the password. Once done, hopefully the connection is made and you will be online.

To get the Pi to connect wirelessly to the campus WiFi network ‘EduRoam’ is rather more tricky – see https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=86253
Using the Jessie graphical user interface of the Pi, you should be able to follow the same procedure to get the Pi online with Eduroam. If you intend to do this however, you must ensure that users all have passwords set, and that the hostname is something other than ‘pi’!

Accessing the Pi from another computer

To start with you have to connect a monitor and keyboard/mouse up to the pi to connect to it. However, ultimately you may want to have it running on its own, and so then be able to connect to it from a different computer – on the command line, or graphically.

Assuming the Pi is using WiFi and is online, find out what its IP address is. To do this, you can either consult the WiFi router’s web console to look for its connected clients, or you can type:
sudo ifconfig
In a home WiFi situation, the IP address will likely be something like ‘192.168.1.nn’ (e.g.

From your other computer (e.g. a PC or Mac), you can now run an ‘ssh‘ (secure shell) client. To do this, on the PC you might use the excellent freeware tool ‘putty’; on a Mac you can fire up the terminal and at the prompt enter ‘ssh <i><ip number=""></ip></i>‘. Make the connection by incorporating the pi user name (which by default is ‘pi’) into the IP address, thus in a mac terminal window for the user name ‘pi’, you would type:
ssh pi@

Sometimes accessing via the command line is just not enough, and you may want to run an app with a graphical interface from another computer. If you use the secure shell (ssh) to log in to the Pi, you may be able to carry the ‘X-windows’ session over to the computer using the ‘-X’ parameter, thus:

ssh –X pi@

On a Mac running Sierra, you may have to run with a ‘-Y’ instead, (assuming you have Quartz installed):

ssh –Y pi@

On Windows computers, you can install and use Xming for the X-windows, and then use putty as noted above for ssh sessions. Putty has a dialogue tick box option to carry X11 over to the local session.

To test this works, install the standard set of X11 apps, then run say xclock, thus:

sudo apt-get install x11-apps xclock

All the above can be a bit fiddly – and a much easier method is to use a VNC (Virtual Network Computing) server. In former times to do this you would install a software package called ‘tightvncserver’ – and there are lots of instructions out on the web to do this – and you can still do this if you wish. However, as from Sept 2016, the Raspberry Pi 3 now includes a VNC server by default, from RealVNC – (see https://www.realvnc.com/docs/raspberry-pi.html). Although installed it is not activated by default. To activate it, select Menu > Preferences > Raspberry Pi Configuration > Interfaces. Ensure the VNC tick box is Enabled and then reboot the Pi. From now on, VNC Server will start automatically whenever your Pi is powered on.

Now, on the computer you want to connect to the Pi, you will also need to install the RealVNC viewer. Visit ‘https://www.realvnc.com/download/viewer/‘, download and install the appropriate viewer. Note you will need to know and enter the IP address of the Pi, as well as your account and password.

Moving files to and from the Pi from another computer – scp

Very often you will want to copy files to and from the Pi – here’s how:

If you have the ssh tools running as above, you can just as easily use the ‘secure copy’ command ‘scp’ to move files to and from the Pi from your controlling computer, as described at https://www.raspberrypi.org/documentation/remote-access/ssh/scp.md.

Copying a file from your computer TO the Pi

scp myfile.txt pi@

or to copy the file to a specific folder:
scp myfile.txt pi@
this copies the file to the /home/pi/myfolder/ directory on your Raspberry Pi

Copying a file from your Pi TO the computer

scp pi@ .

a better strategy is to install a graphical tool with as WinSCP to help you copy files to and from the PI.

Installing and updating software on the Pi

You will need to keep the software installed up to date on the Pi. Being open source, it seems that there are constantly updates that need installing – so this is a procedure that should be run through on a regular basis. The tool needed to do this is called ‘apt’.

Open a terminal and enter (‘apt-get’ is all one word, with no spaces)
sudo apt-get update
sudo apt-get upgrade
This can take a little while – don’t interrupt until it is finished, and keep an eye on it as it may ask questions needing a response. The apt command is described fully here.

This command line tool is very powerful and can be used to install software as well as keep it updated. For example, to install the package ‘curl’, you type:
sudo apt-get install curl

If you need to update the kernel software too, you can type:
sudo apt-get install rip-update sudo rip-update

Curl is a useful command-line tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP).

If you prefer a software package manager tool with a graphical interface, you can try ‘aptitude’:
sudo aptitude

Setting aliases

Using the Pi, you quickly realise that the command line, using the ‘terminal’, offers you powerful and efficient command tools for configuring and running the computer. Did you know you can set up shortcuts to help make the use of these commands even more efficient. An example we shall use here is to set an alias of ‘ll’ to run the full command ‘ls –al’ – a little shortcut that speeds up making full file listings on the screen – so that then, every time you type ‘ll’ the command ‘ls –al’ gets run.

Each time you start a terminal session, a configuration file in your home folder named ‘.bashrc’ is read – and shortcuts can be placed into this file. If you have a look in this file (it is a plain text file) you can actually see that there is a line in it making a call to incorporate any aliases defined in a companion file called ‘.bashrc_aliases’. Note this latter file doesn’t exist by default, so enter the following:

nano .bash_aliases

This starts up the text editor ‘nano’ (any text editor would do the job as well!) and creates the file – now enter a new line in it:
alias ll=’ls -al’

Save the file out and exit (in nano this is Ctrl+O, Ctrl+X)

Now close the terminal window (type ‘exit’). Next time you run terminal session, type ‘ll’ to see the file listing – try and see.

Be sure to visit https://www.raspberrypi.org/ to learn more about these amazing machines.

Learning Python

The Pi offers a fantastic means to learn programming – using languages such as Python. There are so many Python tutorials out there that we don’t write our own here. However, here are a few guidelines to get you up and running on the excellent quick Python tutorial from Magnus Lie Hetland. This is a good starting point for anyone who has done a spot of coding before as it is short, sweet and to the point!

The tutorial is online here

Firstly you need a decent editor (did you know there were so many!). Sadly, our favourite editor PyCharm is not yet posted to the Pi.

At the command line you can use the editor ‘nano’:
nano myfile.py

Better still use a graphical editor – assuming it is installed, use say ‘Leafpad’
(the ‘&’ symbol means run editor as a background process):
leafpad myfile.py &amp;

Best of all, use the Idle3 editor on the Pi:
idle3 myfile.py &amp;

Secondly, run the code with the python command as below, (or in Idle – just press ‘F5’ to run the source code).
python myfile.py
Then you can follow Magnus’ examples through! For example, copy and run this code:

<code># Exercise 2 </code><br><code># Part 1: </code><br><code>print ("Part 1\nThis program continually reads in numbers\nand adds them together until the sum reaches 100:") total = 0 goes = 0 while total &lt; 100: </code><br><code># Get the user's choice: </code><br><code>number = int(input("enter a number &gt; ")) total += number goes += 1 print ("The sum is now", total, "and it took you", goes, "turns.") </code><br><code># Part 2: </code><br><code>print ("\nPart 2\nThis program receives a number of values\nand prints the sum") total = 0 number = int(input("enter the number of values to enter &gt; ")) for counter in range(0, number): # Get the user's choice: number = int(input("enter a number &gt; ")) total += number print ("The total was", total)</code>

This tutorial is one of the following set of related Raspberry Pi tutorials, in order:

  1. Unboxing the Raspberry Pi 3 – Pi Society
  2. Raspberry Pi 3: Hello World – Pi Society
  3. Raspberry Pi 3: Operating LEDs – Pi Society
  4. Making the Raspberry Pi work, the next steps – Pi Society
  5. Connecting a Raspberry Pi to eduroam wifi

Raspberry Pi 3: Hello World – Pi Society

Some of the students here at Cranfield University, are involved in our new ‘Pi Society’ – a gathering of folk with an interest in the amazing new Raspberry Pi’s and all that can be done with them. This video is a guide to the Raspberry Pi kits that are provided, from the Pi Hut, comprising the Pi kit itself, plus the fantastic Cam Jam sensor edu-kit.

In this second tutorial, we set up a Raspberry Pi 3 computer, configure the operating system Jessie, and develop the obligatory ‘Hello World’ python programme.

This tutorial is one of the following set of related Raspberry Pi tutorials, in order:
1. Unboxing the Raspberry Pi 3 – Pi Society
2. Raspberry Pi 3: Hello World – Pi Society
3. Raspberry Pi 3: Operating LEDs – Pi Society
4. Making the Raspberry Pi work, the next steps – Pi Society
5. Connecting a Raspberry Pi to eduroam wifi

Unboxing the Raspberry Pi 3 – Pi Society

Some of the students here at Cranfield University, are involved in our new ‘Pi Society’ – a gathering of folk with an interest in the amazing new Raspberry Pi’s and all that can be done with them. This video is a guide to the Raspberry Pi kits that are provided, from the Pi Hut, comprising the Pi kit itself, plus the fantastic Cam Jam sensor edu-kit.

In this first tutorial, we set up a Raspberry Pi 3 computer, and the CamJam Sensor kit. These materials were purchased in the UK from the Pi Hut (http://thepihut.com). In this tutorial, we unpack and sat up the fantastic new Raspberry Pi 3 kit, together with the Cam Jam sensor kit – offering a superb platform to learn more about micro computers, programming, sensors and the Internet of Things.

This tutorial is one of the following set of related Raspberry Pi tutorials, in order:
1. Unboxing the Raspberry Pi 3 – Pi Society
2. Raspberry Pi 3: Hello World – Pi Society
3. Raspberry Pi 3: Operating LEDs – Pi Society
4. Making the Raspberry Pi work, the next steps – Pi Society
5. Connecting a Raspberry Pi to eduroam wifi

Cookbook – Building a Layar Augmented Reality Server on Raspberry PI

Raspberry_Pi_LogoPurpose: Augmented reality is an exciting new area of computing, with many ‘apps’ available. On this Cranfield University site, we will describe building a server for the popular ‘Layar’ app (http://www.layar.com/), builds on the earlier GeoThread project to Build a LAMP server on the Raspberry Pi computer. The Raspberry Pi is an amazing low-cost computer (see http://www.raspberrypi.org/). The Layar server uses PHP, MySQL and Apache for serving up Layar ‘POI’ (point of interest) objects as a JSON (http://www.json.org/) data stream from the MySQL database.

The mobile phone and tablet ‘layar’ app allows you to connect to an augmented reality server to look at points of interest etc in the world around you. But what does the data the app ‘consumes’ look like? In this tutorial we use the Raspberry Pi to serve up Layar data as a JSON data stream.

This assumes you have a Raspberry Pi, installed with Apache, MySQL, PHP and PHPMyAdmin, plus vsftpd as per the earlier instructions. Get filezilla and ssh terminal working (or use the tightvnc service).

These notes are really to support and extend the basic ‘Layar’ tutorial at:


Download the layar sample source code (held in a zip file) at:


Unpack the files. Note that we had to undertake this process manually in File Explorer, due to the format of the zipfiles not being accepted by the Windows ‘zip extract’ tool.

There are several parts to the tutorial files that you receive – an SQL script to build and populate the database, and then a number of PHP scripts.

If you are likely to load and reload and reload the SQL script – inevitably one does, then consider editing the SQL script to add these lines above each of their respective database table definitions (thus allowing you to rebuild the tables as required).


Building web services always leads to a few errors until you fix the problems. We find it helps to turning on Apache and MySQL logging on the Raspberry Pi until such inevitable snags are removed. To do this, edit the configuration files thus:

MySQL Logging

To turn on the MySQL logging, edit the MySQL configuration file thus:

cd /etc/mysql/my.cnf
sudo nano my.cnf

then, uncomment the lines:

#general_log_file = /var/log/mysql/mysql.log
#general_log = 1

Now restart MySQL and the logging operation is commenced.

sudo service mysql restart
tail –f /var/log/mysql/mysql.log

Reverse this to stop logging once all is working correctly.

Apache Logging

First, inspect the logfile:

sudo more /var/log/apache

or better still to see only new lines as they appear in (are being written to) the logfile

sudo tail –f /var/log/apache2

Establishing the database

The database is created and administered using the phpmyadmin tool. Create a new database called


Run the supplied Layar example SQL script (use the IMPORT button for the database in phpmyadmin) to create and populate the two database tables.

Create a new db user ‘layar’ (password ‘layar’ – or whatever you wish) and add privileges ‘select, insert, update, delete’ rights to the ‘layar_custom’ database on (you can change the IP later for a public website address if you want to go that far).


Create a new folder in the webserver root called ‘layar’ and copy over the php scripts – e.g. to ‘’

Adjust file permissions for web access (chmod 755 for the folder, 554 for files, owner chown pi)

sudo chmod 775 /var/www/layar
sudo chmod 554 /var/www/layar/*

Next, you need to customise the ‘config.inc.php’ file to enable your specific database credentials. Edit the file and add in your details, thus:

define('DBHOST', '');
define('DBDATA', 'layar_custom');
define('DBUSER', 'layar');
define('DBPASS', 'layar');

The files you uploaded, such as “” have a call that loads in the configuration file above only once. You may find you need to disable this until the tool works. In which case, edit the require code thus:


Changing from ‘require_once()’ to ‘require()’ means the code is read in every time you refresh the browser. Once all works, put it back as was.
Running the Application

From your home networked laptop/pc browser, run You may well need to debug the whole configuration until all error messages are resolved – this is where using the apache and mysql logs can really help bugfix. If you encounter a ‘500’ error, this is likely to mean the MySQL user privileges are an issue. Also note the require_once() / require() issue noted above. Once it works, some ‘application programming interface’ API calls can be tried. Note the Layar name is ‘layername’ (as recorded in the MySQL table ‘Layar’).

Example Rest API calls;countryCode=NL&amp;lon=4.9342500000&amp;userId=6f85d06929d160a7c8a3cc1ab4b54b87db99f74b&amp;developerId=4441&amp;developerHash=26ec094e19db2c4a82ebafa200ea2a5e87a7d671&amp;version=4.0&amp;radius=2500&amp;timestamp=1286357071952&amp;lat=52.3741180000&amp;layerName=layername&amp;accuracy=100;lon=4.9342500000&amp;userId=ed48067cda8e1b985dbb8ff3653a2da4fd490a37&amp;radius=2500&amp;lat=52.3741180000&amp;layerName=layername&amp;accuracy=100

This returns a stream of ‘JavaScript Object Notation’ JSON data, e.g.

{"layer":"layername","hotspots":[{"id":"geo_1","imageURL":"http:\/\/custom.layar.nl\/Layar_banner_icon.png","anchor":{"geolocation":{"lat":52.374118,"lon":4.93425}},"text":{"title":"The Layar Office","description":"The Location of the Layar Office","footnote":"powered by Layar"}}],"errorCode":0,"errorString":"ok"}

API Documentation

Request: see http://www.layar.com/documentation/browser/api/getpois-request/

Returns: see http://www.layar.com/documentation/browser/api/getpois-response/


Once this works and your setup is creating valid JSON data you can turn off all the debugging fixes. These instructions are just the start. Taking things forward, you would now need to place the server in the public domain and reveal (register) the service to your Layar account server for registered layars.