
I’ve recently tried to setup a WiFi connection with the RaspberryPi and encountered some issues: the connection didn’t start automatically and it wasn’t stable. I’m using an Edimax EW-7811Un USB dongle, which is supposed to be supported out of the box with Raspian Wheezy (2012-12-16).
After researching the issue, I finally have a configuration that works reliably. Here are the steps I’ve followed.
Setting up the configuration
Edit the /etc/network/interfaces file to look like this:
auto lo iface lo inet loopback iface eth0 inet dhcp #auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
Then add your WiFi parameters to /etc/wpa_supplicant/wpa_supplicant.conf.
Here are my parameters to connect to my freebox (French ISP router).
network={
ssid="YOURSSID"
scan_ssid=1
key_mgmt=WPA-PSK
proto=WPA
psk="YOURPASSWORD"
}
At this point, the you should be able to start the connection with this command:
sudo ifup wlan0
In some cases, you might need to do sudo ifup wlan0 first.
Connect automatically when booting
To make the connection work when the RaspberryPi boots, I have added a few lines to /etc/rc.local (source) :
echo "Starting WiFi..." wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf sleep .5s dhclient wlan0 echo "WiFi should be started" exit 0
Keep the connection alive
To make sure that the connection stays up, I’ve done two things.
First, disable the power management of the WiFi dongle. Create a new /etc/modprobe.d/8192cu.conf file with this content (source):
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
Then, make the RaspberryPi ping the router every minute. Open your crontab:
$ crontab -e
and add this line at the end :
*/1 * * * * ping -c 1 192.168.0.254
Replace the IP address by the actual IP address of your router.
It took me some time to get it right, but now the Pi connection seems to work fine.
Thank you so much! I’ve finally gotten the WiFi to successfully connect to the internet at boot up, and so far this is the only guide that has worked
Glad it was helpful!
Pingback: DIY Raspberry Pi Airplay Speaker for less than 70€ | Blog de Maurice Svay
if you set your interfaces like this there is no need for the rc.local
auto lo wlan0
iface lo inet loopback
iface eth0 inet dhcp
#auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Pingback: Sky+ HD Box – Raspberry Pi « techbasin – Thin Box Software
Pingback: WiFi Horizon, Best news updates, offers and business opportunities
it all works however I still do not have connection to my router. I know that there is an existing wpa_supplicant instance running and I have to kill it prior to running your script. I don’t have enough foo to do that? can you help