Raspbian Image - Howto Enable & Configure WiFi Before First Boot

How To Enable WiFi on Raspbian Image Before First Boot

NOTE: This method does NOT apply to Piaware SD card image. For Piaware SD card image, you have to edit file /boot/piaware-config.txt

 

All the steps below should be done while the microSD Card is still in the Laptop/Desktop’s card reader after writing the Raspbian image.

If you want your RPi to connect to local network/internet using a wired connection to router, do not enable WiFi, and skip this procedure.

If you want your RPi to connect to local network/internet using WiFi, enable Wifi as given below.

Use only one connection at a time, either wired or WiFi. It is not recommended to use both simultaneously.

STEP-1: After image is written, and while the microSD Card is still in the Laptop/Desktop, open File Explorer (Windows) or Finder (Mac), and open the microSD card.

NOTE:
If you have used Etcher, it will automatically eject the microSD card after writing the image.
Physically remove the microSD card or USB adapter and plug it back into the computer before you carry-out steps below.

STEP-2: The microSD card will appear with name “boot” as shown in screenshot below.

STEP-3: Open the drive named “boot”. This will open the /boot folder of PI24. In this folder create a new text file, as shown in screenshot below

STEP-4: Open the text file using Notepad (Windows) or TextEdit (Mac)
In the opened text file, copy-paste following text:

country=CA 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 
update_config=1 

network={ 
ssid="YOUR_SSID" 
psk="YOUR_PASSWORD" 
}

Replace:

  • CA by two letter code for your country e.g. GB for UK, US for USA, DE for Germany, FR for France, SE for Sweden, CH for Switzerland, NL for Netherland, AU for Australia, NZ for New Zealand, etc etc. (click here for complete list)

  • YOUR_SSID by your router’s wifi ssid

  • YOUR_PASSWORD by your router’s wifi password.

STEP-5: Save file.

STEP-6: Change the name of file from “New Text Document.txt” to “wpa_supplicant.conf”

NOTE: If your Desktop/Laptop does not show file extensions, the newly created file “New Text Document” will NOT show .txt extension at the end, as shown in screenshot below.

In the case of hidden extension .txt , even after you change file name to “wpa_supplicant.conf” its full name will be “wpa_supplicant.conf.txt” with “.txt” not visible. If the file has a hidden extension .txt, it will not enable wifi.

Configure Windows File Explorer to show file extensions as shown in the screenshots below:

Now change the name of file “New Text Document.txt” to “wpa_supplicant.conf” , as shown in screenshot below:

To Reconfigure WiFi at later stage:

The file wpa_supplicant.conf which you created in /boot folder is moved to folder /etc/wpa_supplicant, and after booting the Pi, you will NOT find it in /boot folder.

For editing the WiFi config later, open config file by following command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf  

 

NOTE:

You should also enable SSH while the microSD card is still in the card reader of Desktop/Laptop after writing the Raspbian image to microSD card. Please see this post:

For Beginners - How-to SSHto RPi - Setup Putty in Windows

 

 

2 Likes

You should add a note that SSH needs to be enabled as well, otherwise WiFi only doesn’t make that much sense.

The country code should be highlighted in red, took me forever to figure out that is what was needed. In older versions of raspbian that was not needed.

@foxhunter

Thanks for pointing out. Note added at the end of post.

@hellhound604
Cannot make “Country” red color. Flightaware Forum does not have provision to colour the text

2 Likes

Is there any way when using the piaware SD card image to use the standard WiFi configurations or to add multiple networks. As there are several benefits to this:

  1. can set the country code correctly
  2. can configure several networks, including a 5GHz and 2GHz one or a backup SSID
  3. can deal with hidden SSIDs and other WiFi configs

The latter would be very useful to ensure robust connectivity for remote deployments of piaware in a situation where several redundant networks are available.

It appears that the piaware image overwrites the standard wpa_supplicant.conf when it boots, and this only supports a single ssid as far as I can tell. If this is not possible due to ease of use issues on the SD card then can a feature request for the piaware-config file be added to support configuring multiple networks. While I could just build a clean install and add piaware, it is nice to use the SD card image as it supports the LCD for local screenless status checking.

1 Like

You can already set wireless-country

No, and there are no plans for this - the sdcard image deliberately only tries to handle configuring the relatively simple cases, not every possible case. If you need a custom wpa_supplicant setup, then a regular Raspbian image is the way to go.

1 Like

Thanks, so then a related question. If I install a regular raspbian and then add piaware, is there anyway to get the nice embedded LCD info screens to work. As access to the LCD is why I changed my setup and used the SD card image in the first place. I run headless so the status display is a nice touch.