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.

[sg_popup id=”3″ event=”onload”][/sg_popup]

Source: Wikipedia http://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:

Related posts

Leave a Comment