@@ -270,7 +270,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
270270 * call to ArduinoIoTCloudTCP::update() it is wise to
271271 * set a rather large timeout at first.
272272 */
273- Watchdog.enable (120 * 1000 );
273+ Watchdog.enable (SAMD_WATCHDOG_MAX_TIME_ms );
274274#endif /* ARDUINO_ARCH_SAMD */
275275
276276 return 1 ;
@@ -279,15 +279,6 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
279279void ArduinoIoTCloudTCP::update ()
280280{
281281#ifdef ARDUINO_ARCH_SAMD
282- /* Now that we are within the regularly called function
283- * ArduinoIoTCloudTCP::update() it's a wise idea to reduce
284- * the watchdog timeout to a smaller amount of time.
285- */
286- static bool is_watchdog_set = false ;
287- if (!is_watchdog_set) {
288- Watchdog.enable (30 * 1000 );
289- is_watchdog_set = true ;
290- }
291282 /* Feed the watchdog. If any of the functions called below
292283 * get stuck than we can at least reset and recover.
293284 */
@@ -549,13 +540,21 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
549540#if OTA_ENABLED
550541void ArduinoIoTCloudTCP::onOTARequest ()
551542{
543+ #ifdef ARDUINO_ARCH_SAMD
544+ Watchdog.reset ();
545+ #endif /* ARDUINO_ARCH_SAMD */
546+
552547 DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s _ota_url = %s" , __FUNCTION__, _ota_url.c_str ());
553548
554549#if OTA_STORAGE_SNU
555550 /* Just to be safe delete any remains from previous updates. */
556551 WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS" );
557552 WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS.TMP" );
558553
554+ #ifdef ARDUINO_ARCH_SAMD
555+ Watchdog.reset ();
556+ #endif /* ARDUINO_ARCH_SAMD */
557+
559558 /* Trigger direct download to nina module. */
560559 uint8_t nina_ota_err_code = 0 ;
561560 if (!WiFiStorage.downloadOTA (_ota_url.c_str (), &nina_ota_err_code))
0 commit comments