In Ubuntu 12.04 LTS (Precise Pangolin) you may experience that you can’t connect to a hotspot if the power cable isn’t connected. It’s supposedly a bug in Ubuntu’s Energy Management module.
So here’s the workaround:
Open up a Terminal and execute the following command:
sudo gedit /etc/pm/power.d/wireless
Enter your password when asked. A notepad-like application (gedit) will pop-up with the newly created file. Paste the following code:
/sbin/iwconfig wlan0 power off
Save the file and close gedit. Fix the file’s permissions from Terminal:
sudo chmod 777 /etc/pm/power.d/wireless
Reboot and enjoy your working WiFi.