Skip to content

Commit fdd32f5

Browse files
committed
ESP32: use core internal functions to configure and get time
1 parent 9da8516 commit fdd32f5

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/utility/time/TimeService.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ static time_t const EPOCH = 0;
5252

5353
TimeService::TimeService()
5454
: _con_hdl(nullptr)
55-
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
5655
, _is_rtc_configured(false)
57-
#endif
5856
, _is_tz_configured(false)
5957
, _timezone_offset(0)
6058
, _timezone_dst_until(0)
@@ -100,6 +98,13 @@ unsigned long TimeService::getTime()
10098
return utc;
10199
}
102100
return time(NULL);
101+
#elif ARDUINO_ARCH_ESP32 || ARDUINO_ARCH_ESP8266
102+
if(!_is_rtc_configured)
103+
{
104+
configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov");
105+
_is_rtc_configured = true;
106+
}
107+
return time(NULL);
103108
#else
104109
return getRemoteTime();
105110
#endif

src/utility/time/TimeService.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ class TimeService
5656
private:
5757

5858
ConnectionHandler * _con_hdl;
59-
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
6059
bool _is_rtc_configured;
61-
#endif
6260
bool _is_tz_configured;
6361
long _timezone_offset;
6462
unsigned long _timezone_dst_until;

0 commit comments

Comments
 (0)