Skip to content

Commit c6f0336

Browse files
committed
Since the watchdog timeout can't be larger than 16 seconds adjust the code accordingly. Also add watchdog resets within the OTA callback to prevent the watchdog from biting during OTA.
1 parent 50183c2 commit c6f0336

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/ArduinoIoTCloudTCP.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -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)
279279
void 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
550541
void 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))

src/utility/watchdog/Watchdog.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#ifdef ARDUINO_ARCH_SAMD
2626
# include <Adafruit_SleepyDog.h>
27+
# define SAMD_WATCHDOG_MAX_TIME_ms (16 * 1000)
2728
#endif /* ARDUINO_ARCH_SAMD */
2829

2930
#endif /* ARDUINO_AIOTC_UTILITY_WATCHDOG_H_ */

0 commit comments

Comments
 (0)