added option to configure parameters
This commit is contained in:
parent
105f127913
commit
addaf856e5
|
@ -48,6 +48,11 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset, int u
|
||||||
this->_updateInterval = updateInterval;
|
this->_updateInterval = updateInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NTPClient::configure(const char* poolServerName, int timeOffset) {
|
||||||
|
this->_timeOffset = timeOffset;
|
||||||
|
this->_poolServerName = poolServerName;
|
||||||
|
}
|
||||||
|
|
||||||
void NTPClient::begin() {
|
void NTPClient::begin() {
|
||||||
this->begin(NTP_DEFAULT_LOCAL_PORT);
|
this->begin(NTP_DEFAULT_LOCAL_PORT);
|
||||||
}
|
}
|
||||||
|
@ -120,33 +125,6 @@ int NTPClient::getSeconds() {
|
||||||
return (this->getEpochTime() % 60);
|
return (this->getEpochTime() % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
int NTPClient::getYear() {
|
|
||||||
time_t rawtime = this->getEpochTime();
|
|
||||||
struct tm * ti;
|
|
||||||
ti = localtime (&rawtime);
|
|
||||||
int year = ti->tm_year + 1900;
|
|
||||||
|
|
||||||
return year;
|
|
||||||
}
|
|
||||||
|
|
||||||
int NTPClient::getMonth() {
|
|
||||||
time_t rawtime = this->getEpochTime();
|
|
||||||
struct tm * ti;
|
|
||||||
ti = localtime (&rawtime);
|
|
||||||
int month = (ti->tm_mon + 1) < 10 ? 0 + (ti->tm_mon + 1) : (ti->tm_mon + 1);
|
|
||||||
|
|
||||||
return month;
|
|
||||||
}
|
|
||||||
|
|
||||||
int NTPClient::getDate() {
|
|
||||||
time_t rawtime = this->getEpochTime();
|
|
||||||
struct tm * ti;
|
|
||||||
ti = localtime (&rawtime);
|
|
||||||
int day = (ti->tm_mday) < 10 ? 0 + (ti->tm_mday) : (ti->tm_mday);
|
|
||||||
|
|
||||||
return day;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
String NTPClient::getFormattedTime() {
|
String NTPClient::getFormattedTime() {
|
||||||
unsigned long rawTime = this->getEpochTime();
|
unsigned long rawTime = this->getEpochTime();
|
||||||
|
@ -208,6 +186,33 @@ String NTPClient::getFullFormattedTime() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int NTPClient::getYear() {
|
||||||
|
time_t rawtime = this->getEpochTime();
|
||||||
|
struct tm * ti;
|
||||||
|
ti = localtime (&rawtime);
|
||||||
|
int year = ti->tm_year + 1900;
|
||||||
|
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NTPClient::getMonth() {
|
||||||
|
time_t rawtime = this->getEpochTime();
|
||||||
|
struct tm * ti;
|
||||||
|
ti = localtime (&rawtime);
|
||||||
|
int month = (ti->tm_mon + 1) < 10 ? 0 + (ti->tm_mon + 1) : (ti->tm_mon + 1);
|
||||||
|
|
||||||
|
return month;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NTPClient::getDate() {
|
||||||
|
time_t rawtime = this->getEpochTime();
|
||||||
|
struct tm * ti;
|
||||||
|
ti = localtime (&rawtime);
|
||||||
|
int day = (ti->tm_mday) < 10 ? 0 + (ti->tm_mday) : (ti->tm_mday);
|
||||||
|
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
void NTPClient::end() {
|
void NTPClient::end() {
|
||||||
this->_udp->stop();
|
this->_udp->stop();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,10 @@ class NTPClient {
|
||||||
NTPClient(UDP& udp, const char* poolServerName);
|
NTPClient(UDP& udp, const char* poolServerName);
|
||||||
NTPClient(UDP& udp, const char* poolServerName, int timeOffset);
|
NTPClient(UDP& udp, const char* poolServerName, int timeOffset);
|
||||||
NTPClient(UDP& udp, const char* poolServerName, int timeOffset, int updateInterval);
|
NTPClient(UDP& udp, const char* poolServerName, int timeOffset, int updateInterval);
|
||||||
|
/**
|
||||||
|
* Allow adding parameters outside of constructor
|
||||||
|
*/
|
||||||
|
void configure(const char* poolServerName, int timeOffset);
|
||||||
/**
|
/**
|
||||||
* Starts the underlying UDP client with the default local port
|
* Starts the underlying UDP client with the default local port
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue