From f496a10ef272d6b8ea3e2a58e7512d16e562cee2 Mon Sep 17 00:00:00 2001 From: mattbk Date: Wed, 6 Sep 2023 22:07:48 -0500 Subject: [PATCH] Try to account for infrequent weird RTC times. --- vulpes/src/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 403a7f0..3679732 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -555,9 +555,16 @@ void setup() { inputMessage = request->getParam(PARAM_TIME)->value(); //https://stackoverflow.com/a/22733127/2152245 yourInputTime = atol(inputMessage.c_str()); + Serial.print("yourInputTime: "); Serial.println(yourInputTime); // update the RTC time rtc.adjust(DateTime(yourInputTime)); + // Might work to fix random errors? If date is far in the future, + // try to update again. + while(rtc.now().year() > 2100){ + Serial.println("RTC can't set time. Trying again."); + rtc.adjust(DateTime(yourInputTime)); + } ; DateTime now = rtc.now(); Serial.print("UTC time from browser: "); @@ -575,6 +582,9 @@ void setup() { Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); + + Serial.print("rtc.now().unixtime(): "); + Serial.println(rtc.now().unixtime()); } // GET inputFloat value on /get?inputFloat= if (request->hasParam(PARAM_FLOAT)) {