Try to account for infrequent weird RTC times.

This commit is contained in:
mattbk 2023-09-06 22:07:48 -05:00
parent afe5b9338d
commit f496a10ef2

View File

@ -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 <ESP_IP>/get?inputFloat=<inputMessage>
if (request->hasParam(PARAM_FLOAT)) {