Home and Links
 Your PC and Security
 Server NAS
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Using Raspberry Pi on a WiFi network

Pi WiFi

What WiFi 'dongle' ?

As with all things Pi, you need to get one that is both 'compatible' with the Pi's implementation of USB = especially the current limit - approx 200mA - as well as having 'built-in drivers. Fortunatly, the Model A (and B+) is more flexible when it comes to WiFI dongles (supporting most Realtek RT5370, RTL8191S and some rt2x00 based dongles) whilst the Model B only supports RT-5370 and some Realtek RTL8191S based devices. For a more detailed list of actual tests, see Mikronauts.com - note, in particular, that the TP-LINK and TL-WN725N don't work, not even when connected via a powered hub

Image Almost all WiFi dongles, whatever the 'name', are built around one of the Realtek chipsets.
So when you pay £20 (or more) for one of the 'Pi compatible' branded (Belkin or similar) devices, at least 50% of that price is for the name printed on the box you throw away.

I purchased a 'USB 2.0 WIRELESS 802.11N' mini-adapter from a UK seller on eBay (a bargain at less than £5 (inc P&P) each, under half of what CPC was asking). I made sure to choose one advertised as 'Raspberry Pi' compatible.

When it arrived I discovered to my delight that it was based on the Ralink RT-5370 chip, the drivers (& firmware) for which are already 'built-in' to Raspbian Wheezy 2012-08-16 & later. Those using some other build, can 'fetch' the required drivers from the Raspberry Pi on-line 'repository' using the command :-
sudo apt-get install firmware-ralink.

NOTE - multiple users report problems with the Ralink RT-2800 chipset, so you might want to avoid that particular version, although the (earlier) RT-2571 appears to work OK (as does the 8188CU)

So all you have to do is plug the WiFi adapter in and (after the Pi crashes and reboots) check it can be seen OK (by using the 'ls usb' command) :-

Typical output (model B) :-
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

How do I setup the WiFi ?

A minimal system will be a Model A with the WiFi plugged into it's single USB socket. However, you have to make a few tweaks (at the very least, enter your WiFi password) so start up the Model A with a keyboard, enter the config. data and then switch to the WiFi dongle.

It is also possible to setup on a Model B and then move the configfured SDHC card to the A ...

With current release of Raspbian, to enable WiFi you only have to do the following :-From the console (or PuTTY window), edit the network properties of the Raspberry:sudo nano /etc/network/interfacesNow add these lines at the end of the file (or change existing lines to match these):allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "YOUR NETWORK SSID" wpa-psk "WIFI PASSWORD"(Fill in the SSID and password for your WiFi network)Power off, plug in the WiFi dongle, and see if it correctly connects to your WiFi network.

On the Model B, it is also possible to set up WiFi via a GUI - just download the latest version of Raspbmc and install the "Network-Manager" add on. You can configure the WiFi network via "Network-Manager" with a few mouse clicks (this method adjusts the 'wpa_supplicant.conf' file, used as the 'default' by the Pi and allowing it to connect to a non-password protected 'hot spot' automatically)

Below shows how to have the Pi 'log in' to your password protected WiFi LAN using DHCP to obtain an IP Address. If you are using a Laptop PC as an 'Access Point', then (unless you are running a DHCP Server on it), you will need to further edit the Pi's network 'interfaces' file to ensure the 'correct' AP (SSID) is chosen and a (fixed) IP Address is assigned :-

sudo nano /etc/network/interfaces

To activate the WiFi dongle, change the contents from :-
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

To :-

# loopback auto lo iface lo inet loopback # ethernet iface eth0 inet dhcp # WiFi allow-hotplug wlan0 auto wlan0 iface wlan0 inet dhcp wpa-ssid {your SSID} wpa-scan-ssid 1 wpa-psk {your WPA PSK password} # wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf # iface default inet dhcp
Note that the 'wpa-scan-ssid 1' option in above should instruct the Pi to 'connect' even if your SSID is not being 'broadcast'

A2. If you want to assign a fixed ('static') IP address for your Pi, comment out the line :-
iface wlan0 inet dhcp

and add the following :-

#iface wlan0 inet dhcp
iface wlan0 inet static
address {ip address eg}
netmask {sub-net mask eg}
gateway {default gateway eg}

A fixed IP address must be chosen so that it does not 'clash' with another computer (i.e. it must be some address that can never be issued by your Router's DHCP). So either choose something 'outside' the DHCP range OR 'lock' that address to the Pi MAC number in your Router

What is the wpa_supplicant.conf file ?

This appears to be the 'password' file used by the GUI Network-Manager utility to set-up the WiFi. It will contain something like the following :-

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

ssid="{your SSID}"
scan_ssid={1/2. 1 if broadcast, 2 if hidden}
proto={RSN/WPRSN is WP2, WPA is WPA1}
key_mgmt=WPA-PSK {or WPA-EAP if you are using 'enterprise' key management}
psk="{Your PreShared Key}"
pairwise=CCMP TKIP {CCMP means WPA2, TKIP WPA1. Both means accept either}
auth_alg=OPEN {required for WPA or WPA2. The other options are SHARED & LEAP}

Since we 'comment it out' (in network 'interfaces' file, above) it's contents are irrelevant

How do I restart WiFi ?

After making config. changes, to avoid having to power-cycle (or reboot) the Pi, you can restart the Pi's network interface using the following command :-

sudo /etc/init.d/networking restart

Alternatively you can use the commands sudo ifdown wlan0 to 'turn off' WiFi and sudo ifup wlan0 to turn it back on

Note: The Wi-Fi connection should start up automatically when you 'power-on' the Pi.

What problems might I encounter ?

NOTE. The Pi may not be able to find & log-into your WiFi network automatically if you 'Hide' your SSID

You can use the command 'ifconfig wlan0' or 'iwconfig wlan0' to check that the WiFi dongle is working, picking up an IP address and 'logging in' to your WiFi. You can also check that the Pi is 'seen' by your WiFi Router (using your PC) and 'ping' it from your PC, after which you can 'connect' from a PC using a 'putty' terminal window

A1. Whilst almost all problems are due to the power supply, on the Model B, some reports suggest that having both the Ethernet and WiFi running at the same time can lead to 'Pi command confusion' :-) If you run into this, try unplugging the Ethernet cable (and rebooting) before blaming the power supply

A2. If your keyboard starts 'playing up' and/or you get nothing but 'mysterious error messages' from the WiFi, most likely it's the power supply. Your '5v' power-supply needs to be rated at 1A+ and output 5.2v - alternatively, you should move the WiFi dongle to a powered USB hub

You can only draw up to 150mA from the Pi USB socket before the main 'polyfuse' and USB 'reverse protection' diodes drop the voltage from 5.0v to 4.7 or less .. and not a few WiFi 'dongles' get very 'upset' at 4.7v (especially as the voltage drops further when they start using more power to transmit data over the WiFi LAN)

A3. Model A users should be especially aware of power issues. Often you can 'get away' with an 'un-powered' hub when all you have plugged in is the keyboard & mouse, but as soon as you plug in the WiFi dongle you will almost certainly crash the Pi (and loose keyboard control).

The whole point of using the Model A is, of course, to keep down costs and use the WiFi to control the Pi via your LAN. So once you have it running you will want to remove the hub and Keyboard and plug the WiFi dongle into the Pi's on-board USB socket.

It is also possible to setup WiFi on the Model B and, once you have it working, move the SD card to the Model 'A'

A4. If plugging the WiFi straight into the Pi's USB socket 'almost works', adding a decent (100uF +) capacitor across the USB socket power pins to 'smooth out' the power 'glitches' may do the trick

If you still get errors, and you still want to avoid using a powered hub, those who are handy with a soldering iron can bypass the 'polyfuse' and wire the incoming '5.2v' straight through to the Pi's USB socket +5v power pin (the 'reverse protection' diode will stop the 5.2 being fed back into the Pi itself)

Can I drive the Pi from a powered hub ?

Rather than use two separate power blocks, it's quite possible to power the Pi from the 'hub' power block. To avoid cutting off plug ends, get yourself a hub designed to work with smart phones i.e. one that has a 'micro USB' cable. You then open up the hub and wire it's power plug +5 input to the micro USB 5v line (thus allowing you to plug the hub into the Pi's micro USB socket and power the Pi).

Next, on the Pi, you add two wires (Tx & Rx) from the two center pins of the Pi's micro-USB socket to the matching pins on the Pi's main USB socket - this allows the Pi to 'communicate' with the hub via the micro-USB cable !

How do I use a PC (laptop) as a WiFi Access Point (base-station) for the Pi ?

Wireless Routers and Access Points aren't the same. A Wireless Router has a DHCP server that provides IP addresses to other computers and provides routing between those computers and the Internet. An Access Point simply allows other computers to connect using WiFi i.e. it's like a NIC (of course, a stand-alone Access Point might then 'route' other computers through to the Internet via it's own wired Ethernet connection, i.e. it can act like a Hub).

If your home LAN is Ethernet cable based, or you want to use a Laptop 'away from home' to control the Pi, you will need to "create a new ad hoc wireless network".

You do this via Start / Settings / Network Connections. Highlight the WiFi link and right click for Properties. In the 'Wireless Networks' tab, below the 'Preferred Networks' window, click 'Add' & enter a name for your new network.

If you want to use encryption, I suggest you stick to WEP - this may be easy to 'crack', however very few mobile devices support the more complex WPA or WPA2. To use WEP :-

Select "Open" under Network Authentication. Then, under Data Encryption, select "WEP". Then enter desired password under "Network key" and confirm it in the next field.

Make sure to check "This is a computer-to-Your_computer/ (ad-hoc) network; wireless access points are not used" (Microsoft speak for "I want use this computer as a wireless access point, not go via some other"). Then click OK to create your 'hot-spot'. Your new network will now appear under 'Preferred Networks'.

If you want other computers to connect to the Internet via your PC, you will now have to enable 'Internet Connection Sharing (ICS)' through your Ethernet network card, which will allow anybody connected to your 'ad hoc' wireless to use your internet connection.

Note that, unless you install a 3rd party DHCP Sever on your PC/Laptop, you will have to enter all the IP addresses, both on this computer and those you want to connect to it, manually

How do I use WEP with the Pi ?

The Pi should 'default' to WEP. To test if your Pi will connect to a WEP network with e.g. an SSID of 'WiFiSSID' and e.g. a WEP password of 'password', you type :-

iwconfig wlan0 essid "WiFiSSID" key "s:password"

Then type 'dhcpcd wlan0' and it should 'work'

How do I set-up a static IP on the Pi ?

By default, the Pi uses DHCP on both Ethernet (eth0) and WiFi (wlan). To change the settings, edit the 'interfaces' file :-

$ sudo nano /etc/network/interfaces

To set the WiFi to 'static IP', edit the line that contains 'wlan'. To set the wired Ethernet to 'static IP', edit the line with 'eth0', for example :-

iface eth0 inet dhcp

to :-

iface eth0 inet static

Below this line enter the static address you want to use, eg :-

address netmask network broadcast gateway

Next page :- Pi WDT - (WatchDog Timer)