I am using an MKR NB 1500 to send sensor data to the cloud. Periodically it locks up which I'm thinking may be a memory issue (that I do intend to try to resolve separately). I'd like to implement a WDT reset regardless, to ensure this thing keeps running seamlessly.
I've tried implementing the onboard WDT using the AdafruitSleepyDog library. The issue I'm having with that is the max timeout is ~8 sec from my understanding, which is not long enough. It can take 20 sec or more to connect to the MQTT broker (AWS), in which case the WDT is triggered before connecting.
I have been researching and it seems my best option is to use an external WDT so I can set a longer timeout. Is that the right path to pursue? I think I'm going to follow this tutorial, https://www.instructables.com/External-Hardware-Watchdog/ unless someone has other suggestions.
I have read about implementing a 555 timer for WDT, but I'd like to make the timeout configurable instead of having to change components.
A 555, old relic, circuit is a good idea. I don't remember the timing components but maybe a shift register can be used, switching in different caps or resistors, giving 8 preprogrammed timeouts.
I've read a bit about the problems that can cause. Just haven't taken the time to understand and implement the right way to replace the Strings. Any resources you want to point me to would be appreciated!
yes I've implemented that elsewhere in my code, that but in there is one case in which it doesn't work. I'm using the ArduinoMqttClient and the connectMQTT function takes ~20 seconds each time it attempts to connect to the client. You can even see in the code below where I attempted to insert a Watchdog.reset(); in the function to keep it from resetting during that function but that doesn't work (hence why it's commented out). It seems that the part that takes ~20 sec is waiting for it to ping the broker and get a response. I don't have the aptitude or interest in picking that function apart to figure out how to insert a WDT reset somewhere in the underlying function, nor does that seem necessary. So I still think an external WDT is my best route, but I'm open to suggestions.
void connectMQTT()
{
Serial.print("Attempting to MQTT broker: ");
Serial.print(broker);
Serial.println(" ");
while (!mqttClient.connect(broker, 8883))
{
// failed, retry
Serial.print(".");
// Watchdog.reset();
delay(2000);
}
Serial.println();
Serial.println("You're connected to the MQTT broker");
Serial.println();
}
I'm aware I need to figure out what's causing it to hang. I'm pursuing that in parallel, but regardless of that, I want a surefire means of a self-reset mechanism to ensure that this can keep running without intervention should it hang for any reason.
It’s worth a check that you aren’t getting power supply or sensor glitches causing the issue -ive had cases where a spike on an analog input has crashed and locked up a program .
Make sure power supply is big enough for the job
I had previously looked at the WDTZero library and somehow missed the callout on the longer intervals. Embarassing. I'll definitely be swapping to that library. Thanks!