Hardware Problems
Hardware Problems
The EP8266 is great: It gives your IoT device WLAN and IP connectivity for only a few bucks.
On the other hand, the ESP8266 is quite a hand full: It creates power spikes that have negative impact on its own operation, it has out-of-the-blue resets that have to be dealt with, and it experiences hang-ups that can be only cured with a hardware reset or "The IT Crowd" mantra ("have you tried turning it off and on again"; https://www.youtube.com/watch?v=nn2FB1P_Mn8).
I have had A LOT of problems with the ESP8266. Some can be solved with the proper power supply, a bit of hardware, and somewhat sophisticated error handling. Other, more persistent problems can only be addressed with resetting the chip or even cycling the power.
Power Supply
The chip sometimes needs quite a lot of power (current), in example when connecting to a WLAN, or setting up a connection. It definitely needs a proper power supply (using the 3.3V supply of the Arduino is NOT enough). Additionally, give it a 100uF or greater electrolytic capacitor across the power pins, as close to the chip as possible (I soldered it ONTO the chip). The capacitor acts as a buffer when the demand of the chip surges; this helps the stable, reliable operation of the chip and the operation of the rest of your device.
If you get erratic or unexpected behavior, try these measures first. I wasted hours looking for presumed software bugs that were caused by insufficient supply voltage, loose/ corroded contacts, and wimpy power supplies that could not supply the current required.