diff --git a/NTPClient.cpp b/NTPClient.cpp index a84bc36..075ac08 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -42,16 +42,6 @@ NTPClient::NTPClient(const char* poolServerName, int timeOffset, int updateInter this->_updateInterval = updateInterval; } -void NTPClient::begin() { - #ifdef DEBUG_NTPClient - Serial.println("Begin NTPClient"); - Serial.print("Start udp connection on port: "); - Serial.println(this->_port); - #endif - this->_udp.begin(this->_port); - this->forceUpdate(); -} - void NTPClient::forceUpdate() { #ifdef DEBUG_NTPClient Serial.println("Update from NTP Server"); @@ -86,8 +76,9 @@ void NTPClient::forceUpdate() { } void NTPClient::update() { - unsigned long runtime = millis(); - if (runtime - this->_lastUpdate >= this->_updateInterval && this->_updateInterval != 0) { + if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval + || this->_lastUpdate == 0) { // Update if there was no update yet. + if (this->_lastUpdate == 0) this->_udp.begin(this->_port); // Start _udp if there was no update yet. this->forceUpdate(); } } diff --git a/NTPClient.h b/NTPClient.h index 82bbfb1..65c8265 100644 --- a/NTPClient.h +++ b/NTPClient.h @@ -32,13 +32,6 @@ class NTPClient { NTPClient(const char* poolServerName, int timeOffset); NTPClient(const char* poolServerName, int timeOffset, int updateInterval); - /** - * Starts the NTPClient - * This will create the UDP Socket and get the first update from the NTP server. This must be called after - * a WiFi connection is established. - */ - void begin(); - /** * This should be called in the main loop of your application. By default an update from the NTP Server is only * made every 60 seconds. This can be configured in the NTPClient constructor. diff --git a/examples/Advanced/Advanced.ino b/examples/Advanced/Advanced.ino index 92e8284..f359b34 100644 --- a/examples/Advanced/Advanced.ino +++ b/examples/Advanced/Advanced.ino @@ -17,10 +17,6 @@ void setup(){ delay ( 500 ); Serial.print ( "." ); } - - // Start the NTPClient after an WiFi connection is established - timeClient.begin(); - } void loop() { diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino index e4280ff..c22f8b0 100644 --- a/examples/Basic/Basic.ino +++ b/examples/Basic/Basic.ino @@ -17,10 +17,6 @@ void setup(){ delay ( 500 ); Serial.print ( "." ); } - - // Start the NTPClient after an WiFi connection is established - timeClient.begin(); - } void loop() {