From 80ed2d83e907b06fedb1a5de622dea5ed7ef50ed Mon Sep 17 00:00:00 2001 From: technyon Date: Wed, 6 Apr 2022 18:49:40 +0200 Subject: [PATCH] restart device when millis is about to overflow --- main.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.cpp b/main.cpp index 8f7de36..fd453b3 100644 --- a/main.cpp +++ b/main.cpp @@ -39,11 +39,28 @@ void presenceDetectionTask(void *pvParameters) } } +void checkMillisTask(void *pvParameters) +{ + while(true) + { + vTaskDelay( 60000 / portTICK_PERIOD_MS); + // millis() is about to overflow. Restart device to prevent problems with overflow + if(millis() > (2^32) - 5 * 60000) + { + Serial.println(F("millis() is about to overflow. Restarting device.")); + vTaskDelay( 2000 / portTICK_PERIOD_MS); + ESP.restart(); + } + } +} + + void setupTasks() { xTaskCreate(networkTask, "ntw", 32768, NULL, 1, NULL); xTaskCreate(nukiTask, "nuki", 8192, NULL, 1, NULL); xTaskCreate(presenceDetectionTask, "prdet", 1024, NULL, 1, NULL); + xTaskCreate(checkMillisTask, "mlchk", 512, NULL, 1, NULL); } uint32_t getRandomId()