Setting up the Edimax EW-7811Un or Tenda W311Mi 802.11b/g/n WiFi Adapter on a Raspberry Pi

Note: On Raspberry Pi models with built-in WiFi (e.g. the Raspberry Pi 3 model B), USB WiFi interfaces will use wlan1 (wlan0 is reserved for the first interface, in this case the internal one).

Since this is maybe the fourth time I've done this process on my Raspberry Pis, I decided to document the process of setting up cheap mini WiFi adapters on a Raspberry Pi A+/B+/2.

This process works great with any USB WiFi adapter that's supported out of the box. My three favorites (due to their inexpensive price and decent connection speed/reliability) are:

Configuring the adapter

  1. Make sure the Raspberry Pi sees the adapter on the USB bus: $ lsusb.
  2. Make sure the network interfaces file (/etc/network/interfaces) has a wlan0 configuration; if not, make it look somewhat like the following:
    allow-hotplug wlan0
    iface wlan0 inet manual
        wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    
  3. Edit your wpa_supplicant.conf file (/etc/wpa_supplicant/wpa_supplicant.conf), and add your wireless network settings to the end of the file:
    network={
      ssid="YOUR_NETWORK_SSID"
      psk="YOUR_NETWORK_PASSWORD"
    }
    
  4. If the Pi doesn't connect automatically within 10-20 seconds, you can manually refresh the interface to connect and get an IP address: $ sudo ifdown wlan0 && sudo ifup wlan0. Then run ifconfig to find your IP address (in the wlan0 section).

You can also reboot your Pi entirely ($ sudo reboot) to make sure the configuration sticks and your Pi joins the network automatically. I typically set up static IP reservations on my network router, so each Pi gets a permanent IP address.

Also, if you need to scan for a list of the WiFi networks your Pi can see, run sudo iwlist wlan0 scan.

Troubleshooting the wifi connection:

  • Make sure your Pi can see the network you're trying to connect to: use $ sudo iwlist wlan0 scan | grep ESSID to list all the found network SSIDs. If you're network isn't in the list, it might be a 5GHz network (the Edimax only works on 2.4GHz networks), or it might be out of range.
  • To find your IP address, MAC address, and other interface information, run the command $ ifconfig -a.

Ensuring the adapter doesn't go into sleep mode

One of the most annoying things that can happen with a headless wifi-connected computer is the wireless connection dropping, or hanging for 10+ seconds at a time. It seems the Edimax is configured to go into a sleep state after a few seconds of inactivity by default, but this can be disabled pretty easily:

  1. Create a configuration file for the adapter: $ sudo nano /etc/modprobe.d/8192cu.conf
  2. Add the following two lines to the configuration file and save the file:
    # Disable power management
    options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
    
  3. Reboot your Raspberry Pi: $ sudo reboot

I've had one Pi running for almost a year now, doing nothing but some temperature data aggregation inside the house, and the Edimax WiFi adapter has been rock solid. A missed packet here or there, but way more reliable than any other cheap adapter I've used!

I've only recently started using the Tenda adapter, but so far it seems to be just as reliable as the Edimax, despite being a little less popular. It doesn't seem to require any extra configuration to stay out of sleep mode, and it's readily available at my local Micro Center!

Comments

Im getting an error where I copied your changes and an error mentions inet dhcp? Using Pi2 raspbian and edimax as you mentioned.

Unfortunately this config isn't valid; wpa-roam isn't allowed with inet dhcp; it's only allowed with inet manual.

Yikes, you're right! In between the past year's worth of edits, the config here was messed up and doesn't reflect the config I'm actually using on my Pis. I've corrected this.

Couple of questions:

When I run lsusb I get:
Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
so is /etc/modprobe.d/8192cu.conf the right file to create since my Edimax is reporting a RTL8188CUS instead of an 8192cu?

Secondly, iwconfig reports 'Power Management:off' for wlan0. Is the modprobe.d file configuring some other power management setting?

It appears that Jessie Lite has the "disable power management" feature already selected. At the very least the configuration file was already there with the same settings as you listed. Loving Jessie Lite, BTW.

Oh God! I wish I had seen this page before I had the idea to starte playing with clustering...

This method helped. Thank you.

I have attempted other similar approaches without success, but your walk-through did the trick.

Nowadays you can use the USB Wifi adapter likes Tenda, Edimax, and kootek etc. You can also U

Thanks for sharing this marvelous post. I m very pleased to read this article.

Hi Jeff,

First, thank you for the article. I'm using Tenda W311M and it worked like a champ on a first try without any issues or needing to configure anything.

But, in my Pi B Tenda W311M is going in sleep and I am having to manually cutoff power to restart. I would appreciate if you can please provide the script for it. I bought this one from Micro Center:

https://www.microcenter.com/product/486399/tenda-w311m-150mbps-wireless…

Thank you again for nice article and recommendation.