Skip to content
Boaz Feldboim edited this page Nov 21, 2020 · 23 revisions

Arduino Internet Recovery Box

This project is intended to run on an Arduino MEGA2560 board with Ethernet Shield 2. What it does is continuously ping a server on the internet and optionally a local address on the LAN. If ping fails, it switches the router power to off and then on after several seconds. Then it waits for internet connectivity to resume. If internet connectivity is not resumed after some time, it switches the modem power to off and then on after several seconds. Then it waits for internet connectivity to return. If internet connectivity does not return, it goes again through the recovery attempts cycles until internet connectivity returns, or maximum recovery cycles exceeded.

There are quite a few configurable parameters to this software, like name of server on the internet to ping, an optional alternative internet server to ping if the ping to the first server failed. Also the time for power disconnect and waiting time for connection to resume is configurable and more.

For turning the power off and on, it is necessary to have a two relay board wired to two GPIO pins. The pin numbers are also configurable.

There is also an implementation of a web (HTML) site that is used for controlling and configuring the software. The web site also has a page for reporting recoveries history.

The files in the SD directory should be (tree) copied to an SD card and be placed in the Ethernet Shield 2.

Edit the content of file config.txt on the SD card. The content is pretty much self-explanatory. The TimeServer parameter is used for setting the server name used for getting the current GMT time using NTP protocol. The TimeZone parameter is used to set the local time. The value is in minutes and can also be negative. Then there are parameters for setting Ethernet. The code uses static IP address so the site address is always the same. Then you can also set the pin numbers for switching the router and modem power using relays.

The application is running a state machine that starts in a state where it tests the connectivity using sending ping messages to configurable addresses. If it finds that the connectivity is OK it waits a configurable time an then test connectivity again and so on. If connectivity is lost, it starts a recovery cycle. First it turns off the power to the router waits a configurable time and turns on the router power. Then it waits a configurable time for the connectivity to resume. While it wait for the connectivity to resume it continuously sends ping messages to the configured addresses. If connectivity is resumed within the configured time, it returns to the first state. If connectivity was not resumed, it turns off the modem power waits a configurable time and turns on the modem power. Then it waits a configurable time for the connectivity to resume. If connectivity was resumed, it goes to the first state. Else it starts a new router recovery. This can go on forever, until connectivity is resumed, or a configurable maximum number of recovery cycles.

The recovery control module that is internally implemented by a state machine (described above) that exports an observers object that triggers events upon changes in recovery states. One observer is updating the user interface. A second observer is triggering another state machine that generate history information about previous recoveries.