Raspberry Pi – Adding Wifi (WPA/WPA2) using wpa_cli

One of the first things that I wanted to do was get my Raspberry Pi to work on wireless. For those of you that have seen my shopping list, you will remember that I went with the Airlink 5099 USB Wifi Adapter which is on the “approved” USB wifi to minimize the hassle of downloading and installing drivers. I plugged in the device and noticed that my RPi went through a reboot. I later found out that that is normal activity. Plug in your USB Wifi adapter with the RPi powered off.
The first command that I wanted to use is the lsusb command. This will show you all of the USB devices that your RPi currently knows about. Here is the output that I received –

pi@raspberrypi:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter

As a further configuration I used the ifconfig command and saw that there was additional information that confirmed that the driver has properly loaded for the Wifi USB adapter –

wlan0 Link encap:Ethernet HWaddr 00:21:2f:30:be:25
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)

With the output of the two different commands, the next step is to enter the USB Wifi adapter.

The first command to use is wpa_cli. When you get to the command prompt, type scan and press enter. This will get the Wifi USB adapter to scan all the 2.4Ghz channels to see what SSIDS’s are being broadcast. After about a minute, you will see a prompt on the screen that indicates that the channel scan is complete. Type scan_results and press Enter. You will see a list of the SSID’s that were “heard”. If you see your SSID, you are ready to proceed to the next step. Type add_network and press enter. You should see a “0” displayed followed by the command prompt. Type set_network 0 said followed by your SSID encased in quotes and press enter. Type set_network 0 psk followed by your passphrase encased in quotes. Now that this configuration has been entered, we need to activate it. This is done by using the enable_network 0 and pressing the Enter key. Within a few seconds, you should see several lines appear on the screen (these show up in the video accompanying this post).

Now that the configuration has been entered, type save_config followed by the Enter key. This will write the information to the configuration file use by the wpa supplicant process. Using the iwconfig command will show your current wireless config to the screen. Using the ifconfig command should show you an ip address for the wlan0 interface. I had researched another way of configuring the wifi interface but this one was much easier and faster.

To see more of my posts about the Raspberry Pi, please go to http://www.ronnutter.com/category/raspberry-pi/

Send to Kindle
This entry was posted in Blog Entries, Raspberry Pi and tagged . Bookmark the permalink.