How to Configure Raspberry Pi to Auto-Connect to a Wi-Fi Hotspot
Follow these steps to configure your Raspberry Pi to automatically connect to a Wi-Fi hotspot when it is in range:
-
Open the network configuration file
wpa_supplicant.conffor editing. Use the following command:sudo nano /etc/wpa_supplicant/wpa_supplicant.conf -
Add the following configuration to include your hotspot details:
Replacenetwork={ ssid="Your Hotspot SSID" psk="Your Hotspot Password" priority=1 }Your Hotspot SSIDwith the name of your hotspot andYour Hotspot Passwordwith its password. Thepriorityvalue ensures your Raspberry Pi prefers this network if multiple are available. -
Save the file and exit the editor:
- If using
nano: PressCTRL+Oto save, thenCTRL+Xto exit. - If using
vim: Type:wqand pressEnter.
- If using
-
Restart the networking service to apply the changes:
sudo systemctl restart networking.service sudo systemctl restart dhcpcd.service -
To verify the connection, activate your hotspot and check whether the Raspberry Pi connects to it automatically:
Ensure theifconfigwlan0interface shows an IP address assigned by the hotspot network.
If the Raspberry Pi does not connect automatically, ensure the SSID and password are correct and your hotspot is active. Optional configurations (such as setting a static IP for easier SSH access) or troubleshooting steps can help refine the setup.
Additional Notes
- To add multiple networks, include multiple network blocks in wpa_supplicant.conf and assign priority values to prioritize them.
- Use the wpa_cli reconfigure command if you need to reload the configuration without restarting the services.
Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Education and Culture Executive Agency (EACEA). Neither the European Union nor EACEA can be held responsible for them.
Project Number: 2023-3-CY02-KA210-YOU-000173087