Right way to set up WiFi in Raspberry pi

I’ve recently tried to setup a WiFi connection with the RaspberryPi and encountered some issues: the connection was not starting automatically. I am using following wifi adapter : 
$ dmesg | grep usb 
New USB device found, idVendor=0bda, idProduct=8179 
After researching the issue, I finally have a configuration that works reliably. Here are the steps I’ve followed.
One final bit left to do now: configuring our adapter. Before that though, we should make sure that you have wpasupplicant package installed since you’ll probably want to connect to a WPA secured network:
$ sudo apt-get install wpasupplicant
 WiFi configuration of router is as follows

Setting up the configuration

Edit the /etc/network/interfaces file to look like this:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

#allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa.conf
Then add your WiFi parameters to /etc/wpa.conf.
network={
ssid="YOUR_SSID"
scan_ssid=1
key_mgmt=WPA-PSK
proto=WPA
psk="YOUR_PASSWORD"
}
Restart your networking subsystem with:
$ sudo /etc/init.d/networking restart

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.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/8188eu.conf file with this content:
options 8188eu 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.1.1
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.

No comments:

Post a Comment