How I Set Up My Raspberry PI – Lesson 3 Demystifing Wi-Fi Setup For My Raspberry Pi

As I indicated in my last Raspberry Pi post, trying to learn how to set up my USB Wi-Fi adapter could only be described as demystifying a “Black Art” of sorts. In attempting to get my USB Wi-Fi operational, I could not find anything that I could understand that defined the process in simple terms. The YouTube video that is part of How I Set Up My Raspberry PI – Lesson Two Deciding on Operating System Distributions walked me through the process and got my USB Wi-FI adapter working. However it provided no overview of the process and left me wondering where the configuration commands (called stanzas) came from and what those instructions actually did. Since the Raspberry PI is not a consumer device but instead a computer designed for users to learn how these kind of setups are supposed to work, I thought it would be prudent to post my version of how to set up a USB Wi-Fi adapter in an attempt to demystify the process.

What Steps Are Involved In Making My USB Wi-Fi Module Work On My Raspberry PI?

In a nutshell the installation steps are as follows;

  1. Ensure that your Raspberry Pi detects your USB Wi-Fi module once it’s plugged in. If your module is not supported by Raspbian Wheezy it means that the module’s drivers/firmware are not installed or the module is not compatible with Raspbian Wheezy’s RISC based hardware.
  2. Modify the /etc/network/interfaces configuration file to operate the USB Wi-Fi module and provide the network name and password. This file is modified using nano which is a basic text editor built into Raspbian Wheezy.
  3. Use Linux commands to light up the Wi-Fi module, then reboot so the Wi-Fi automatically logs into your wireless network.

What Skills Are Required To Activate My USB Wi-Fi Module Work On My Raspberry PI?

In a nutshell the following basic skills are are required;

  1. The ability to open, edit and save text based configuration files using nano. Nano is a basic text editor built into Raspbian Wheezy.
  2. The ability to work with Raspbian Wheezy’s (Linux) Command Line Interface.

What Are The Pitfalls Of My Raspberry Pi USB Wi-Fi Module Installation That Can Really “Mess One Up” ?

  1. The USB Wi-Fi module that you are using is not naively supported by Raspbian Wheezy. You might overcome the problem by installing drivers or firmware (if available) but it’s best to use Raspbian Wheezy supported modules that are listed here. I mention the specific module(s) I’m using later in this post. Since both my modules were recognized by my Raspberry PI’s, I have no direct experience in making a non supported module work from scratch, As such this blogpost offers no information on how to install drivers or firmware for un supported USB Wi-Fi modules.
  2. Be sure that you understand the encryption system that your Wi-Fi transmitter uses. It’s probably either WPA2 or WEP. This matters because the /etc/networks/interfaces configuration files are written differently for WPA and WEP encryption/password configurations. If you do not fill in the information correctly in the /etc/network/interfaces file then the Wi-Fi will not log into the network and appear not to be working.

Where Do I get These Basic Skills To Install My USB Wi-Fi Module Work On My Raspberry PI?

In setting up my USB Wi-Fi adapter I followed the video in How I Set Up My Raspberry PI – Lesson Two Deciding on Operating System Distributions blog post. It needs to be noted that;

  • the USB Wi-Fi adapter I used in this setup was the Adafriut Miniature WiFi (802.11b/g/n) Module. (This is a Raspbian Wheezy supported module)
  • the encryption used on my wireless network is WPA2. For the example below the network name will be canada and the WPA2 password is 18671867

In A Nutshell The Video In Lesson Two Directed Me To Do The Following To Get My USB Wi-Fi Module Operational;

Step 1: Login to my Raspberry Pi. At the command line prompt type iwconfig

The Command Line Interface (CLI) returns;

lo no wireless extensions.

wlan0 unassociated Nickname:”<WIFI@REALTEK>”
Mode:Auto Frequency=2.412 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr: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

eth0 no wireless extensions.

The iwconfig command shows connected network interfaces and the above readout is good news. What the screen is telling me is that wlan0 (short for wireless lan 0) is seeing my USB Wi-Fi Module which is equipped with Realtek firmware and it’s identified to my Raspberry Pi as wlan 0. The word unassociated following wlan0 indicates that wlan0 is not connected to a network at this point. Our next step will be to edit the /etc/network/interfaces configuration file to associate wlan0 to our wireless network.

A couple of things to note;

  • If wlan does not appear at all in the readout, the USB Wi-Fi module you are using requires the drivers/firmware to be installed on your Raspberry Pi. As mentioned above I have no direct experience on installing firmware/drivers so you need to seek other internet resources to accomplish this.
  • The readout might identify your USB Wi-Fi module associated with wlan1. If this is the case you will need to code the /etc/network/interfaces file (next step) wlan1 instead of wlan0

Step 2: Edit The /etc/network/interfaces Configuration File To Associate wlan0 With Our Wireless Network. At the CLI prompt type: sudo nano /etc/network/interfaces

This will start nano (the built in text editor mentioned above). What I did was completely replace the configuration file with the following stanza (text);

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0

auto wlan0

iface wlan0 inet dhcp
wpa-essid “canada”
wpa-psk “18671867”

After saving the file and exiting nano returning back to the CLI prompt the USB Wi-Fi module interface is ready go. The next step is activate the the Wi-Fi module.

