Connect to Multiple Wireless Networks

To have a Raspberry Pi scan and automatically connect to different wireless networks:

sudo nano /etc/network/interfaces

Remove all extra entries so it only has the following:

auto lo
iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp 
pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

Edit wpa_conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Make sure it is exactly as shown below. Add the SSID and Secret Key for each network:

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

network={
  ssid=”SSID 1″
  scan_ssid=1
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk=”The encryption Key for this network goes here”
  }

network={
  ssid=”SSID 2″
  scan_ssid=1
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk=”The encryption key for this network goes here”
  }

Reset the wireless network

(Can use --force with ifup and ifdown)

ifdown wlan0; ifup wlan0
ifconfig

You should now see an IP Address next to wlan0 if it has connected to the wireless network.

With hidden SSIDs you must include

bssid=mm:aa:cc:aa:dd:rr

(See https://www.raspberrypi.org/forums/viewtopic.php?t=66656&p=488120)

Enter the MAC address of the access point in the network={...} block in your supplicant config.

 


Source: http://www.instantsupportsite.com/self-help/raspberry-pi/raspberry-connect-multiple-wireless-networks/