Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Automatically Apply A WiFi Network Configuration To A Raspberry Pi

TwitterFacebookRedditLinkedInHacker News

As you probably know, I’m a fan of the Raspberry Pi and Pi Zero Internet of Things (IoT) devices. Well, I recently had a moment where I felt like a total newbie. I go through a lot of installations of Raspbian Linux and during every installation I go through a network configuration process. This process of configuration is either by Ethernet or UART connection. Well, it turns out there is an easier way.

It is actually possible to apply a network configuration through the FAT mountable partition saving the hassle of having to connect over UART or Ethernet first. We’re going to see how this is possible.

In case you haven’t already seen the previous articles I wrote on the subject, you might benefit from learning how to configure a Raspberry Pi as a headless unit as well as using the GPIO pins for a UART connection.

So let’s assume you’ve just installed a fresh copy of Raspbian to a micro SD card. As it turns out, in 2016 Raspbian started looking for a particular file in the boot directory of the mountable FAT partition. More information on this set of updates can be found on the Raspberry Pi blog.

Mount your micro SD card to a Windows, Mac, or Linux host computer and open the boot directory. What you’ll want to do is create a file called wpa_supplicant.conf at the root of this directory. This file should contain something like the following:

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

network={
    ssid="NETWORK_NAME"
    psk="WPA_PASSWORD"
}

You’ll want to replace the SSID and the WPA with that of your actual wireless network. What is happening is Raspbian will replace the Linux file equivalent file found at /etc/wpa_supplicant/wpa_supplicant.conf with the file that you’ve provided. This happens when you try to boot the Raspberry Pi.

After the Raspberry Pi or Pi Zero has finished booting, you can connect to it over WiFi. If you’re using a Pi Zero, but aren’t sure how to get wireless internet, check out a few options on the subject.

Conclusion

There are many ways to take control of your Raspberry Pi or Pi Zero device. While you could use UART or Ethernet to configure the wireless access point information, it is no longer necessary. Instead you can just create a simple file after flashing the micro SD card with your network information. This can save a lot of time, specially if you’re constantly installing Raspbian like I am.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in C#, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Unity. Nic writes about his development experiences related to making web and mobile development easier to understand.