Chronicles of the Afro Kid
Chronicles of the Afro Kid

Setting up WiFi on Raspberry Pi 2

Riyadh Al Nur
Tags: raspberry , pi , ssh , wifi , linux , ubuntu , snappy

Raspberry Pi in enclosure

TL;DR I recently purchased a Raspberry Pi 2 and picked up a WiFi adapter from TP-Link to go with it. Naturally, my aim is to be able to SSH into my Pi and not have a screen connected to it at all times. As seen in the image at the beginning of this post, the only wire I have connected is the power cable (I have wiring OCD). I installed Ubuntu Snappy Core. It's lightweight and designed for developers but since it's the bare basics, a lot of hardware might not work directly just like my WiFi Adapter. Setting it up is easy though now that at least wpasupplicant comes pre-installed in Snappy Core. Until you have WiFi up and running, you will need to connect the Pi to a monitor/TV, and a keyboard and mouse.

TP-Link WiFi Adapter

Fire up a new file using your preferred text editor. Snappy comes with vi installed and not nano.
sudo vi /etc/network/interfaces.d/wlan0

In the file,

auto wlan0 #autostart on machine boot  
allow-hotplug wlan0 #enable hot-plugging  
iface wlan0 inet dhcp #interfaces  
wpa-conf /home/ubuntu/wireless-setup.conf #location of wifi configuration file  

I commented each line describing the purpose of each one.

Now moving on to the configuration file to connect to the WiFi network,
vi /home/ubuntu/wireless-setup.conf

  ssid="mywifi" #wifi ssid
  psk="mywifipass" #wifi password

The configuration file is self explanatory. Save this file and run ifup wlan0 to fire up WiFi. You can run ifconfig to see the list of all the network interfaces.

To check if your WiFi connects automatically on boot, run sudo reboot and after logging in, run ifconfig again. You should see the WiFi interface listed.

Now that we have all that sorted, you can SSH into the Pi using it's assigned network address. You can usually find this in your router's configuration page.

SSHing into Pi