Raspberry Pi: Multiple wpa_supplicant networks
Imagine building a raspberry pi project at home that is dependent on wifi. Everything is working perfectly until you move that project somewhere outside your home network. You have to go find a monitor and keyboard to set it up on the new wifi. This process is difficult, time consuming, and stressful. I have had the pleasure to endure this multiple times throughout my projects. Especially when there is pressure to have it done for a public event. I was curious if there was a way to get the networks to be plug and play, where there would not be an issue when moving it from one place to another. Doing a bit of research I have found that you can setup multiple wireless networks on the raspberry pi. There are two pieces in which were new to me for the wpa_supplicant file:
- id_str This will be the name we will save for later to reference this network .
- Priority The higher the number, the higher the priority is for that network if it finds two from the list
In the example below, I have my home network as the first one it will connect to if it finds it. If I plug it in at Spruce it should be already ready to go. If the two of those can not be found I have a backup hotspot on my phone to make the magic happen. Below is an example of the wpa_supplicant file.
/etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="Hemstreet Home Network" psk="SuperSecretPassword!" id_str="home" priority=1 } network={ ssid="Spruce" psk="beards are good and stuff" id_str="spruce" priority=2 } network={ ssid="Cell Hotspot" psk="SecretPassword" id_str="cell" priority=3 }
In the example below you can notice that the 2nd column is the corresponding id_str we had set earlier in our wpa_supplicant file.
/etc/network/interfaces
iface home inet dhcp iface spruce inet dhcp iface cell inet dhcp