With so many smart devices at home, my router occasionally freezes, requiring a manual reset to get back online. Until I invest in a more powerful router, this is the solution I found: a device that automatically resets the router if the internet goes down.
Materials Needed
ESP32-C3 Super Mini
Simple relay module for Arduino (5V)
LM2596 3A buck voltage regulator
2.1mm threaded P4 power connector
Old power cable or similar alternative
Some screws salvaged from an old hard drive
Wires for connecting the components
Tools Needed: Soldering kit (iron, solder, and flux)
Breadboard
Multimeter
3D printer to print the box (if you don't have one, you can get creative and invent something)
USB-C cable
Steps
Prototype the project on a breadboard or similar.
Assemble the final device in the box. The 3D model is quite tight, so be patient. There are 3 screws: two for the voltage regulator and one for the cover, but I think they are all dispensable.
Adjust the voltage regulator to 5V. DO THIS BEFORE CONNECTING ANYTHING TO ITS OUTPUT.
Insert your Wi-Fi data into the code and upload it to the ESP32 using the Arduino IDE.
Conclusion
This regulator is fixed regardless of the input, that is, once adjusted to 5V, regardless of the power source used to power the system, the output will always be 5V.
The code is available on GitHub for any possible future updates: https://github.com/etcho/esp32-router-watchdog/blob/main/esp32_watchdog.ino
To facilitate testing, a button is configured in the code that simulates an internet outage, so you don't need to turn off the router to test. This button is not used when assembling the final project.
Brief explanation of the code:
- Boot: starts, connects to Wi-Fi and marks the boot time.
- Initial lockout: after boot, router reset actions are blocked for 5 minutes (for the router to finish booting up).
- Periodic checks: every 5 seconds the device checks external connectivity (ping to 3 public hosts).
- Timeout/attempts per test: each attempt has a short timeout (≈1 s) and uses 1 attempt per host (configurable).
- Failure counter: if ALL 3 hosts fail a check, it increments a counter of consecutive failures.
- Trigger logic: only when the counter reaches the threshold (5 consecutive checks) and the initial 5-minute lockout has passed, the device activates the relay to reset the router for 5 seconds.
- Post-reset window: after a reset, the system waits 5 minutes before allowing another reset.
- Attempt limit: each router reset increments a counter; if 3 consecutive resets are reached without restoring the connection, the device restarts itself (reboot).
- Manual button: for testing purposes only, if the button is pressed, the device's Wi-Fi is turned off while it is pressed; when released, it attempts to reconnect and clears the counters.
- All these values and times are configurable in the code.