Tag Archives: WiFi

Matters relating to WiFi networks and their connectivity

Using multiple WiFi networks with a Raspberry Pi

Here at Cranfield University we use Raspberry Pi computers for a number of applications, such as monitoring environmental sensors and processing data. The devices get moved around the campus and need to work across multiple WiFi networks with ease ad without the need for reconfiguration. Here is how this is done (make backups of the files before editing!).

First, edit file /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Second, edit file /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary wired network interface
iface eth0 inet dhcp

# The wireless network interface
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

# Default
iface default inet dhcp

Reboot the Pi after the edits. This approach uses DHCP for connecting to the network.

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

Cookbook – Configuring WiFi on Raspberry PI

Raspberry_Pi_LogoPurpose: Following on the earlier Raspberry Pi posts on this Cranfield University site, this cookbook explains how we got the Raspberry Pi to run on a network using a WiFi USB dongle.

Although the default setup for the Raspberry Pi allows wired ethernet connections out of the box, it is useful to enable the Pi to work with WiFi. The first thing you need is to buy a suitable WiFi USB hardware dongle. Before purchasing this, be sure to visit the peripherals site at http://elinux.org/RPi_VerifiedPeripherals. Select one of the ‘Working USB WiFi Adapters’. We chose the inexpensive ‘USB Wifi Adapter for the Raspberry Pi’, sold by a number of vendors such as the ‘Pi Hut’ (http://thepihut.com/products/usb-wifi-adapter-for-the-raspberry-pi) and Amazon, etc.

Once you have this, insert into the Pi and boot up. When running, we followed the excellent instructions here (http://www.raspberrypi-tutorials.co.uk/set-raspberry-pi-wireless-network/). First, we see what devices are recognised on the USB port:


This listed our adapter as:

Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

Although all drivers are supposed to be pre-loaded, even if you have the latest ‘Wheezy’, it is good practice to update the system to the latest set of drivers. To do this, type:

sudo apt-get update
sudo apt-get install

Once finished you can search for the new device in the APT package cache. We used this command:

sudo apt-cache search ralink

The last word is the actual search string, here ‘ralink’. Before this worked, we had tried a few other strings like ‘RT5370’ – which had returned nothing. Note there is no ‘-‘ before the word search! Anyway, once we tried ‘ralink’ the search worked and it reported:

firmware-ralink – Binary firmware for Ralink wireless cards

Now we installed the latest drivers for our wifi key, thus:

sudo apt-get install firmware-ralink

Once this whirred away and finished updating the drivers, we rebooted the computer:

sudo shutdown -r now

Once the Pi was back up and running, we made sure the USB key was recognised:


Hopefully you will see the ‘wlan0’ interface being listed.

The next step is to configure the wireless key to work with the router. There are  few options here. First you can manually configure everything, and secondly you can use the ‘WiFi Config’ tool on the Pi graphical login screen – as shown. The latter is certainly the easiest option.

Pi_WiFi_ConfigRunning this config tool, the programme immediately spotted the ‘wlan0‘ adapter. Selecting ‘Scan’ enabled the programme to locate the SSID of the network router to connect to. Under the ‘Manage Networks’ tab, we then ‘edited’ the connection to add in the relevant security connection information (eg. WEP, WPA keywords etc ). The first ‘Current Status’ tab then showed a successful connection had been made to the router and an IP address successfully allocated by the router’s DHCP server.

Under the bonnet
So far so good – a working WiFi connection. However, we are using the Pi as a ‘LAMP’ database server (see http://www.geothread.net/building-a-lamp-server-on-the-raspberry-pi-computer/). A dynamic IP address is therefore not ideal if we want to connect to say the Pi MySQL server instance from other devices (e.g. iPhone). We therefore wanted to establish a ‘static’ IP address for the Pi and to do this we need to dive under the bonnet. First move to and edit the network configuration file (‘nano’ is a text editor, the ‘sudo’ runs nano as the root user):

cd /etc/network
sudo nano interfaces

This interfaces file controls access to the various networking interfaces the Pi can use. There is a LOT of discussion on the web of different configurations people use – with varying degrees of success reported. Editing this file must be undertaken carefully – we certainly suggest taking a backup first! To cut a long story short, and following a fair bit of frustration, the following configuration file worked for us:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary wired network interface
auto eth0

# The wireless network interface
auto wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

# Default connection
iface default inet static

Note the fixed IP address we wanted was on our local subnet. Note also the ‘manual’ setting of the wlan0 network. This setting ensures the ‘/etc/wpa_supplicant/wpa_supplicant.conf’ file (created by the WiFi Config tool above) is read correctly. Lastly, the use of the default setting at the end for the IP address ensures that if the Pi connects, either by wired or wifi link, it still has the same fixed IP address. The original ‘dhcp’ setting line was removed. Note finally that blank lines are ignored and that ‘#’ symbol denotes a comment.

Configuring networks is clearly a complex subject, this post just highlights how we got ours working. There are lots of other examples online.

Formal network interface documentation is also at http://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_basic_syntax_of_etc_network_interfaces

The Pi itself also has some standard configuration file examples, worth looking at,  see ‘/usr/share/doc/ifupdown/examples/network-interfaces’, but the file is ‘gzipped’ up and needs unzipping to view it first, thus:

cd /usr/share/doc/ifupdown/examples
sudo cp network-interfaces.gz network-interfaces_examples.gz
sudo gunzip network-interfaces_examples.gz
sudo more network-interfaces_examples

We hope this helps you get your WiFi running smoothly!