Access Watchdog Timer of Raspberry Pi using JAVA

Ot with raspberry p using JAVA

This tutorial is all about using the watchdog timer of Raspberry Pi by using JAVA. For this, we are going to use Pi4J library. Watchdog Timer: “watchdog timer (sometimes called a computer operating properly or COP timer, or simply a watchdog) is an electronic timer that is used to detect and recover from computer malfunctions. During normal operation, the computer regularly resets the watchdog timer to prevent it from elapsing, or “timing out”. If due to a hardware fault or program error, the computer fails to reset the watchdog, the timer will elapse and generate a timeout signal. The timeout signal is used to initiate corrective action or actions. The corrective actions typically include placing the computer system in a safe state and restoring normal system operation.

Source: Wikipedia bit.ly/2ybQuE9

Video:
Code:
import com.pi4j.io.wdt.WDTimer;
import com.pi4j.io.wdt.impl.WDTimerImpl;
import java.io.IOException;

public class MainClass {
    public static void main(String[] args) throws IOException, InterruptedException {

     
        WDTimer watchdog =  WDTimerImpl.getInstance();

        watchdog.open();

        int timeout = watchdog.getTimeOut();
        System.out.println("Timeout of WatchDog is "+timeout);
  
        watchdog.setTimeOut(15);//1-15 Seconds
        Thread.sleep(18000);
        watchdog.heartbeat();
           
        watchdog.disable(); 
        watchdog.close();
        System.out.println("WatchDog closed.");
    }
}

 

Buy Products:
Links:
Bikash Panda
Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WeArGenius
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Bikash Panda

A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.