Friday, November 29, 2013

Raspbian Wireless Wi-Fi


Are you wanting to connect to your Raspberry Pi over WiFi?  The following are instructions for configuring WiFi on Raspbian (the other Debian based Raspberry Pi distributions should work in a similar manner).

Although the Raspberry Pi model B conveniently comes with an Ethernet port (the model A does not), there are a number of applications where having WiFi is super convenient.  I have one of my Raspberry Pi out in our garage, controlling and monitoring the garage door.  Running a network cable would have been a very ugly solution.

To connect via wireless one must add a WiFi USB dongle, which will consume one of your precious few available USB ports (maybe time to expand with a powered USB hub).  There are other low level hardware options, but nothing quite as simple, and plug and play, as a WiFi USB dongle.

There are a number of compatible WiFi USB dongles on the market.  Review the RPi USB Wi-Fi Adapters list for verified adapters.  My personal favorite is the Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter (pictured above), as it is popular, works fairly well, and is only $9 on Amazon (with Amazon Prime).

To enable WiFi, simple connect your WiFI USB dongle to an available USB port, modify your network interfaces configuration file and restart your Pi.  To configure the network interfaces configuration file, add the wlan0 section to /etc/network/interfaces:
auto lo
iface lo inet loopback

iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-ssid "YOUR_SSID"
        wpa-psk "YOUR_WEP_OR_WPA_KEY"
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

Your WPA key above can specified as either be the clear text passphrase, or the hex encoded version.  If you would prefer to not list your clear text passphrase you can generate the encoded hex version with the wpa_passphrase tool or even online tools.
# wpa_passphrase test testtesttest
network={
        ssid="test"
        #psk="testtesttest"
        psk=b6df3a2ab8a19db1b646e4a852892d39fc4e73c13cb2ade0ad9d8887bb414ecd
}

WPA passwords are managed on Linux with the wpa_supplicant tools.  The wpa_passphrase tool is designed to generate a section that can be added to the /etc/wpa_supplicant/wpa_supplicant.conf configuration file.  You can also add multiple SSIDs to wpa_supplicant.conf.  If you have multiple SSID you may want to connect to (such as a mobile Raspberry Pi), don't add the wpa-ssid and wpa-psk lines to the interfaces file.  Instead use the wpa_passphrase tool to add multiple sections to the wpa_supplicant.conf configuration file.

You can auto add the output of wpa_passphrase, to the wpa_supplicant.conf, with the following:
# wpa_passphrase test testtesttest >> /etc/wpa_supplicant/wpa_supplicant.conf

Finally, to bring up the wireless, either reboot the Raspberry Pi, or run the following:
# ifdown wlan0
# ifup wlan0

You should now be able to use your Raspberry Pi over WiFi.



For reference, there are several command line tools that can be used to manually configure and view wireless settings.

To see your wireless IP address:
# ifconfig wlan0
lan0     Link encap:Ethernet  HWaddr 80:1f:02:be:XX:Xx
          inet addr:10.10.10.100  Bcast:10.10.10.255  Mask:255.255.255.0

To manually configure SSID and other wireless options, the iwconfig command can be used. The output of iwconfig looks similar to the ifwconfig, but with wireless settings:
# iwconfig wlan0
wlan0     IEEE 802.11bg  ESSID:"MY_SSID"  Nickname:""
          Mode:Managed  Frequency:2.437 GHz  Access Point: 00:14:BF:E0:XX:XX
          Bit Rate:54 Mb/s   Sensitivity:0/0
          Encryption key:****-****-****-****-****-****-****-****   Security mode:open

To scan for wireless access points:
# iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 00:14:BF:E0:89:XX
                    ESSID:"MY_SSID"
                    Protocol:IEEE 802.11bg
                    Mode:Master
                    Frequency:2.437 GHz (Channel 6)
                    Encryption key:on
                    Bit Rates:54 Mb/s



No comments:

Post a Comment

Please be respectful.