Skip to content

Timeout vs. Sleeptime

jbaumann edited this page Mar 30, 2022 · 2 revisions

Timeout

The timeout interval is the maximum time between two communications between Raspberry Pi and ATTiny. After this timeout has been reached, the RPi is assumed to be shut down and, if the voltage level allows it (higher than the restart voltage), is restarted.

The challenge here is that there are situations during which the RPi is incommunicado without a need to restart it. One very prominent example is the reboot of the system. Depending on the periphery connected and the used boot delays a full reboot (from the stop of the daemon running on the RPi before shutting down to the restart of the daemon after booting) could take 30 seconds or even longer. If you are unsure then do a manual reboot and use a stopwatch to measure the time from you typing in the reboot command until the system is again reachable via ssh. This leaves you with an upper bound for the time needed for a reboot. Now multiply that by 2, and you have a safe margin, hopefully even if the last shutdown wasn‘t made orderly, and the system starts a file system check. If you want to cover all these cases, then choose a comparatively long timeout value e.g., something like 300 seconds. The effect of this is that now the time before a reboot is initiated in case the Raspberry has shut down is that much longer. Since we are talking about a system that should run all the time (this is what I assume with a system that has a UPS) this situation should happen nearly never anyways.

I‘ve been using 60 seconds without any problems so far, and feel quite comfortable with it.

Sleeptime

The RPi reads the register should shutdown in regular intervals. This interval is configured by the configuration option sleeptime.

The hard requirement regarding this interval is that it has to be shorter than the timeout, because otherwise the ATTiny would assume that the Raspberry has shut down. Additionally, timeout - sleeptime should be larger than the time needed for a reboot as well. This is easily explained: If we start the reboot of the RPi right before the end of one sleeptime interval, then the next read from the RPi has to happen in the remaining time until the timeout. If this difference is too low, the daemon running on the RPi writes a warning to the log.

The shorter this interval is, the sooner you get a warning regarding a low voltage situation. But at the same time you increase the power consumption of the ATTiny, and even with very small batteries (I‘ve experimented with 300-500mAh) you have a number of minutes to go from warn voltage down to shutdown voltage if you have a power outage.

TL;DR

The timeout is the time used by the ATTiny to determine whether the RPi is still alive, the sleeptime is the interval used by the Raspberry to get updates about the current situation from the ATTiny. The first should be comparatively long, the second comparatively short.

The values I use are 60 seconds for the timeout and 20 seconds for the sleeptime. But these come from my need to experiment and play with the system. Good values might be 120 seconds for the timeout and 40 seconds for the sleeptime in a production environment.