Getting your Pi set up for WiFi

Setting up WiFi

The small size of the Raspberry Pi unchains it from a desk; Power it with batteries and it can roam cable free! Add WiFi and it can be deployed anywhere.

Setting up WiFi on a Raspberry Pi is as simple as creating a file on the SD card, these steps will allow a new system to connect effortlessly to your own network, perfect for headless setups/robots/quick testing.

Of course if your Raspberry Pi has a screen, mouse and keyboard this can be completed on the desktop with a few clicks. This is perfect for a system that only has power and is in range of a WiFi router.

What do you need?

Most importantly, you need a Raspberry Pi with WiFi capability, either via a wireless dongle or any Raspberry Pi 3 onwards, or ZeroW has this capability on board. Any Raspberry Pi below 3 will require a USB dongle to add wireless capability.

SD card with Raspbian installed.

Got those, what now?

Slight caveat

As you will be changing file extensions, you may need to change your settings to show this, otherwise the files won’t work as intended;

Windows

As standard, file extensions are hidden for common files to save accidental changes, as we’ll be changing a file from .txt extension to .conf, we need to see what we are doing.

Go to Control Panel, and change the View by: to Large Icons

Click Folder Options

Now click the View tab at the top of the window

Untick the Hide extensions for known file types

Click OK, and close Control Panel.

 

Writing the Settings

Pop the SD card in to a computer and access the filesystem by clicking on the drive that’ll appear – This can be completed on any system, be it Windows, Mac, Linux or Android, all we are doing is creating a simple text file.

Click, create a new file, and called this file;

wpa_supplicant.conf

Open this file in your favourite text editor, and copy and paste the following;

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
  ssid="NAME OF NETWORK"
  psk="PASSWORD TO LOGIN TO NETWORK"
}

Simply change the ssid and psk to your own network details.

The SSID is the broadcast name of the WiFi router, the name of the network your connecting to. The PSK is the password (Pre-Shared Key) to allow your device to decrypt the information flowing between itself and your router, or password to make it easier.

If you plan to move your Raspberry Pi around between multiple networks, or want to add a second network for redundancy, just add another network block to the end of your file, the Pi will connect to any network it sees and recognises in the list.

network={
  ssid="NAME OF SECOND NETWORK"
  psk="PASSWORD TO LOGIN TO SECOND NETWORK"
}

Save the file and close your editor.

Allowing SSH connections

If you have a configured setup, such as a web server, or script that runs automatically and you don’t need to access, you can skip this step.

If this is a new headless (without screen, mouse and keyboard) this would prove handy, allowing you to login and setup/configure software, check its’ status all remotlely from another computer.

Due to the security risk of having an SSH server running would allow anyone with access to the network the ability to login to your Raspberry Pi, so only enable if you require it, and change the default password from raspberry as soon as you login to increase the security of the device.

Back at the SD card, create a file called;

ssh

That is it, the file doesn’t need any contents, or extension.

Now what?

Remove the SD card from your computer, if you aren’t rebellious to just remove it, make sure you Eject the media safely prior to removal.

Put the SD card in the Raspberry Pi and add power, after a minute or so, the device will be connected and be available to use. As the address is normally assigned automatically by the DHCP server built in to your router, it’ll be given a random number, so using a network scanner such as SoftPerfect Network Scanner to find the IP allowing you to connect to it.