Browse Source

NTP method to get a string from any unix timestamp

rfm69
Xose Pérez 6 years ago
parent
commit
4600fd5fa3
2 changed files with 6 additions and 4 deletions
  1. +0
    -1
      code/espurna/config/general.h
  2. +6
    -3
      code/espurna/ntp.ino

+ 0
- 1
code/espurna/config/general.h View File

@ -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) #define NTP_DST_REGION 0 // 0 for Europe, 1 for USA (defined in NtpClientLib)
#endif #endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ALEXA // ALEXA
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 6
- 3
code/espurna/ntp.ino View File

@ -129,10 +129,8 @@ bool ntpSynced() {
return (year() > 2017); return (year() > 2017);
} }
String ntpDateTime() {
if (!ntpSynced()) return String();
String ntpDateTime(time_t t) {
char buffer[20]; char buffer[20];
time_t t = now();
snprintf_P(buffer, sizeof(buffer), snprintf_P(buffer, sizeof(buffer),
PSTR("%04d-%02d-%02d %02d:%02d:%02d"), PSTR("%04d-%02d-%02d %02d:%02d:%02d"),
year(t), month(t), day(t), hour(t), minute(t), second(t) year(t), month(t), day(t), hour(t), minute(t), second(t)
@ -140,6 +138,11 @@ String ntpDateTime() {
return String(buffer); return String(buffer);
} }
String ntpDateTime() {
if (ntpSynced()) return ntpDateTime(now());
return String();
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void ntpSetup() { void ntpSetup() {


Loading…
Cancel
Save