Python Script to Configure WiFi On Raspberry Pi Without Reboot
In this short post, I will walk you through the steps of configuring Wifi on a Raspberry Pi device using a Python script. Generally, a reboot is required after a new Wifi config is added to the config file. We will learn how to avoid this step so that the newly added wifi config can be applied without a reboot.
The wifi configs on a Raspberry Pi are stored in the following file.
wpa_supplicant.conf file contents should look something like this:
Here’s a list of steps that we need to perform
- Make the
/etc/wpa_supplicant/wpa_supplicant.conffile editable by modifying its permissions
- Update the
wpa_supplicant.conffile with the desired wifi credentials.
- Refresh the Wifi configs on the Raspberry Pi to apply the changes. Once we refresh the configs, the Raspberry Pi will connect to the newly added config.
Here’s the python script that will do all of the above steps for you. It contains the
configure_wifi that takes in the wifi credentials and performs the required steps.
That’s it for this post. Please leave a clap if you found this article useful. Consider subscribing to Medium to read more of my stories.