DIY QlockTwo
Perfect DIY version of famous QlockTwo Classic with ESP8266
ClockModule Class Reference

ClockModule is handling the RTC and keeps it updated over NTP. More...

#include <ClockModule.h>

Public Member Functions

 ClockModule (RtcDS3231< TwoWire > _rtc, Timezone _localTZ, String _ntpServerName)
 ClockModule is handling the RTC and keeps it updated over NTP. More...
 
 ~ClockModule ()
 
void setup ()
 Setup NTP client and RTC connection. More...
 
bool isDateTimeValid ()
 Either true if rtc time is not valid or the updateInterval is reached. More...
 
void update ()
 Get current time from NTP server and update RTC. More...
 
time_t getUtcTime ()
 Get current time from RTC in UTC. More...
 
SimpleTime getLocalSimpleTime ()
 Get current time from RTC in local time. More...
 

Private Member Functions

time_t getNtpTime ()
 Get NTP time from set NTP server over UDP. More...
 
void sendNTPpacket (IPAddress &address)
 Send an NTP request to the time server at the given address. More...
 

Private Attributes

RtcDS3231< TwoWire > rtc
 
Timezone localTZ
 
WiFiUDP ntpUDP
 
String ntpServerName
 
byte packetBuffer [NTP_PACKET_SIZE]
 
unsigned int localPort = 8888
 

Static Private Attributes

static const int NTP_PACKET_SIZE = 48
 

Detailed Description

ClockModule is handling the RTC and keeps it updated over NTP.

Definition at line 24 of file ClockModule.h.

Constructor & Destructor Documentation

◆ ClockModule()

ClockModule::ClockModule ( RtcDS3231< TwoWire >  _rtc,
Timezone  _localTZ,
String  _ntpServerName 
)

ClockModule is handling the RTC and keeps it updated over NTP.

Parameters
_rtcArduino Wire object
_updateIntervalInterval of updating RTC in Seconds
_ntpServerNameNTP server address.

Definition at line 22 of file ClockModule.cpp.

◆ ~ClockModule()

ClockModule::~ClockModule ( )

Definition at line 27 of file ClockModule.cpp.

Member Function Documentation

◆ getLocalSimpleTime()

SimpleTime ClockModule::getLocalSimpleTime ( )

Get current time from RTC in local time.

With timezone and daylight saving adjustment.

Returns
Current Local Time as SimpleTime.

Definition at line 140 of file ClockModule.cpp.

◆ getNtpTime()

time_t ClockModule::getNtpTime ( )
private

Get NTP time from set NTP server over UDP.

Returns

Definition at line 150 of file ClockModule.cpp.

◆ getUtcTime()

time_t ClockModule::getUtcTime ( )

Get current time from RTC in UTC.

Returns
Current Time as time_t in UTC.

Definition at line 132 of file ClockModule.cpp.

◆ isDateTimeValid()

bool ClockModule::isDateTimeValid ( )

Either true if rtc time is not valid or the updateInterval is reached.

Returns

Definition at line 47 of file ClockModule.cpp.

◆ sendNTPpacket()

void ClockModule::sendNTPpacket ( IPAddress &  address)
private

Send an NTP request to the time server at the given address.

Parameters
addressIP address

Definition at line 185 of file ClockModule.cpp.

◆ setup()

void ClockModule::setup ( )

Setup NTP client and RTC connection.

Definition at line 32 of file ClockModule.cpp.

◆ update()

void ClockModule::update ( )

Get current time from NTP server and update RTC.

Returns
true if updating successful

Definition at line 93 of file ClockModule.cpp.

Member Data Documentation

◆ localPort

unsigned int ClockModule::localPort = 8888
private

Definition at line 32 of file ClockModule.h.

◆ localTZ

Timezone ClockModule::localTZ
private

Definition at line 27 of file ClockModule.h.

◆ NTP_PACKET_SIZE

const int ClockModule::NTP_PACKET_SIZE = 48
staticprivate

Definition at line 30 of file ClockModule.h.

◆ ntpServerName

String ClockModule::ntpServerName
private

Definition at line 29 of file ClockModule.h.

◆ ntpUDP

WiFiUDP ClockModule::ntpUDP
private

Definition at line 28 of file ClockModule.h.

◆ packetBuffer

byte ClockModule::packetBuffer[NTP_PACKET_SIZE]
private

Definition at line 31 of file ClockModule.h.

◆ rtc

RtcDS3231<TwoWire> ClockModule::rtc
private

Definition at line 26 of file ClockModule.h.


The documentation for this class was generated from the following files: