I would suggest backing up your Pi and installing the latest official raspbian image from scratch. Do an upgrade and firmware upgrade. The reason I suggest it because it has wpa-supplicant pre installed and all you need to do is add 3 or 4 lines in to the supplicant file.
This is different because the interfaces file uses wpa-roam. Thanks to that line if you loose connection wpa-supplicant will try to reconnect to the next access point in the file. If there is only one it will try to reconnect to that one only.
I was messing about for weeks with an old image that was upgraded and had lots of rubbish. COnnection was dropping out all the time and it was driving me mad. I put on the latest image and my wifi is stable now. I could not run for an hour or more -with the new install it is going for over 24hours now. I am not sure how many times it reconnects but I know it is connected the whole time now.
Interfaces file
#/etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
The supplicant file
#/etc/wpa_supplicant
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="ssid_leave_the_quotes"
proto=WPA RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="password_leave_the_quotes"
}
Proto: WPA is WPA1. RSN is WPA2. If you leave both supplicant will figure out which one but if you dont specify one in there it wont automatically detect and use it.
pairwise: CCMP is AES counted. TKIP is WPA2 key manager. Again if you leave both supplicant will choose the correct one.
key_mgmt: will always be WPA-PSK for home routers. If you have a private key router this will be different and you will know what to put there.
/var/log/syslog
.