From 644702f7005ba4708d37c9a696eb64c4bb282d3f Mon Sep 17 00:00:00 2001 From: mwood77 <43637076+mwood77@users.noreply.github.com> Date: Wed, 3 Apr 2024 20:37:07 +0200 Subject: [PATCH] manually parse (local) datestring for `rtc.setTime()` (#49) --- src/platformio/osww-server/src/main.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/platformio/osww-server/src/main.cpp b/src/platformio/osww-server/src/main.cpp index 911283a..41c7fbf 100644 --- a/src/platformio/osww-server/src/main.cpp +++ b/src/platformio/osww-server/src/main.cpp @@ -132,11 +132,20 @@ void getTime() { JsonDocument json; deserializeJson(json, http.getStream()); - const unsigned long epoch = json["unixtime"]; - const unsigned long offset = json["raw_offset"]; - - rtc.offset = offset; - rtc.setTime(epoch); + const String datetime = json["datetime"]; + + String date = datetime.substring(0, datetime.indexOf("T") - 1); + int day = date.substring(8, 10).toInt(); + int month = date.substring(5, 7).toInt(); + int year = date.substring(0, 4).toInt(); + + String time = datetime.substring(datetime.indexOf("T") + 1); + int seconds = time.substring(6, 8).toInt(); + int hours = time.substring(0, 2).toInt(); + int minutes = time.substring(3, 5).toInt(); + + rtc.setTime(seconds, minutes, hours, day, month, year); + Serial.println("[STATUS] - Time: " + datetime); } http.end();