|
43 | 43 |
|
44 | 44 | #include "cbor/CBOREncoder.h"
|
45 | 45 |
|
| 46 | +#include "utility/watchdog/Watchdog.h" |
| 47 | + |
46 | 48 | /******************************************************************************
|
47 | 49 | * EXTERN
|
48 | 50 | ******************************************************************************/
|
@@ -262,11 +264,36 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
|
262 | 264 | }
|
263 | 265 | #endif /* OTA_STORAGE_SNU */
|
264 | 266 |
|
| 267 | +#ifdef ARDUINO_ARCH_SAMD |
| 268 | + /* Since we do not control what code the user inserts |
| 269 | + * between ArduinoIoTCloudTCP::begin() and the first |
| 270 | + * call to ArduinoIoTCloudTCP::update() it is wise to |
| 271 | + * set a rather large timeout at first. |
| 272 | + */ |
| 273 | + Watchdog.enable(120 * 1000); |
| 274 | +#endif /* ARDUINO_ARCH_SAMD */ |
| 275 | + |
265 | 276 | return 1;
|
266 | 277 | }
|
267 | 278 |
|
268 | 279 | void ArduinoIoTCloudTCP::update()
|
269 | 280 | {
|
| 281 | +#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 | + } |
| 291 | + /* Feed the watchdog. If any of the functions called below |
| 292 | + * get stuck than we can at least reset and recover. |
| 293 | + */ |
| 294 | + Watchdog.reset(); |
| 295 | +#endif /* ARDUINO_ARCH_SAMD */ |
| 296 | + |
270 | 297 | /* Run through the state machine. */
|
271 | 298 | State next_state = _state;
|
272 | 299 | switch (_state)
|
|
0 commit comments