- Accurate diagnosis by interpreting WiFi.status() status codes and disconnection reasons.
- Importance of stable power supply to avoid restarts due to brownout and transmission power management.
- Correct configuration of the 2,4 GHz band, compatible channels and WPA2 security protocols.
- Automatic reconnection strategies and implementation of static IPs to improve device stability.
Dealing with wireless connectivity on the ESP32 can be a real headache, especially when the code seems perfect but the serial monitor keeps spitting out endless dots. Don't despair, because most of the time it's not a hardware failure , but rather technical details in the router configuration or electrical problems that go unnoticed at first glance.
To bring order to this chaos, it's crucial to understand that the chip follows a logical process: it searches for a network, authenticates, performs the security handshake, and finally requests an IP address. If you know exactly at which step your device is stuck, finding the solution will be a piece of cake , saving you hours of pointless firmware flashing.
Interpreting status codes and connection errors
The most powerful tool you have is function WiFi.status()If you print this value, you'll see numbers that tell you the truth about what's happening. For example, if you see a state of 6, the device is still disconnected; if it goes to 0, it has already connected to the router and is just waiting for an IP address; and state 3 means you're already browsing. If you're stuck in state 1, it's very likely that The ESP32 hasn't even found the SSID that you have configured.
When the connection drops, the ESP-IDF core generates reason codes. If you see reason 15 or 202, you've almost certainly entered the wrong password or the encryption type is incorrect. On the other hand, code 201 usually indicates that the access point hasn't been located, which means you should check the signal strength or the band configuration.
The problem of eating and the dreaded brownout

A very common symptom is that the board restarts right when it tries to activate the Wi-Fi radio. This happens because the transmitter causes current spikes of up to 400 mA, which can cause the 3,3 V voltage to drop sharply. The chip detects this and triggers the "Brownout detector was triggered" error , entering an infinite loop of restarts that can drive you crazy.
To solve this, the first thing to do is pull good quality and short USB cablesbecause long or cheap cables cause voltage drops. If the problem persists, you can try lowering the transmission power using the function WiFi.setTxPower()Reducing the power to 15 dBm or even 8,5 dBm decreases power consumption peaks and, in many clone boards or Super Mini models, is the only way to achieve a stable connection without adding external capacitors.
Router configuration and hardware limitations

It's crucial to remember that the ESP32 only communicates on the 2,4 GHz band. If your router is dual-band and uses the same name for both bands, the chip should connect, but sometimes the router tries to force the device onto the 5 GHz band, causing frequent disconnections. The best solution is to create a separate 2,4 GHz guest network or use separate SSIDs for each band to avoid confusion.
Additionally, the Wi-Fi channel matters. While channels 1 through 11 always work, channels 12 and 13 can cause problems depending on the region. The safest option is to set the router's channel to 1, 6, or 11. Regarding security, the ESP32 prefers WPA2-Personal; if you use older protocols like WEP, the Arduino core will reject them by default unless you use a specific protocol. WiFi.setMinSecurity().
Advanced tips: Static IPs and corporate networks

If your router's DHCP server fails or you need your ESP32 to always have the same address to set up a web server, the best option is to configure a static IP address using WiFi.config()It is essential that this address be outside the automatic allocation range of the router to avoid conflicts with other devices in the house.
In university or office environments that use WPA2-Enterprise (such as eduroam), the conventional connection method will not work. For these cases, you must use a variant of WiFi.begin() that allows you to enter your PEAP username and ID. If it still doesn't connect, check if the network has a MAC address filterIn which case you will need to provide the network administrator with your network card's MAC address.
Quick diagnosis using the mobile hotspot

When you're unsure whether the problem lies with your motherboard or the router, the best test is to use your smartphone's hotspot. Configure your phone with a simple name, without spaces or special characters, and make sure to enable the " maximize compatibility" option (which forces the 2,4 GHz band). If the ESP32 connects to the phone but not the router, then the hardware is fine and the problem is with the router's configuration.
To prevent your project from going permanently offline after a power outage, implement a reconnection routine based on millis(). Avoid using delay() Long periods in the loop prevent the board from checking the network status. A good practice is to attempt reconnection every 15 seconds and, as a last resort, run a ESP.restart() if several minutes pass without success.
WiFi stability on the ESP32 depends on a balance between a robust power supply, an interference-free 2,4 GHz network configuration, and the correct interpretation of system error codes. By combining the use of WiFi.status() for diagnosis, the adjustment of setTxPower() To avoid power restarts and for intelligent reconnection management, most connectivity failures can be eliminated, ensuring that the device remains operational in any environment.
FAQ
Why does my ESP32 keep restarting when trying to connect to WiFi?
This is usually due to the brownout detector, which activates when the voltage drops due to peak WiFi power consumption. It can be fixed by using a higher-quality USB cable or reducing the transmission power with WiFi.setTxPower().
What does it mean if the WiFi.status() value is 1 or 6?
State 6 indicates that the device is disconnected or starting the process, while state 1 means that the ESP32 has failed to find the network with the provided name.
Is the ESP32 compatible with 5 GHz WiFi networks?
No, ESP32 modules only work on the 2,4 GHz band. If the router only broadcasts on 5 GHz or tries to force that band, the device will not be able to connect.
How to fix connection errors on university networks or eduroam?
These networks require WPA2-Enterprise, so the PEAP-specific WiFi.begin() method must be used, providing identity, username, and password.
What is the purpose of configuring a static IP address on the ESP32?
It helps avoid relying on the router's DHCP server, ensuring that the device always has the same IP address, which is ideal for web servers.
What to do if the serial monitor shows infinite unconnected dots?
It is recommended to use a diagnostic sketch that prints the status code and the reason for disconnection, in addition to testing the connection with a mobile hotspot to rule out router failures.
Does the router channel affect the ESP32 connection?
Yes, some channels like 12 and 13 may not be actively detected. Ideally, you should configure your router to a fixed channel like 1, 6, or 11.