ESP32 loses Wi-Fi or will not reconnect

Why the connection drops after hours or days, what to set in the code and how to make a node recover by itself.

Dropped connections have a short list of causes, and most are cheap to fix. Start with the ones that cost nothing.

Check the network first

  • The ESP32 works on 2.4 GHz only. If your router merges bands under one name, give the 2.4 GHz network its own name for the first test.
  • Set the router channel manually to 1, 6 or 11 with a 20 MHz width. Automatic channel hopping can drop devices that are not expecting it.
  • Use WPA2 rather than a mixed or WPA3-only mode if the connection fails to start.
  • Look at the signal strength (RSSI). Below roughly −75 dBm the link is fragile; move the board or the access point.

Check the board

A weak supply causes silent resets that look like Wi-Fi problems, so read the brownout guide if the board restarts. Keep metal and wires away from the antenna, and on very small boards expect a short range.

Change the code

  • Turn Wi-Fi power saving off if the board must respond quickly: WiFi.setSleep(false).
  • Register a disconnect handler and call reconnect, instead of only connecting once in setup.
  • Reboot after the network has been gone for several minutes. It sounds crude, and it is the most reliable recovery for unattended nodes.
  • Do not do long blocking work on the same core as the Wi-Fi tasks.

For many nodes

If several battery nodes talk to one place, ESP-NOW avoids the router entirely and uses far less energy. See the ESP-NOW network idea.

Tools that help

  • AI Error Doctor — Paste a Serial Monitor error or a sketch and get a plain-language cause, step-by-step fix and corrected code.
  • Web serial monitor — Read ESP32 Serial logs over USB in Chrome or Edge: 9600 / 115200 / 460800 baud, clear, download .txt and send errors to the AI Error Doctor.

Projects related to this guide

⚠ Caution

Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.

Router reboot when the internet dies

Pings a few addresses and, if the connection is really gone, power-cycles the router through a relay, with limits so it never reboot-loops.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit
⚠ Caution

Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.

ESP-NOW sensor network with one gateway

Several battery nodes send readings over ESP-NOW without joining Wi-Fi, and one gateway forwards them to MQTT or Home Assistant.

  • Board ESP32-C3 SuperMini
  • Level ●●● Advanced
  • Build time 2–4 h
Pick parts / kit

Read next

← All guides

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.