Search code examples
pythonbeagleboneblackioctlwatchdog

Beaglebone Black watchdog in Python


I have a Beaglebone Black running Debian and I need a script running in background, which would check every few seconds if the system is still running. As far as I understand, watchdog in BBB is hardware-based and runs independently from OS, so it can reboot the device even if OS is completely frozen (right?). Here is a very simple example from logicsupply:

#!/usr/bin/env python

import time
import os

os.nice(20)
time.sleep(60)                  # Wait before starting
wd = open("/dev/watchdog", "w+")
while 1:
     wd.write("\n")
     wd.flush()
     time.sleep(5)

But I can't find a way to change default timeout. In C it would look like:

ioctl(fd, WDIOC_SETTIMEOUT, &timeout);

But calling ioctl functions in Python seems to be rather obscure. From this discussion it seems like C macro definitions may have different values depending on hardware. Is there a convenient way to address them (at least, this particular one, to change default watchdog timeout) in Python? And what is the best way to run the script in background so that it could reboot the system with a frozen OS?


Solution

  • This comment by Padraic Cunningham has directed me to the manpage for watchdog.conf which is the right and working way to configure the hardware WDT on AM335x, so there's no need for additional scripts/daemons:

    watchdog-timeout = 10