User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Multiple wifi profiles

Sat Aug 23, 2014 5:27 pm

I'm sure this is a pretty simple question, but I just haven't found the answer yet...

I have a raspberry pi that I take around the country with me when I visit various family members. I'd like to be able to configure the Pi to connect automatically to the various wifi networks at each location rather than having to do this manually each time.

The Pi runs Raspbian and headless so the configuration would need to be done from the command line.

My /etc/network/interfaces file typically looks like this:

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static
address 192.168.0.41
netmask 255.255.255.0
gateway 192.168.0.254
wpa-ssid "MyHomeSSID"
wpa-psk "MyHomePassword"
So I'd really like some way to list all SSIDs and passwords (for home, parents etc etc) and have the machine connect automatically. One complication is that the gateways may also change.

I like to use static IPs as I often need to SSH into the Pi for various reasons, but I'm happy to give this up if there's a good reason to (i.e. easier to configure and still easy to access via SSH)

I could probably knock up a script in python to do this, but I suspect there is a more correct way of doing this!

Any comments/solutions would be greatly appreciated.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Multiple wifi profiles

Sat Aug 23, 2014 8:14 pm

I think that if you use wpa-supplicant, you can add multiple networks. (Getting a new fuse for my pi so can't test it right now).
Change your interfaces file and take out the ssid and PSK and put in:

Code: Select all

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Next in /etc/wpa_supplicant/wpa_supplicant.conf, put in the following and replace the ssid, PSK and the nickname.

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="SCHOOLS NETWORK NAME"
    psk="SCHOOLS PASSWORD"
    proto=WPA
    key_mgmt=WPA-PSK 
    pairwise=TKIP
    auth_alg=OPEN
    id_str="school"
}

network={
    ssid="HOME NETWORK NAME"
    psk="HOME PASSWORD"
    proto=WPA
    key_mgmt=WPA-PSK 
    pairwise=TKIP
    auth_alg=OPEN
    id_str="home"
}
And then change the static ip from iface wlan0 inet static to iface home inet static and then add another entry for your other network.
There are 10 types of people: those who understand binary and those who don't.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Multiple wifi profiles

Sat Aug 23, 2014 9:35 pm

Great. Thanks for this. I'll give it a try and report back.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Multiple wifi profiles

Mon Aug 25, 2014 7:19 am

Thanks kusti8. That seems to be working nicely so far.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Return to “Networking and servers”