arduino uno watchdog example

i have implemented a watchdog routine in the following mathlab ino. will someone guide me if this is correct.

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <avr/wdt.h>

//Enetr a MAC address and IP address for your controller below.
// The Ip address will be dependent on your local network

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,100);

char linebuffer[20];
int linenumber = 0;

boolean isTemp =false;

//Temperature Variables
float tempC;
byte byteH;
byte byteL;
int temp;

// Initialize the ethernet server library
// with the ip and and port you want to use
// (port 80 is the default for HTTP)
EthernetServer server(80);

void setup() {
  //open serial communication and wait for port to open:
  wdt_disable();
  Serial.begin(9600);
  
  pinMode(2, OUTPUT);
  // start etehrnet connection and server
  Ethernet.begin(mac, ip);
  server.begin();
}
  
void loop() {
  // listen for incoming clients
  wdt_enable(WDTO_8S);
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    
    // an http request ends with a blank line
    boolean currentLineIsBlank =true;
    
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you have gotten to the end of line (recieved a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          parseRequest();
          sendHTTPResponse(client);
          wdt_reset();
          char linebuffer[20]; // clear buffer
          linenumber = 0; // reset buffer
          
          break;
        }
        if (c == '\n') {
          // you are starting a new line
          currentLineIsBlank = true;
        }else if (c != '\r') {
          if(linenumber < 20){//if there is room in the buffer
            linebuffer[linenumber] = c; //Add char to buffer
            linenumber++; //increment counter
          }
          // you have gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
   //give webbrowser time to recieve data
   delay(10);
  // close the connection
 client.stop();
 Serial.println("client disconnected");
 wdt_reset();
 }
}


void parseRequest(){
  if(linebuffer[5] == 'O' && linebuffer[6] == 'N'){//if request was for /ON
  // Turn LED on
    isTemp = false;
  digitalWrite(2, HIGH);
  wdt_reset();
  
  }else if(linebuffer[5] == 'O' && linebuffer[6] == 'F'){ //if request was for /OFF
  // turn led off
    isTemp = false;
  digitalWrite(2, LOW);
  wdt_reset();
  }else if(linebuffer[5] == 'T' && linebuffer[6] == 'M' && linebuffer[7] == 'P'){ // if request was for temp
  // respond with temp
    isTemp = true;
    wdt_reset();
  }else{
    isTemp = false;
    wdt_reset();
  }
}  

void sendHTTPResponse(EthernetClient client){
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html"); 
  client.println("Connection: close"); // the connection will be closed after completion of the response
  client.println();
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  if(isTemp){ //if request is for temp
    getTempCent(); //get the temp
    client.println(tempC); // send the temp
  }else{
    client.println("OK"); // else send OK
  }
  client.println("</html>");
}


void getTempCent()
{
  Wire.requestFrom((0x91 >> 1), 2); // request 2 bytes of data from the temp sensor
  byteH = Wire.read(); // read the higher byte
  byteL = Wire.read(); // read the lower byte
  temp = (byteH << 4); // Bitshift the MSB left
  temp |= (byteL >> 4); // Bitshift the LSB right and logic OR with the MSB
  tempC = (temp*0.0625); //scale from binary range by resolution multiplier to degree celsius
}

Does it do what you want ?

If not, what does it do ? And what do you want it to do ?

...R

i am using arduino to control a 5v relay module the sketch is running ok but i am not sure if the watchdog is properly implemented.

Thanks

rajbadri: i am using arduino to control a 5v relay module the sketch is running ok but i am not sure if the watchdog is properly implemented.

Have you some way to force the watchdog to intervene - that seems an essential test. Maybe write another program with the same watchdog code but something that, for example, sends it into an infinite loop.

...R