Try to account for infrequent weird RTC times.
This commit is contained in:
parent
afe5b9338d
commit
f496a10ef2
|
@ -555,9 +555,16 @@ void setup() {
|
||||||
inputMessage = request->getParam(PARAM_TIME)->value();
|
inputMessage = request->getParam(PARAM_TIME)->value();
|
||||||
//https://stackoverflow.com/a/22733127/2152245
|
//https://stackoverflow.com/a/22733127/2152245
|
||||||
yourInputTime = atol(inputMessage.c_str());
|
yourInputTime = atol(inputMessage.c_str());
|
||||||
|
Serial.print("yourInputTime: ");
|
||||||
Serial.println(yourInputTime);
|
Serial.println(yourInputTime);
|
||||||
// update the RTC time
|
// update the RTC time
|
||||||
rtc.adjust(DateTime(yourInputTime));
|
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();
|
DateTime now = rtc.now();
|
||||||
Serial.print("UTC time from browser: ");
|
Serial.print("UTC time from browser: ");
|
||||||
|
@ -575,6 +582,9 @@ void setup() {
|
||||||
Serial.print(':');
|
Serial.print(':');
|
||||||
Serial.print(now.second(), DEC);
|
Serial.print(now.second(), DEC);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
|
Serial.print("rtc.now().unixtime(): ");
|
||||||
|
Serial.println(rtc.now().unixtime());
|
||||||
}
|
}
|
||||||
// GET inputFloat value on <ESP_IP>/get?inputFloat=<inputMessage>
|
// GET inputFloat value on <ESP_IP>/get?inputFloat=<inputMessage>
|
||||||
if (request->hasParam(PARAM_FLOAT)) {
|
if (request->hasParam(PARAM_FLOAT)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user