I'm streaming

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 lower 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

An inventive, entrepreneurial and positively unsatisfied mind that constantly pushes the tech boundaries to create new solutions and devices that change people’s lives.

4 Comments
  1. Reply saki June 9, 2016 at 11:48 pm

    this is really too useful and have more ideas from yours. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.

    • Reply Jon Hemstreet June 10, 2016 at 7:47 am

      Glad you found it useful!

  2. Reply Gissa August 30, 2016 at 5:03 am

    The information you provided about Raspberry pi for enabling to know with the multiple networks. I am expecting more concepts like this. And i have one idea to implement with the camera recording project. Is it easiest for using raspberry pi or something else??

    • Reply Jon Hemstreet September 16, 2016 at 8:40 pm

      A raspberry pi may be the way to go if cost / form factor is not a concern. Personally I have not messed too much with a camera on the raspberry pi. The fact that it is a computer w/ an OS makes it that much easier to program.

Leave a Reply