Here at Cranfield University we use Raspberry Pi computers for a number of applications, such as monitoring environmental sensors and processing data. The devices get moved around the campus and need to work across multiple WiFi networks with ease ad without the need for reconfiguration. Here is how this is done (make backups of the files before editing!).
First, edit file /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="SSID_1" psk="PASSWORD_1" } network={ ssid="SSID_2" psk="PASSWORD_2" }
Second, edit file /etc/network/interfaces
# The loopback network interface auto lo iface lo inet loopback # The primary wired network interface iface eth0 inet dhcp # The wireless network interface allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf # Default iface default inet dhcp
Reboot the Pi after the edits. This approach uses DHCP for connecting to the network.