So far I've tried to get closer to the AP, changing channels and testing the example sketches to eliminate any potential issues arising from other parts of my code. Nothing has helped.
If I power cycle the ESP about 10 or so times it connects flawlessly. I wrote a code that will reset the module (ESP.reset()) if it fails to connect, but even after running it for 30 minutes (reset every 20 seconds) it still can't get access to the network, so only power cycling works. Maybe there's something cached that I don't know about, has this happened to anybody else?
EDIT
These are the messages I get from debug serial:
scandone
state: 0 -> 2 (b0)
Connecting to AP: 4a82dd
state: 2 -> 0 (2)
reconnect
f 0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f -180, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f 0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f -180, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f r0,