I've found a problem with arduino uno wifi that cannot be solved using the watchdog because of the limitation of max delay WDTO_2S on this board.
My project implements a "smart thermometer", which communicates via mqtt with a message broker (mosquitto). Then I can activate the wdt only at the end of the setup after the connection to the wifi network and then to the message broker.
The system works pretty well, but frequently disconnects from the wifi net during the normal work executed in the loop so that the wdt ends up restarting the board. However, sometime the board doesn't restart at all. My guess is that this is because of an error in the setup during the WiFi or the PubSubclient connections. Anyone had a similar experience? Any idea of how I could set a WDTO long enough to allow the normal setup to be completed?
Thanks for your attention
Any idea of how I could set a WDTO long enough to allow the normal setup to be completed?
The ATmega4809 can set the watchdog timeout up to 8seconds.
Another way may be to reset the watchdog several times during a long setup(). Everything is speculation until we see your code!
My guess is that this is because of an error in the setup during the WiFi or the PubSubclient connections.
You're guessing an error in your code but you don't post it?
Thanks for your answer. Actually, by trying I've discovered that, even if the constant is not defined in the wdt library available for arduino uno wifi, you can define it yourself up to 16 second (#define WDTO_16S 15). Apparently it works and I'm currently testing the program. Up to now it seems to work. I'll keep you informed.
Abaout the programming error I think that should be a bug in Ethernet library or in the PubSubclient.
It is just a guess because the setup was the only part of the program not covered by wdt.
Well, I've solved the problem. Just because it can be useful to someone else I summarize the lesson I've learned.
- in wdt library (depending on the board) not all the delays are defined. In Arduino uno the maximum is 2 seconds, in other cases it seem that it arrave to 8 secondes. Nevertheless you can define it yourself up to 16 seconds and it works.
- the method connect*() in pubSubClient of Mqtt library, sometime hangs when tries to connect to the message broker. This was the cause of my problem. By setting wdt with 16 seconds before calling connect() you leave enough time for completing the connection when it succeed and you reset the board when the method hangs.
Anyhow, it should be worth fixing the bug in the connect() method, but I'm not familiar with code of PubSubClient library.
In Arduino uno the maximum is 2 seconds,
Wrong! An Arduno UNO WiFi is not an Arduino UNO!
For the UNO's ATmega328p all steps up to the 8 seconds it supports are defined.
Anyhow, it should be worth fixing the bug in the connect() method, but I'm not familiar with code of PubSubClient library.
I don't get the impression that the bug is in the PubSubClient library. If there is a bug I'd vote for the WiFiNINA library.