Published on December 10, 2018
A watchdog is an electronic timer used for monitoring hardware and software functionality. Software uses a watchdog timer to detect and recover fatal failures.
In this short tutorial, we will setup a watchdog software  on Raspberry Pi.
In this setup, we are specifically interested in network failures. We will configure the watchdog to reboot the board if network is down for too long.
The purpose of the Meazurem gateway is to listen sensor data and upload the data to the cloud. So it’s very important that the gateway stays connected to the Internet.
Otherwise, the data upload would fail. To resolve Internet connectivity issues automatically, we’ll setup the watchdog to reboot the board.
We are using the latest official Raspberry Pi Linux distribution called Raspbian. At the time of writing, the latest version is 9.4 (stretch).
First, log in and configure Internet connectivity on your Raspberry Pi.
The next step is to install the watchdog software:
sudo apt-get install watchdog
Then check the approriate network interface you want to check:
For the WiFi interface, we’ll get something like
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.11 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 aa11::bb22:cc33:dd44:ee55 prefixlen 64 scopeid 0x20<link> ether aa:bb:cc:dd:ee:ff txqueuelen 1000 (Ethernet) RX packets 395 bytes 116061 (113.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 345 bytes 50275 (49.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
It’s also possible to check any other interface such as 3G/4G modem. This is especially useful if you have the gateway at a remote location with wireless broadband.
Now, configure the watchdog
sudo nano /etc/watchdog.conf
Something like this, for example:
# use the correct interface from the previous step interface = wlan0 # timeout [sec] until reboot retry-timeout = 60 # an internet or local address to test, for example 192.168.0.1 ping = 188.8.131.52 # interval [sec] of testing the connectivity interval = 15
In this example, the watchdog monitors wlan0 interface (used for Wi-Fi connectivity). The watchdog will test the network connectivity (by pinging to 184.108.40.206) once per 15 seconds, and reboot the board if the network is down for longer than 60 seconds.
Finally, start the watchdog service
sudo service watchdog start
That’s it. You can check the status of the watchdog anytime by running
sudo service watchdog status
It’s very important to test the watchdog functionality after the setup. This is to make sure you configured it correctly and it really works the way you intended!
Remember to do this step every time you change the configuration!
Create a free account and get started with one sensor.
: watchdog(8) - Linux man page, https://linux.die.net/man/8/watchdog