Back to Troubleshooting

ESP32 Fails to Reconnect to Wi-Fi Automatically

Fix scenarios where the ESP32 does not reconnect to Wi-Fi after signal loss, router reboot, or waking from deep sleep.

Common Causes

  • 🔁

    No Reconnection Logic in Code

    ESP32 does not reconnect automatically unless you explicitly implement retry logic using event handlers or timers.

  • 🌙

    Deep Sleep Without Wi-Fi Resume

    After waking from deep sleep, the ESP32 does not retain Wi-Fi credentials or connection state unless managed manually.

  • ⚠️

    Router Takes Time to Restart

    The ESP32 may give up reconnecting before the router is ready again after a reboot or power failure.

  • 🧯

    Static IP Used Without Retry

    A static IP setup may not retry DHCP if reconnection isn’t triggered on disconnect, leaving the ESP32 offline.

Symptoms

ESP32 Connects Once, Then Stops

Works on boot, but fails to reconnect after Wi-Fi is interrupted or the board resets.

Serial Log Shows Disconnected but No Reconnect

Logs include WiFi lost but no attempt is made to re-establish the connection.

Manual Reset Restores Connection

Pushing the reset button or power-cycling the board reconnects Wi-Fi, confirming code logic is the issue.

Fails to Reconnect After Deep Sleep

Board wakes successfully but does not rejoin Wi-Fi unless manually reset or rebooted.

Solutions

Add Reconnection Event Handling

Use WiFi.onEvent() to detect disconnects and call WiFi.reconnect() automatically.

Implement Retry Timer

Use millis() or a periodic check to retry connecting if WiFi.status() != WL_CONNECTED.

Save Wi-Fi Credentials and Restore on Wake

In deep sleep applications, save credentials to RTC memory or use persistent WiFi.begin() logic on boot.

Use Longer Retry Timeout or Watchdog

Allow more time for the network to come back online after router reboots before giving up.

More Details

ESP32 Fails to Reconnect to Wi-Fi Automatically #

The ESP32 connects to Wi-Fi on boot, works as expected, but then disconnects and never reconnects unless you manually reset it. This is a common pitfall in many ESP32-based projects where reconnect logic isn’t properly implemented or deep sleep behavior isn’t handled correctly.

This guide explains why the ESP32 doesn’t reconnect automatically after a disconnection and how to reliably restore Wi-Fi connections in all scenarios.


What Causes Reconnect Failures? #

🔁 No Reconnect Logic in Code #

Unlike many mobile devices, the ESP32 does not automatically reconnect to Wi-Fi after losing signal or after the router reboots — unless your code tells it to. If you only call WiFi.begin(ssid, password) once in setup(), the device won’t attempt reconnection after a dropout.

🌙 Coming Back from Deep Sleep #

When the ESP32 wakes from deep sleep, all RAM (except RTC memory) is cleared. That includes any stored Wi-Fi connection state. Unless you re-run your connection logic on wake-up, the device will boot without any network access.

⚠️ Router Reboot Takes Time #

Many routers take 20–60 seconds to reboot. If the ESP32 tries to reconnect immediately and fails, and you don’t retry later, it will remain offline.

🧯 Static IP Without Retry Handling #

If you’re using a static IP with WiFi.config(), and don’t actively check for connection status, the ESP32 will think it’s connected (IP is set) — but it won’t be online if the Wi-Fi handshake didn’t complete. Reconnection must be triggered manually.


Detecting Reconnect Issues #

  • Serial monitor shows:
WiFi disconnected. Reason: 200

but nothing follows.

  • After a power blink or Wi-Fi outage, the ESP32 never reconnects unless reset.

  • In deep sleep projects, the device wakes up and runs code, but network functions (MQTT, HTTP, etc.) fail silently.


How to Fix Reconnection Problems #

✅ Use Wi-Fi Event Handlers #

Add this in your setup() function to listen for disconnection events:

WiFi.onEvent([](WiFiEvent_t event){
if (event == SYSTEM_EVENT_STA_DISCONNECTED) {
Serial.println("WiFi disconnected! Attempting reconnect...");
WiFi.reconnect();
}
});

This ensures a reconnect is triggered automatically whenever the link drops.

✅ Periodically Check and Reconnect #

If you prefer a simpler method, poll WiFi.status() in loop():

if (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, password);
}

Use a timer or interval to avoid hammering the connection.

✅ Handle Deep Sleep Properly #

On wake from deep sleep, re-initiate the Wi-Fi connection in setup():

WiFi.begin(ssid, password);

Optionally, store credentials in RTC memory or EEPROM and restore on wake-up. You can also delay actions (like MQTT publish) until Wi-Fi is confirmed:

while (WiFi.status() != WL_CONNECTED) {
delay(500);
}

✅ Add Retry Delay or Watchdog Recovery #

If the router is still rebooting when the ESP32 tries to reconnect, it may fail too early. Use a retry loop or watchdog to keep checking for available networks before proceeding.

Conclusion #

The ESP32 doesn’t reconnect to Wi-Fi by default — especially after disconnections or deep sleep. But with a few lines of code, you can make it resilient and always online.

Checklist:

  • Use WiFi.onEvent() to handle drops

  • Re-run WiFi.begin() after wake-up or failure

  • Don’t rely on static IP to mean you're connected

  • Add logging to catch missed events

With proper reconnect handling, your ESP32-based device can operate reliably over hours, days, and beyond — even in dynamic Wi-Fi environments.

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.

No registration required. Start solving issues right away!