How to configure Edimax EW-7811UN Wifi dongle on Raspbian

If you want to connect your RaspberryPi to your home network and you want to avoid cables, I suggest you to use the Edimax wifi adapter. This device is quite cheap (around £8 on Amazon) and it’s very easy to configure on Raspbian (I assume you are using a recent version of Raspbian. I’m using the one released on 20/06/2014).

edimax-pi3{ width=100% }

Configure the wifi adapter

Edit /etc/network/interfaces and insert these configuration values:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
auto lo
iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet dhcp
wpa-ssid YOURESSID
wpa-psk YOURWPAPASSWORD

Power management issue

There is a known “issue” with this adapter default configuration that makes it to turn off if the wlan interface is not in use for some minutes. To avoid this you have to customize the parameters used to load the kernel module. First check that your adapter is using 8192cu module:

1
2
sudo lsmod | grep 8192
8192cu 551136 0

Create the file /etc/modprobe.d/8192cu.conf and insert the following lines inside:

1
2
# prevent power down of wireless when idle
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

I also suggest to create a little entry in crontab to make the RaspberryPi ping your router every minute. This will ensure that your wifi connection will stay alive. To edit crontab just type (from pi user, you don’t need to be root):

1
crontab -e

and insert this line at the end:

1
*/1 * * * * ping -c 1 192.168.0.1

where 192.168.0.1 is the IP of your router (of course substitute this value with the ip of your router).

Keep Alive Script

I created a further script to keep my WIFI alive. This script will ping the router (change the IP using the one of your router) every 5 minutes and if the ping fails it brings down the wlan0 interface, the kernel module for the wifi and bring them up again.

Just put this script in **/root/wifi\_recover.sh** and then execute from **root** user:
1
2
chmod +x wifi_recover.sh
crontab -e

Insert this line inside the crontab editor:

1
*/5 * * * * /root/wifi_recover.sh

Conclusion

The configuration is done. Just reboot your RaspberryPi and enjoy your wifi connection.

comments powered by Disqus
source code available on GitHub
Built with Hugo
Theme Stack designed by Jimmy