Skip to content

Commit

Permalink
manually parse (local) datestring for rtc.setTime() (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwood77 authored Apr 3, 2024
1 parent 353eec3 commit 644702f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/platformio/osww-server/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 644702f

Please sign in to comment.