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.
Comments
No comments yet. Share your experience or ask a question.