A couple of things to note;

  • the wpa-essid information (in quotes) is the name of my network that I want to log into. Replace canada with the name of your network name and be sure to keep the network name inside the quote (“) marks
  • the wpa-psk information (in quotes) is the password to my network. Replace 19871987 with your networks password and be sure to keep the password the quote (“) marks
  • remember if your iwconfig readout showed your USB Wi-Fi module as wlan1, replace all of the wlan0 references with wlan1 in the above stanza
  • the above stanza is written to support WPA2 encryption. To write a stanza that supports WEP the information can be found at http://bit.ly/RuT4sA
  • information on what the coding of the above stanza actually does can be found at http://bit.ly/13122kY

Step 3: Start Up Your USB Wi-Fi module At the CLI prompt type: sudo ifup wlano

Initiating the ifup should wake up your USB Wi-Fi module. Yo You will know it is working because the transmission LED’s light up on the module itself.

A couple of things to note;

  • The module lighting up is a good sign. It should mean that the drivers/firmware are working properly with your pi.

If your USB Wi-Fi module does not light up it’s likely due to;

  • the driver/firmware not being correct. No suggestions to correct this in this post
  • the wlan reference is wrong in the /etc/network/interface file. Double check your modules reference by running iwconfig and edit the /etc/network/config file to the correct wlan number using nano

The module being lit does not mean that you are successfully connected to your network. A successful connection to your network will result in a readout similar to what follows;

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/00:e0:4c:09:25:ff
Sending on LPF/wlan0/00:e0:4c:09:25:ff
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.1.1
DHCPACK from 192.168.1.1
bound to 192.168.1.105 — renewal in 120069 seconds.

The key stanza to look for is; bound to 192.168.1.105 — renewal in 120069 seconds. This means that your Wi-Fi module is connected to the network and your Raspberry Pi has been assigned an IP address of 192.168.1.105 from your network. Please note the IP address assigned by your network is likely to be different from the readout above.

To confirm that you are connected to the right network at the CLI type: iwconfig

A Wi-Fi connected Raspberry Pi readout would be similar to the following;

wlan0 IEEE 802.11bgn ESSID:”canada” Nickname:”<WIFI@REALTEK>”
Mode:Managed Frequency:2.457 GHz Access Point: 90:F6:52:95:5D:5B
Bit Rate:150 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality=100/100 Signal level=63/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

eth0 no wireless extensions.

The key stanza in the readout is wlan0 IEEE 802.11bgn ESSID:”canada” meaning that wlan0 is connected to the canada Wi-Fi network

An unsuccessful connection to your network will result in a (sudo ifup wlan0) readout similar to what follows;

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/00:e0:4c:09:25:ff
Sending on LPF/wlan0/00:e0:4c:09:25:ff
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 13
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 10
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 18
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 13
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 2
No DHCPOFFERS received.
Unable to obtain a lease on first try. Exiting.
Failed to bring up wlan0.

The above readout indicates that your Wi-Fi Module is working and trying to log into your wireless network. It indicates it has been unsuccessful with the stanza  Failed to bring up wlan0. In this case it could not obtain a DHCP IP address from the network probably because it could not log in. In this case one would check;

  • if the network name and password are entered properly in the /etc/networks/interfaces configuration file
  • to ensure that the /etc/network/interfaces stanzas conform to your networks use of either WPA2 or WEP encryption. To write a stanza that supports WEP the information can be found at http://bit.ly/RuT4sA

Sonetimes you can connect to a network but its connection to the Internet is down. To check if your network is connected to the Internet. At the CLI type: ping google.ca

If your network is connected to the internet your readout should look similar to; (note hit CONTR-C to stop pinging)

ping google.ca
PING google.ca (74.125.226.88) 56(84) bytes of data.
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=1 ttl=52 time=202 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=2 ttl=52 time=119 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=3 ttl=52 time=150 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=4 ttl=52 time=142 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=5 ttl=52 time=152 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=6 ttl=52 time=127 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=7 ttl=52 time=138 ms
64 bytes from yyz06s07-in-f24.1e100.net (74.125.226.88): icmp_req=8 ttl=52 time=111 ms
^C
— google.ca ping statistics —
8 packets transmitted, 8 received, 0% packet loss, time 7001ms

If your network is NOT connected to the internet your readout should look similar to;

ping google.ca
ping: unknown host google.ca

This pretty much wraps up this post, it took a little doing but I’m glad I took the time to learn as much as I could about how a USB Wi-Fi module is set up on the Raspberry Pi. I’ll close this post with some of the Linux Command Line Commands I used (and learned) in tackling this project;

  • sudo reboot – reboots PI
  • ping google.com – pings website to ensure internet is active
  • startx – starts graphical user interface
  • sudo shutdown -h now – shuts off PI
  • sudo ifup wlan0 – wakes up wireless interface at wlan0
  • sudo nano /etc/network/interfaces – edits network interface for configuration
  • iwconfig – shows connected network interfaces
  • exit – logs out
  • sudo raspi-config – brings up Raspberry Pi Config Menu
  • clear – clears command line interface screen placing cursor at top of screen
Advertisements

One Response

  1. best instruction on the web for setting up wifi on a pi !!!! Great job and many thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: