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:

  1. Open the network configuration file wpa_supplicant.conf for editing. Use the following command:
    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
  2. Add the following configuration to include your hotspot details:
    
    network={
        ssid="Your Hotspot SSID"
        psk="Your Hotspot Password"
        priority=1
    }
                
    Replace Your Hotspot SSID with the name of your hotspot and Your Hotspot Password with its password. The priority value ensures your Raspberry Pi prefers this network if multiple are available.
  3. Save the file and exit the editor:
    • If using nano: Press CTRL+O to save, then CTRL+X to exit.
    • If using vim: Type :wq and press Enter.
  4. Restart the networking service to apply the changes:
    
    sudo systemctl restart networking.service
    sudo systemctl restart dhcpcd.service
                
  5. To verify the connection, activate your hotspot and check whether the Raspberry Pi connects to it automatically:
    ifconfig
    Ensure the wlan0 interface 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.

Co funded by the EU

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