ESP32 Disconnects Randomly from Wi-Fi
Troubleshoot unexpected or periodic Wi-Fi disconnections on ESP32, especially in long-running applications or under poor signal conditions.
Common Causes
- 📶
Weak or Unstable Wi-Fi Signal
Poor RSSI levels, interference, or distance from the router can cause the ESP32 to lose its Wi-Fi connection intermittently.
- ⏱
Power-Saving or Sleep Mode
ESP32 default power management may disable Wi-Fi periodically or reduce signal stability unless explicitly configured.
- 🔧
Router Incompatibility or DHCP Timeout
Some routers have compatibility issues or short lease times that cause the ESP32 to disconnect and reconnect frequently.
- 📡
Overlapping Channels or RF Noise
Congested 2.4GHz spectrum (from neighboring networks, microwaves, etc.) can cause random disconnects or low-quality links.
Symptoms
Serial Monitor Shows Wi-Fi Disconnected Messages
Logs show WiFi disconnected
, Reason: 200
or similar codes without a clear pattern.
Works Initially, Then Drops After Minutes or Hours
ESP32 connects successfully at startup, but loses connection after some time without user action.
Works on One Network, Fails on Another
Stable on some routers but disconnects frequently on mesh networks, hotspots, or ISP-provided routers.
Disconnection Triggers Unexpected Reboots
Disconnection coincides with watchdog resets or loop crashes, especially when reconnect logic isn’t handled properly.
Solutions
Disable Wi-Fi Power Save Mode
Use WiFi.setSleep(false)
in your setup code to disable power-saving behavior that can cause disconnections.
Move Closer to Access Point or Improve Signal
Reduce distance, avoid walls, and try non-overlapping channels to improve Wi-Fi reliability.
Increase DHCP Lease Time
Adjust router settings to extend DHCP lease time and prevent periodic disconnections from expired leases.
Implement Reconnect Logic in Code
Use event handlers to detect disconnections and trigger reconnects programmatically to maintain uptime.
More Details
ESP32 Disconnects Randomly from Wi-Fi #
An ESP32 that boots and connects successfully to Wi-Fi - only to disconnect minutes or hours later - is one of the most frustrating issues to debug. These random or periodic disconnections often don't follow a clear pattern and may happen under load, at idle, or after specific intervals.
This guide walks through the most common reasons for unexpected disconnections and how to fix them for stable long-term operation.
Common Symptoms #
You may observe:
- Serial monitor outputs like:
[WiFi-event] Disconnected. Reason: 200
- Disconnection after a set interval (e.g., 1 hour)
- ESP32 reboots when Wi-Fi disconnects (if not handled properly in code)
- Works fine on some routers, fails on others
These clues point to one of several common causes.
Key Causes of Random Wi-Fi Disconnection #
📶 Weak or Unstable Wi-Fi Signal #
If the ESP32 is too far from the router or surrounded by interference (walls, appliances, metal), the signal may fluctuate. This causes dropped packets and ultimately disconnects.
You can check RSSI with:
Serial.println(WiFi.RSSI());
Values weaker than -75 dBm
often indicate unstable performance.
⏱ Wi-Fi Sleep Mode Interferes with Stability #
By default, the ESP32 uses a power-saving Wi-Fi mode that periodically disables parts of the transceiver. On some routers, this causes synchronization problems, especially under poor signal.
To disable it:
WiFi.setSleep(false);
Place this before WiFi.begin()
in your setup code.
🔧 Router DHCP Timeout or Lease Issues #
Many routers issue short DHCP leases (e.g., 1 hour). If the ESP32 doesn’t renew in time or the lease is lost during a signal glitch, the router may drop the connection.
This often results in disconnection after predictable time intervals (like every 3600 seconds).
To resolve:
Set a longer lease time in router settings (e.g., 24h or infinite)
Or assign a static IP with:
WiFi.config(local_IP, gateway, subnet, dns);
📡 RF Interference or Channel Crowding #
The 2.4GHz band used by ESP32 is shared with Bluetooth, microwaves, and many other Wi-Fi networks. If your network overlaps with many others on the same or nearby channels (e.g., channel 6), congestion can cause disconnects.
Use a Wi-Fi analyzer app to scan channels and select a less crowded one in your router’s settings.
Best Practices to Prevent Random Disconnects #
✅ Disable Wi-Fi Power Save Mode #
This is the single most effective fix for long-running applications:
WiFi.setSleep(false);
This ensures the ESP32 maintains a full-time connection and avoids router sync issues.
✅ Add Reconnection Logic #
Detect disconnects and automatically reconnect using event handlers:
WiFi.onEvent([](WiFiEvent_t event){
if (event == SYSTEM_EVENT_STA_DISCONNECTED) {
Serial.println("WiFi lost, reconnecting...");
WiFi.reconnect();
}
});
Or use a timer to check WiFi.status()
and reconnect periodically.
✅ Use Static IP on Unreliable Routers
By setting a fixed IP, you bypass DHCP lease expiration issues.
✅ Improve Antenna Position or Shielding
Even with onboard PCB antennas, signal quality improves dramatically if:
The ESP32 is mounted vertically
Kept away from metal enclosures
Uses an external antenna (if available on your module)
Conclusion #
Random Wi-Fi disconnects on ESP32 often stem from weak signal, router quirks, or power-saving behaviors. These aren’t bugs in your code - but environmental or configuration issues.
To keep the ESP32 connected:
Disable sleep mode
Improve signal quality
Handle disconnects in software
Consider a static IP or longer DHCP lease
A stable Wi-Fi connection is key to reliable IoT systems - and with the right tweaks, ESP32 can maintain a connection for days or even weeks without issue.

Quick Navigation
Additional Resources
Still Stuck with an ESP32 Issue? Let's solve it together.
Our interactive troubleshooting wizard will guide you through common ESP32 problems and their solutions, step by step.