Setting up wlan configuration on raspbery Pi.

1. Check Wifi device is recognized

sudo lsusb

2. Try Scanning with Wifi device

sudo iwlist wlan0 scan

3. Modify interface

Edit wpa_supplicant.conf to add network profile.

sudo vim /etc/wpa_supplicant/wpa_suplicant.conf
network={
  ssid=“AP_NAME”
  psk=“AP_PASSWORD"
}

Edit interfaces file.

sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default net dhcp


wpa-roam :
Reconfigure wifi setup automatically at reboot or wifi disconnect.
If configuration above causes error(Some APs have troubles), try below:

auto lo
auto wlan0

iface lo net loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default net dhcp

A more stable configuration, however need to reconnect manually when disconnected.

4. reboot and check

sudo reboot
sudo ifdown wlan0  # Response varies depending on status
sudo ifup wlan0
wpa_cli status  # Check status