1. 2015-07-01 - Setup WLAN for Raspberry Pi; Tags: Setup WLAN for Raspberry Pi
    Loading...

    Setup WLAN for Raspberry Pi

    This post explains how to setup a WiFi (WPA prototcol) connection on Raspbian. You will need an USB WiFi dongle attached to the Raspberry Pi.

    Check if the dongle is recognized with lsusb

    root@pelion:~# lsusb
    Bus 001 Device 002: ID 0424:9514 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 0409:005a NEC Corp. HighSpeed Hub
    Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
    Bus 001 Device 006: ID 18a5:0408 Verbatim, Ltd
    Bus 001 Device 007: ID 1845:0104
    Bus 001 Device 008: ID 1058:0705 Western Digital Technologies, Inc.
    

    You should find something similar like above entry with wireless.

    Check if wlan adapter is available with ifconfig or iwconfig.

    root@pelion:~# ifconfig
    eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              inet addr:192.168.1.122  Bcast:192.168.1.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5743385 errors:0 dropped:461 overruns:0 frame:0
              TX packets:6026159 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:2793859426 (2.6 GiB)  TX bytes:3795578538 (3.5 GiB)
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:14036 errors:0 dropped:0 overruns:0 frame:0
              TX packets:14036 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:4439608 (4.2 MiB)  TX bytes:4439608 (4.2 MiB)
    wlan0     Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    

    Output of iwconfig

    root@pelion:/etc/wpa_supplicant# iwconfig
    wlan0     unassociated  Nickname:"<wifi @REALTEK>"
              Mode:Managed  Frequency=2.412 GHz  Access Point: Not-Associated
              Sensitivity:0/0
              Retry:off   RTS thr:off   Fragment thr:off
              Encryption key:off
              Power Management:off
              Link Quality:0  Signal level:0  Noise level:0
              Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
              Tx excessive retries:0  Invalid misc:0   Missed beacon:0
    lo        no wireless extensions.
    eth0      no wireless extensions.
    

    Add WLAN details (name, type and authentication data) in /etc/wpa_supplicant/wpa_supplicant.conf

    Add network data

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
      ssid="my_wlan_name"
      # wlan key
      psk="gggg-0000-uuuu-nnnn_replace_with_your_key"
      # Protocol type can be: RSN (for WP2) and WPA (for WPA1)
      proto=RSN
      # Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
      key_mgmt=WPA-PSK
      # Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
      pairwise=TKIP
    }
    

    If your WLAN SSID is not hidden, you can scan accessible WLANs with iwlist scan. Replace above SSID and WLAN key.

    With the next reboot the wlan adapter should be connected to your WLAN. Next section test the WLAN connection manually.

    Bringing up the interface

    ifconfig wlan0 up
    

    Connect to WLAN with SSID office

    iwconfig wlan0 essid office
    

    Check iwconfig

    root@pelion:~# iwconfig
    wlan0     IEEE 802.11bg  ESSID:"office"  Nickname:"<wifi @REALTEK>"
              Mode:Managed  Frequency:2.412 GHz  Access Point: xx:xx:xx:xx:xx:xx
              Bit Rate:54 Mb/s   Sensitivity:0/0
              Retry:off   RTS thr:off   Fragment thr:off
              Encryption key:****-****-****-****-****-****-****-****   Security mode:open
              Power Management:off
              Link Quality=100/100  Signal level=95/100  Noise level=0/100
              Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
              Tx excessive retries:0  Invalid misc:0   Missed beacon:0
    lo        no wireless extensions.
    eth0      no wireless extensions.
    

    Acquire IP address via DHCP from your router

    root@pelion:~# dhclient -v wlan0
    Internet Systems Consortium DHCP Client 4.2.2
    Copyright 2004-2011 Internet Systems Consortium.
    All rights reserved.
    For info, please visit https://www.isc.org/software/dhcp/
    Listening on LPF/wlan0/xx:xx:xx:xx:xx:xx
    Sending on   LPF/wlan0/xx:xx:xx:xx:xx:xx
    Sending on   Socket/fallback
    DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8
    DHCPREQUEST on wlan0 to 255.255.255.255 port 67
    DHCPOFFER from 192.168.1.1
    DHCPACK from 192.168.1.1
    Reloading /etc/samba/smb.conf: smbd only.
    bound to 192.168.1.124 -- renewal in 37014 seconds.