Skip to content

Commit

Permalink
NTP method to get a string from any unix timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Apr 11, 2018
1 parent 94e47b4 commit 4600fd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,6 @@ PROGMEM const char* const custom_reset_string[] = {
#define NTP_DST_REGION 0 // 0 for Europe, 1 for USA (defined in NtpClientLib)
#endif


// -----------------------------------------------------------------------------
// ALEXA
// -----------------------------------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions code/espurna/ntp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,20 @@ bool ntpSynced() {
return (year() > 2017);
}

String ntpDateTime() {
if (!ntpSynced()) return String();
String ntpDateTime(time_t t) {
char buffer[20];
time_t t = now();
snprintf_P(buffer, sizeof(buffer),
PSTR("%04d-%02d-%02d %02d:%02d:%02d"),
year(t), month(t), day(t), hour(t), minute(t), second(t)
);
return String(buffer);
}

String ntpDateTime() {
if (ntpSynced()) return ntpDateTime(now());
return String();
}

// -----------------------------------------------------------------------------

void ntpSetup() {
Expand Down

0 comments on commit 4600fd5

Please sign in to comment.