Wireless networking on a Raspberry Pi

The process here should work for most USB wireless devices, and should work on both a Raspberry Pi and an ordinary PC running Debian (or even Ubuntu) provided the device is supported by the current kernel.

This post has a more up to date description of the steps needed to enable the wireless network interface on the different models of Raspberry Pi.

I have a N150 Nano USB wireless adaptor that I brought from Maplin for my Raspberry PI and I also recently acquired an old USB wireless adapter made by TP-Link. Although the latter was physically huge compared to the current USB nano wireless adapters, it was interesting in that it came with its own stand allowing it to be mounted on a desktop a few feet away from the machine it was plugged into – ideal for getting the wireless antenna out into the open from behind the hi-fi or media cabinet, so I decided to see if I could get it to work with my Raspberry Pi.

Identifying the adapter

When I plugged the TL_WN422G in to the USB port on my Raspberry Pi I was pleased to see the following output on the console.

usb 1-1.4: new high-speed USB device number 5 using dwc_otg
usb 1-1.4: New USB device found, idVendor=0cf3, idProduct=1006
usb 1-1.4: New USB device strings: Mfr=16, Product=32, SerialNumber=48
usb 1-1.4: Product: USB2.0 WLAN
usb 1-1.4: Manufacturer: ATHEROS
usb 1-1.4: SerialNumber: 12345
usb 1-1.4: ath9k_htc: Firmware htc_9271.fw requested
usb 1-1.4: firmware: failed to load htc_9271.fw (-2)
usbcore: registered new interface driver ath9k_htc
usb 1-1.4: ath9k_htc: USB layer deinitialized

Great news it looks like it is supported – the key phrase is I think ‘registered new interface driver’ which shows that the device was recognized by the kernel which attempted to load the firmware, and not surprisingly as it wasn’t installed, failed.

Plugging in a N150 Nano USB wireless adaptor you get a similar output on the console.

usb 1-1.4: new high-speed USB device number 5 using dwc_otg
  :
usb 1-1.4: New USB device found, idVendor=148f, idProduct=5370
usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.4: Product: 802.11 n WLAN
usb 1-1.4: Manufacturer: Ralink
usb 1-1.4: SerialNumber: 1.0
usb 1-1.4: reset high-speed USB device number 5 using dwc_otg
ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 5390, rev 0502 detected
ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 5370 detected
usbcore: registered new interface driver rt2800usb
ieee80211 phy0: rt2x00lib_request_firmware: Loading firmware 'rt2870.bin'
rt2800usb 1-1.4:1.0: firmware: failed to load rt2870.bin (-2)

Note – Before doing anything else unplug the USB Wireless device for now.

Given the information above the thing is to determine what firmware is required.

A bit of searching for ‘htc_9271.fw firmware package‘ or ‘rt2870.bin firmware package‘ suggest that the required packages are ‘firmware-atheros‘ for the TL-WN422G and ‘firmware-ralink‘ for much smaller N150 USB Nano.

Installing the Firmware

Now we know which package we need we can install the required firmware but, since most firmware packages are in the ‘non-free’ repository (as they are released under proprietary licences) we need to update ‘sources.list’ and add the following entry (shown in bold) first.

# vi /etc/apt/sources.list

deb http://mirrordirector.raspbian.org/raspbian jessie main firmware non-free
deb http://archive.raspberrypi.org/debian wheezy main

# apt-get update

Having added the ‘non-free’ repository to the package sources and updated the available packages we should now be able to install the required firmware.

# apt-get install firmware-atheros
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  firmware-atheros
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 873 kB of archives.
After this operation, 1803 kB of additional disk space will be used.
  :
  :
  :
Preparing to unpack .../firmware-atheros_0.43_all.deb ...
Unpacking firmware-atheros (0.43) ...
Setting up firmware-atheros (0.43) ...
#

Alternativly if you are using the N150 Nano USB wireless adaptor then you need to install the ‘firmware-ralink’ package.

# apt-get install firmware-ralink
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  firmware-ralink
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 22.2 kB of archives.
After this operation, 103 kB of additional disk space will be used.
  :
  :
  :
Unpacking firmware-ralink (0.43) ...
Setting up firmware-ralink (0.43) ...
#

If you now plug the USB wireless adapter back in you should see some messages on the console indicating that the device has been detected and the firmware loaded successfully

usb 1-1.4: new high-speed USB device number 6 using dwc_otg
usb 1-1.4: New USB device found, idVendor=0cf3, idProduct=1006
usb 1-1.4: New USB device strings: Mfr=16, Product=32, SerialNumber=48
usb 1-1.4: Product: USB2.0 WLAN
usb 1-1.4: Manufacturer: ATHEROS
usb 1-1.4: SerialNumber: 12345
usb 1-1.4: ath9k_htc: Firmware htc_9271.fw requested
usb 1-1.4: firmware: direct-loading firmware htc_9271.fw
usb 1-1.4: ath9k_htc: Transferred FW: htc_9271.fw, size: 51272
ath9k_htc 1-1.4:1.0: ath9k_htc: HTC initialized with 33 credits
ath9k_htc 1-1.4:1.0: ath9k_htc: FW Version: 1.3
ieee80211 phy0: Atheros AR9271 Rev:1
cfg80211: Calling CRDA to update world regulatory domain

Configuring the Wireless Interface

To be able to connect to a wireless network we also need to install the following packages..

# apt-get install wireless-tools wpasupplicant
apt-get install wireless-tools wpasupplicant
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libiw30 libnl-3-200 libnl-genl-3-200 libpcsclite1
Suggested packages:
  pcscd wpagui libengine-pkcs11-openssl
The following NEW packages will be installed:
  libiw30 libnl-3-200 libnl-genl-3-200 libpcsclite1 wireless-tools
  wpasupplicant
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 1065 kB of archives.
After this operation, 2640 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
  :
  :
  :
Setting up wpasupplicant (2.3-1+deb8u1) ...
Setting up wireless-tools (30~pre9-8) ...
Processing triggers for libc-bin (2.19-18+deb8u1) ...
Processing triggers for dbus (1.8.20-0+deb8u1) ...
#

Check that the wireless interface is detected.

# iwconfig
wlan0     IEEE 802.11bgn  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          
lo        no wireless extensions.

eth0      no wireless extensions.
#

If there is not an entry corresponding to your wireless network then your wireless device is not supported, you may find that upgrading to a newer kernel (using 'apt-get upgrade'), or newer linux release solves this problem.

If the wireless device is listed as 'eth1' instead if 'wlan0' you can change this by editing the corresponding entry in '/etc/udev/rules.d/70-persistent-net.rules' so that the name is 'wlan0' instead of 'eth1'.

Then unless you want to use the network manager you need to configure the wireless interface by editing '/etc/network/interfaces'.

The advantage of using the network manager is that you can select which network to connect to once you have logged in, which works if you are using the desktop and logging in locally but if you want to connect to the network automatically when the machine boots you need to use '/etc/network/interfaces'.

# vi /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid <insert your-ssid here>
    wpa-psk  <insert your-password here>

You will need to substitute your real network ssid (the name of your wireless network) and your real network password, sometimes referred to as a pre-shaired key or PSK, in place of your-ssid and your-password in '/etc/network/interfaces'.

The next time you reboot the wireless network should start automatically.


Raspberry Pi is a trademark of the Raspberry Pi Foundation

This entry was posted in Debian, Linux, Raspbian and tagged , , , . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.