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.

installing idVendor = 0bda idProduct = 8179 wifi card to raspberrypi

I have been using Raspberry pi for a quite a long time now. I bought it when I was in England for some time and got my hands on the early versions of it as it was previously available in England only.

So today I am going to explain about making an Airplay device from Raspberrypi.

First Things First.

Please check the Compatibility list to get the verified hardware only.

So now lets move to installation.

Install Raspian and boot the device.

pi@raspberrypi ~ $ sudo apt-get upgrade
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo reboot

Insert the usb Wifi dongle and check if its recognized.

pi@raspberrypi ~ $ lsusb
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 0bda:8179 Realtek Semiconductor Corp.

pi@raspberrypi ~ $ dmesg | more
[3.326389] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[3.447524] usb 1-1.2: New USB device found, idVendor=0bda, idProduct=8179
[3.465540] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[3.479331] usb 1-1.2: Product: 802.11n NIC
[3.485392] usb 1-1.2: Manufacturer: Realtek

Interesting part is idVendor=0bda, idProduct=8179

This is not a native wifi card and will not be working on its on. So we need modification.

Check the kernel version you have

pi@raspberrypi ~ $ uname -r
3.12.22+

To make it work just download the kernel object (.ko) file which is the compiled module driver for the kernel.

For raspbian image: 2014-06-20-wheezy-raspbian.img
8188eu.ko & firmware (Compiled in 2014-06) (Working in kernel Linux raspberrypi 3.12.22+ #691 PREEMPT)

pi@raspberrypi ~ $ sudo install -p -m 644 8188eu.ko /lib/modules/3.12.22+/kernel/drivers/net/wireless
pi@raspberrypi ~ $ sudo insmod /lib/modules/3.12.22+/kernel/drivers/net/wireless/8188eu.ko
pi@raspberrypi ~ $ sudo cp rtl8188eufw.bin /lib/firmware/rtlwifi/
pi@raspberrypi ~ $ sudo depmod -a
pi@raspberrypi ~ $ reboot

pi@raspberrypi ~ $ ifconfig

Now wlan0 can be seen and will be working properly.