Sunday, April 10, 2016

Setting up your wifi network on Raspberry Pi Jessie

In this blog entry  I am going to document some tasks that must be completed when Raspberry Pi boots the first time under the Jessie operating system. For this instructional I am using this release of Raspian Jessie on a Raspberry PI 2.

  No LSB modules are available.   
  Distributor ID: Debian   
  Description: Debian GNU/Linux 8.0 (jessie)   
  Release: 8.0   
  Codename: jessie   

The device boots up on its own. But under the first boot you will notice some subtle things you will need to do to make the device functional. The most obvious thing you will want to do is bring up the wifi network interface and configure the default gateway for network routing. You will need to edit some config files, which are rather simple and straight forward to modify. This will lead to one subtle and annoying thing you must edit first which has nothing to do with network configuration. The default keyboard configuration is for a UK keyboard layout. I am in the US and I found the keys, like the " and the @ symbol are swamped - among others! 

Setting the Keyboard Layout to US

My first step was to edit my default keyboard config file for a US keyboard.  To edit the deyfault keyboard file, you will need to open a terminal window on your Raspberry Pi . Type the following command from your terminal,


 sudo nano /etc/default/keyboard   


 You will need to locate setting XKBLAYOUT="uk" field in this file and change it to "us".
 

 XKBLAYOUT="us"  


To exit the nano editor, press the keys, CTRL-X. Then answer Y-yes to save the file.  

The Raspberry Pi will then need to be rebooted.

 sudo reboot  

After the system has rebooted we can proceed to setting up the wifi network.


Configuring the Wifi Network on the Raspberry Pi

My Raspberry Pi was originally running wheezy. I had a lot of wifi issues under the old operating system and I could never get my USB wifi to run properly. Under Jessie, my wifi came right up!

Open a terminal window and let's bring up your wifi. From the terminal window command line you will need go to the wifi configurations directory. We're going to edit the wpa_supplicant.conf  file.

 cd /etc/wpa_supplicant  
 sudo nano wpa_supplicant.conf  


Add the following lines to wpa_supplicant file. Note that the SSID is your wifi network name, and the psk is the password field for your wifi network.


 network={  
     SSID="MY_WIFI_NETWORK_NAME"  
     psk="my_wifi_network_password"  
 }  

To exit the nano editor, press the keys, CTRL-X. Then answer Y-yes to save the file.  

A true unix administrator would bring up the network interface rather than reboot. I could not get my wifi network to reset with the commands,


 sudo ifdown wlan0  
 sudo ifup wlan0  

I opted for the complete device reboot. 

 sudo reboot  

When the device reboot is completed you should be able to ping the address of your default gateway router (your wifi).

Configuring the Default Gateway

Now we have a wifi network, but you probably noticed your web browser doesn't work. What happened?

The default gateway is not configured on the Raspberry Pi. The Raspberry Pi is confined to accessing only devices that are on the same network subnet.

This is not straight forward in Raspian OS. I initially tried simply configuring the default gateway from the terminal window with the command route add,  where the gateway address on my network is 10.0.0.1.
     
 sudo route add default gw 10.0.0.1  

This worked fine until I rebooted my Raspberry Pi and I lost my network default gateway. I wanted a permanent solution. Of course the solution is not so obvious, but here is what I found googling for an answer. Let the device determine the default gateway! 

You will need to edit your /etc/network/interfaces file from a terminal window.

 sudo nano /etc/network/interfaces  

Add the following configuration to this file,

 auto eth0

To exit the nano editor, press the keys, CTRL-X. Then answer Y-yes to save the file.   

And of course - reboot!

 sudo reboot  


 By now you should have usable internet connection to start configuring the rest of your Raspberry Pi. Hope this helps you in bringing up your Raspberry Pi.