Software
On most computers with a GUI, configuring WiFi is easy. However, on a headless Linux box—often a Raspberry Pi in my case—it often strikes me as a painfully baroque task.
Part of the problem is simply that Linux’s WiFi stack supports a very wide range of different configurations, but I just want to connect to a particular WiFi network with a given password. As is often the case, it’s actually very easy to do this, once you’ve worked out what you don’t need.
Only two files matter: /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf.
/etc/network/interfaces
Add the definition for wlan0 so the file looks like this:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
/etc/wpa_supplicant/wpa_supplicant.conf
This splendidly named file contains the WiFi configuration data. I’m happy to rely on the defaults, but obviously I need to specify the name (SSID) and password (PSK) for the WiFi network I want to use. My file looks like this:
network={
ssid="NETWORK NAME"
#psk="Banana"
psk=757474b54c7f338f5cfb2db98735a36bcf893c0ec2193f117d53884d84510bdc
}
You might reasonably guess that I’m supplying the PSK (pre-shared key) twice, and you’d be right. This is simply because the documentation claims it makes things a bit faster.
Generating the file is easy:
$ wpa_passphrase "NETWORK NAME" BananaBanana |
sudo tee /etc/wpa_supplicant/wpa_supplicant.conf
Raspberry Pi Hardware
Sadly the Raspberry Pi doesn’t come with Wi-Fi. However it does have USB ports, and USB Wi-Fi adaptors are cheap. In the UK, Amazon sell the Edimax EW-7811UN1 for less than ten pounds. It seems to work reliably if you just plug it into the Raspberry Pi’s USB socket: no hub required.
Six months’ ago, we had to fettle the kernel drivers to make all this work, but in the 2013-02-09 release of Raspbian it all just works.
References
- 1. http://www.amazon.co.uk/Edimax-EW-7811UN-Wireless-802-11b-150Mbps/dp/B003MTTJOY/