From 4600fd5fa32d9de183804c976a3033ad6b99e77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 11 Apr 2018 14:39:28 +0200 Subject: [PATCH] NTP method to get a string from any unix timestamp --- code/espurna/config/general.h | 1 - code/espurna/ntp.ino | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index de66526c..103c3863 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -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 // ----------------------------------------------------------------------------- diff --git a/code/espurna/ntp.ino b/code/espurna/ntp.ino index a21e312b..5118c7fe 100644 --- a/code/espurna/ntp.ino +++ b/code/espurna/ntp.ino @@ -129,10 +129,8 @@ 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) @@ -140,6 +138,11 @@ String ntpDateTime() { return String(buffer); } +String ntpDateTime() { + if (ntpSynced()) return ntpDateTime(now()); + return String(); +} + // ----------------------------------------------------------------------------- void ntpSetup() {