Skip to content

Commit e7120b4

Browse files
committed
Add sync method
1 parent 01cc777 commit e7120b4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/utility/time/TimeService.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ unsigned long TimeService::getTime()
170170
#endif
171171
}
172172

173+
bool TimeService::sync()
174+
{
175+
_is_rtc_configured = false;
176+
unsigned long utc = getRemoteTime();
177+
178+
if(isTimeValid(utc)) {
179+
DEBUG_DEBUG("TimeServiceClass::%s Drift: %d RTC value: %u", __FUNCTION__, getRTC() - utc, utc);
180+
setRTC(utc);
181+
_last_ntp_sync_tick = millis();
182+
_is_rtc_configured = true;
183+
}
184+
return _is_rtc_configured;
185+
}
186+
173187
void TimeService::setTimeZoneData(long offset, unsigned long dst_until)
174188
{
175189
if(_timezone_offset != offset)

src/utility/time/TimeService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class TimeService
4343

4444
TimeService();
4545

46-
4746
void begin (ConnectionHandler * con_hdl);
4847
unsigned long getTime();
4948
unsigned long getLocalTime();
5049
void setTimeZoneData(long offset, unsigned long valid_until);
50+
bool sync();
5151
/* Helper function to convert an input String into a UNIX timestamp.
5252
* The input String format must be as follow "2021 Nov 01 17:00:00"
5353
*/

0 commit comments

Comments
 (0)