kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
format check in ntp client
rodzic
9d6ce8dfac
commit
74e01a76a7
|
@ -44,7 +44,7 @@ jobs:
|
|||
- 'lib/BoardFinder'
|
||||
- 'lib/ConfigurationManagement'
|
||||
#- 'lib/Display'
|
||||
#- 'lib/NTPClient'
|
||||
- 'lib/NTPClient'
|
||||
- 'lib/PowerManagement'
|
||||
- 'lib/System'
|
||||
#- 'lib/TimeLib'
|
||||
|
|
|
@ -28,7 +28,7 @@ NTPClient::NTPClient(long timeOffset) {
|
|||
this->_timeOffset = timeOffset;
|
||||
}
|
||||
|
||||
NTPClient::NTPClient(const char* poolServerName) {
|
||||
NTPClient::NTPClient(const char *poolServerName) {
|
||||
this->_poolServerName = poolServerName;
|
||||
}
|
||||
|
||||
|
@ -37,18 +37,18 @@ NTPClient::NTPClient(IPAddress poolServerIP) {
|
|||
this->_poolServerName = NULL;
|
||||
}
|
||||
|
||||
NTPClient::NTPClient(const char* poolServerName, long timeOffset) {
|
||||
NTPClient::NTPClient(const char *poolServerName, long timeOffset) {
|
||||
this->_timeOffset = timeOffset;
|
||||
this->_poolServerName = poolServerName;
|
||||
}
|
||||
|
||||
NTPClient::NTPClient(IPAddress poolServerIP, long timeOffset){
|
||||
NTPClient::NTPClient(IPAddress poolServerIP, long timeOffset) {
|
||||
this->_timeOffset = timeOffset;
|
||||
this->_poolServerIP = poolServerIP;
|
||||
this->_poolServerName = NULL;
|
||||
}
|
||||
|
||||
NTPClient::NTPClient(const char* poolServerName, long timeOffset, unsigned long updateInterval) {
|
||||
NTPClient::NTPClient(const char *poolServerName, long timeOffset, unsigned long updateInterval) {
|
||||
this->_timeOffset = timeOffset;
|
||||
this->_poolServerName = poolServerName;
|
||||
this->_updateInterval = updateInterval;
|
||||
|
@ -74,12 +74,12 @@ void NTPClient::begin(unsigned int port) {
|
|||
}
|
||||
|
||||
bool NTPClient::forceUpdate() {
|
||||
#ifdef DEBUG_NTPClient
|
||||
#ifdef DEBUG_NTPClient
|
||||
Serial.println("Update from NTP Server");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// flush any existing packets
|
||||
while(this->_udp.parsePacket() != 0)
|
||||
while (this->_udp.parsePacket() != 0)
|
||||
this->_udp.flush();
|
||||
|
||||
this->sendNTPPacket();
|
||||
|
@ -88,9 +88,10 @@ bool NTPClient::forceUpdate() {
|
|||
byte timeout = 0;
|
||||
int cb = 0;
|
||||
do {
|
||||
delay ( 10 );
|
||||
delay(10);
|
||||
cb = this->_udp.parsePacket();
|
||||
if (timeout > 100) return false; // timeout after 1000 ms
|
||||
if (timeout > 100)
|
||||
return false; // timeout after 1000 ms
|
||||
timeout++;
|
||||
} while (cb == 0);
|
||||
|
||||
|
@ -112,7 +113,8 @@ bool NTPClient::forceUpdate() {
|
|||
bool NTPClient::update() {
|
||||
if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval
|
||||
|| this->_lastUpdate == 0) { // Update if there was no update yet.
|
||||
if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT) this->begin(this->_port); // setup the UDP client if needed
|
||||
if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT)
|
||||
this->begin(this->_port); // setup the UDP client if needed
|
||||
return this->forceUpdate();
|
||||
}
|
||||
return false; // return false if update does not occur
|
||||
|
@ -125,7 +127,7 @@ unsigned long NTPClient::getEpochTime() const {
|
|||
}
|
||||
|
||||
int NTPClient::getDay() const {
|
||||
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
|
||||
return (((this->getEpochTime() / 86400L) + 4) % 7); // 0 is Sunday
|
||||
}
|
||||
int NTPClient::getHours() const {
|
||||
return ((this->getEpochTime() % 86400L) / 3600);
|
||||
|
@ -165,7 +167,7 @@ void NTPClient::setUpdateInterval(unsigned long updateInterval) {
|
|||
this->_updateInterval = updateInterval;
|
||||
}
|
||||
|
||||
void NTPClient::setPoolServerName(const char* poolServerName) {
|
||||
void NTPClient::setPoolServerName(const char *poolServerName) {
|
||||
this->_poolServerName = poolServerName;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
#define NTP_DEFAULT_LOCAL_PORT 1337
|
||||
|
||||
class NTPClient {
|
||||
private:
|
||||
private:
|
||||
WiFiUDP _udp;
|
||||
bool _udpSetup = false;
|
||||
|
||||
const char* _poolServerName = "pool.ntp.org"; // Default time server
|
||||
const char *_poolServerName = "pool.ntp.org"; // Default time server
|
||||
IPAddress _poolServerIP;
|
||||
unsigned int _port = NTP_DEFAULT_LOCAL_PORT;
|
||||
long _timeOffset = 0;
|
||||
|
@ -26,12 +26,12 @@ class NTPClient {
|
|||
|
||||
void sendNTPPacket();
|
||||
|
||||
public:
|
||||
public:
|
||||
NTPClient();
|
||||
explicit NTPClient(long timeOffset);
|
||||
explicit NTPClient(const char* poolServerName);
|
||||
NTPClient(const char* poolServerName, long timeOffset);
|
||||
NTPClient(const char* poolServerName, long timeOffset, unsigned long updateInterval);
|
||||
explicit NTPClient(const char *poolServerName);
|
||||
NTPClient(const char *poolServerName, long timeOffset);
|
||||
NTPClient(const char *poolServerName, long timeOffset, unsigned long updateInterval);
|
||||
explicit NTPClient(IPAddress poolServerIP);
|
||||
NTPClient(IPAddress poolServerIP, long timeOffset);
|
||||
NTPClient(IPAddress poolServerIP, long timeOffset, unsigned long updateInterval);
|
||||
|
@ -41,7 +41,7 @@ class NTPClient {
|
|||
*
|
||||
* @param poolServerName
|
||||
*/
|
||||
void setPoolServerName(const char* poolServerName);
|
||||
void setPoolServerName(const char *poolServerName);
|
||||
|
||||
/**
|
||||
* Set random local port
|
||||
|
|
Ładowanie…
Reference in New Issue