I am having trouble getting the watch dog timer to work. I have read multiple posts on various forums and what I have done looks standard but nothing happens.
This is one where I want to reboot if I don’t get a tcp connection within 60 seconds
// Start TCP Client
// Reboot if we don't get TCP Connection within 60 seconds
LoopExitTime = millis() + 60000;
while ( ( !myTcpClient.connect( SrvrIP, Port ) ) && ( millis() < LoopExitTime ) )
{
delay(10);
}
// Reboot
if ( millis() > LoopExitTime )
{
Serial.println( F( "Failed to open TCP connection" ) );
delay(200);
wdt_enable(WDTO_15MS);
}
Serial.println( F( "TCP running" ) );
In this one, I have a function which waits 70 seconds for input from a serial device (Dylos dust monitor).
When I set thinhs up so that failures occur - stop tcp listener in first example, turn power off to Dylos in second - nothing happens. I get the diagnostic message on the serial monitor showing the logic clearly arrives in that branch but the sketch logic does not restart.
… does not appear in the output list along with all the other “included” files.
I thought the WDT stuff may be native so I commented out this include statement and tried to compile, I got error messages that both ‘WDTO_15MS’ and ‘wdt_enable’ were not declared in this scope. I found all this very confusing.
I haven’t worked with the watchdog before, but it seems that you’re definitely using the best method you can. Have you got a bit of serial printing that triggers when your code starts so you can tell when it restarts?
From the code you’ve posted so far, I can’t see any errors, but could you post the rest as well?
I’ll do some experimentation on my end to try and get a watchdog to work in my instance
-James
I would have thought the WDT (enabled at WDTO_1S ) would have kicked in before the 16:40:26.281 line.
While working out what to say here, I continued searching and I think I have found the (an?) answer. I was going to pull the pin but then I thought you may be interested in what I found.
At this address: Watchdog Timer in Arduino | Arduino
I found an example that is very close to mine above except that it has a delay after the wdt_disable statement. With that in place it works perfectly. I tried the 3000ms in the example but cut that back to 500 and it worked fine.
I now need to work out whether I need to do this just once or in multiple logic paths.
Still happy to share my full sketch with you. I plan to do so soon anyway when I have got it fully “productionised”.
1 Like
And you can get our latest projects and tips straight away by following us on: