DV Industrial Computer Ltd.
 | News | Products | Support | Ordering |   
TeleServ Example of using of WatchDog timer

The WatchDog timer is designed to overpass a computer hanging up. Usually computer almost never hangs up. However, if it hangs up and gets stuck, usually there is nobody at the site to press the reset or nobody knows where the stuck computer is because there were no problem with it for a long time. The WatchDog timer is used just for such situations. It automatically restarts the computer that is hung up. The WatchDog timer is off after starting of the controller. To switch it on, the command “Esc[WW” should be sent and timeout (number of ticks, one tick is 0.3 seconds) should be set by indicating required W, which is a value between 0 and 255. To switch the timer off, timeout should be set to 0 by "Esc[W0" command. The special driver is used to load and to control timeout counter. To ensure non-stop running of the computer, the driver should set the timeout periodically to avoid that the WatchDog hits with following “reset” contacts closing. If your computer ever locks up, the driver no longer sets the timeout and the WatchDog hits – “reset” contacts are closed. The WatchDog is designed in such way that it hits only once. This allows to avoid it hitting again during the file system check which will probably follow after the reset (or after power on start). When the computer comes up again, the driver program needs to re-enable it (to send the command Esc[WW with needed timeout). The WatchDog guarantees that the system is always able to execute programs. It does not guarantee that application is still running and responding. To check such things, you can use a crontab entry for Linux/UNIX or other programs. You can be confident that the crontab will be working because the WatchDog ensures that software in general is still executing. For example, you can design a script that is triggered by a cronjob and downloads a webpage from your webserver every 50 seconds. However, you have to be careful with that: a webserver can get heavily loaded with a lot of requests and it is normal if it does not answer all of them.

For our example we have created a script watchdog.cgi to learn the WatchDog timer facilities in interactive mode. Operation of this script is tested in OS SuSE Linux, however they should operate in any other Unix like OS. Interface with the controller is allocated in special module TeleServ.pm. You should copy this file in any directory and you should define environment variable PERLLIB. The easiest way is to add to the file /etc/profile the following string:

    PERLLIB=”the name of your directory”
    export PERLLIB

You can indicate directory where modules would be searched in the script adding at the beginning of the script the following directive:

    use libs “the name of your directory”

This way is more preferable because the script is run as a CGI program under web server Apache. To get it, both web server and script watchdog.cgi that provides such service should be installed and run. This script is tested with installed web server Apache on controlled (remote) host. Execution of CGI programs should be enabled in Apachе settings (refer to documentation of web server for instructions). Script watchdog.cgi should be copied to controlled host in directory where CGI program are located. To test it you can run web browser and enter local URL of script in the address string, for example:

    http://127.0.0.1/cgi-bin/watchdog

The following page with table should appear:



Fill in the Refresh time field with the time of automatic information update on browser screen. The comfortable time is 2-3 seconds.

Fill in the WatchDog timeout field with the initial value of counter (for example, 50 seconds).

Fill in the Update time field with the time of update of initial value of counter (for example, 30 seconds).

Clicking on button start runs page with continuous updating (time of update is indicated in Refresh time), takes up the counter of timer into initial value and allows to watch the downcounting and then taking up the counter of timer. Do not connect J13 of the controller to “reset” connector of motherboard when you play with refresh time and update time. Otherwise every time when counter value is zeroizing the computer resets.

If the host is connected to the net, URL of script should be entered in the address string of your browser. Then you can watch the same page.


Home | Contact Us | About Us |