How to use a WiFi USB adapter on the RasPi

RasPi with Edimax WiFi adapterThe following description how to set up an USB WiFi adapter in Raspbian is a compendium based on several tutorials (also see the sources at the end). Additions about specific characteristics of certain hardware or corrections are always welcome.

Prerequisites

To make WiFi adapters work in general when starting the RasPi, the network configuration in the file /etc/network/interfaces should look like following:

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

Hardware

Edimax EW-7811Un

For the use with the RasPi a common recommendation is often the “nano” WiFi adapter Edimax EW-7811Un as it is supported by Raspbian out of the box. When the adapter is connected you can check if it was recognized at all with the following command:

lsusb

In case of the Eximax model the result should like this:

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]

Another test is to verify if a network interface had been created. This is done with

ifconfig

In the result you should see the interface wlan0 as well:

wlan0     Link encap:Ethernet  HWaddr 80:1f:02:f6:fe:4a
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:1 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ISY IWL 2000

The ISY IWL 2000 contains an adapter by Belkin which can be used with the kernel module 8192cu like the Edimax model. However it has a different device ID, so the module will not be loaded automatically:

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 050d:11f2 Belkin Components

But this problem can be solved easily without forcing the module to load as described in some tutorials.

First you create a customized configuration for modprobe in the file /etc/modprobe.d/rtl8192cu.conf using the following command:

echo 'install 8192cu /sbin/modprobe --ignore-install 8192cu; /bin/echo "050d 11f2" > /sys/bus/usb/drivers/rtl8192cu/new_id' | sudo tee /etc/modprobe.d/rtl8192cu.conf

Then create an additional udev rule in the file /etc/udev/rules.d/10-wlan-stick.rules which ensures that the module will only be loaded when the adapter is actually connected. You can use the following command for this:

echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="050d", ATTR{idProduct}=="11f2", RUN+="/sbin/modprobe 8192cu"' | sudo tee /etc/udev/rules.d/10-wlan-stick.rules

After restarting the RasPi ifconfig should now also list the interface wlan0.

Disabling the power management of the kernel module 8192cu

The kernel module 8192cu has a quite annoying feature: When no data is transmitted for a while the WiFi adapter will be turned off to save energy. This also means that the RasPi is not accessible any longer from outside.

This problem can be solved as well. You have to create the file /etc/modprobe.d/8192cu.conf with an additional option to disable the power management:

echo 'options 8192cu rtw_power_mgnt=0 rtw_enusbss=0' | sudo tee /etc/modprobe.d/8192cu.conf

After restarting the RasPi you can check with the command

cat /sys/module/8192cu/parameters/rtw_power_mgnt

if the action was successful. Here you should see the following result:

0

Configuration of the wireless network

The network configuration of the wireless network is done in the file /etc/wpa_supplicant/wpa_supplicant.conf. Here you add an additional block which looks like following (without spaces in network={):

network={
  ssid="WIFI-SSID"
  psk="WIFI-PASSWORT"
  scan_ssid=1
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP
  auth_alg=OPEN
}

You find additional information about this file in the man page which you can open with the following command:

man wpa_supplicant.conf

By using the WPA supplicant instead of a static configuration in /etc/network/interfaces the wireless network will be used automatically if it is reachable. In the same way you can also add multiple networks, which is useful when you use the RasPi at different places or with a mobile WiFi hotspot from time to time. For every network just add an additional network block with the required settings.

Sources

The information in this post has been compiled based on articles from the following sources:

Daniël’s Linux Blog – Raspberry Pi and the ISY USB Wireless Micro Adapter

Blog de Maurice Svay – Setting up a WiFi connection on the RaspberryPi

One thought on “How to use a WiFi USB adapter on the RasPi”

  1. I suggest this USB Wifi from Netgear for RPi. Works really well for me http://www.reviewstew.net/wifi-adaptor-netgear-rangemax-dual-band-wnda3100-v2/

Leave a Comment to Shane Cancel Comment

Your email address will not be published. Required fields are marked *