Settings up multiple wifi connections


4 posts
by insidus » Wed Jul 18, 2012 4:06 pm
Heres the deal. I currently live between 2 houses atm, and i would like to set up the PI to be able to connect too either 1 of 2 connections, depending where i am.

/etc/networks/interfaces
Code: Select all
auto lo
iface lo inet loopback

#auto eth0
#iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet static
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1


How could i add another connection, say
Code: Select all
address 192.168.2.10 etc

and make it pick that connection over the first.

I'd also have to change the /etc/wpa_supplicant/wpa_supplicant.conf file
Code: Select all
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1

network={
  ssid="thename"
  psk="thekey"
  proto=WPA
  key_mgmt=WPA-PSK
  pairwise=TKIP
  group=TKIP
}


Thanks for any help, greatly appreciated
Posts: 4
Joined: Wed Jul 18, 2012 10:34 am
by abishur » Wed Jul 18, 2012 4:23 pm
Two thoughts come to mind

First, is the basic problem that they share the same SSID, but not other details? Otherwise, on the WPA key, can't you have multiple SSID stored in there? If you have control over both networks, I'd just make them match each other so you don't have to swap anything around

Second, if that's just not a feasible solution I would write a simple bash script that did the following

1. Rename the current interfaces file to house1.bak or house2.bak depending on which house you're at.
2. Rename the appropriate houseX.bak file to interfaces
3. Restart Networking

Add that script to /usr/bin and you can simply type house1 or house2 at the prompt and it will make all the changes for you.

Edit: There might be a fancier way that a more experienced linux user could mention, that's just off the top of my head talk ;-)
Dear forum: Play nice ;-)
User avatar
Forum Moderator
Forum Moderator
Posts: 4263
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
by insidus » Wed Jul 18, 2012 4:42 pm
I should have made that clearer. Both connections do have different SSID/Passwords and that, and i did think about making a script to do it, but there must be a way to do it automatically :(
Posts: 4
Joined: Wed Jul 18, 2012 10:34 am
by abishur » Wed Jul 18, 2012 5:01 pm
In that case, beyond either setting your pi to DHCP and letting it automatically select the appropriately stored SSID and getting it's IP automatically or writing a script and setting the IP statically, I don't know of any fancier ways to do this ;-)
Dear forum: Play nice ;-)
User avatar
Forum Moderator
Forum Moderator
Posts: 4263
Joined: Thu Jul 28, 2011 4:10 am
Location: USA