Skip to content

Commit 7f05bf9

Browse files
committed
Remove .begin() from API
1 parent eae9724 commit 7f05bf9

File tree

4 files changed

+3
-27
lines changed

4 files changed

+3
-27
lines changed

NTPClient.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ NTPClient::NTPClient(const char* poolServerName, int timeOffset, int updateInter
4242
this->_updateInterval = updateInterval;
4343
}
4444

45-
void NTPClient::begin() {
46-
#ifdef DEBUG_NTPClient
47-
Serial.println("Begin NTPClient");
48-
Serial.print("Start udp connection on port: ");
49-
Serial.println(this->_port);
50-
#endif
51-
this->_udp.begin(this->_port);
52-
this->forceUpdate();
53-
}
54-
5545
void NTPClient::forceUpdate() {
5646
#ifdef DEBUG_NTPClient
5747
Serial.println("Update from NTP Server");
@@ -86,8 +76,9 @@ void NTPClient::forceUpdate() {
8676
}
8777

8878
void NTPClient::update() {
89-
unsigned long runtime = millis();
90-
if (runtime - this->_lastUpdate >= this->_updateInterval && this->_updateInterval != 0) {
79+
if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval
80+
|| this->_lastUpdate == 0) { // Update if there was no update yet.
81+
if (this->_lastUpdate == 0) this->_udp.begin(this->_port); // Start _udp if there was no update yet.
9182
this->forceUpdate();
9283
}
9384
}

NTPClient.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ class NTPClient {
3232
NTPClient(const char* poolServerName, int timeOffset);
3333
NTPClient(const char* poolServerName, int timeOffset, int updateInterval);
3434

35-
/**
36-
* Starts the NTPClient
37-
* This will create the UDP Socket and get the first update from the NTP server. This must be called after
38-
* a WiFi connection is established.
39-
*/
40-
void begin();
41-
4235
/**
4336
* This should be called in the main loop of your application. By default an update from the NTP Server is only
4437
* made every 60 seconds. This can be configured in the NTPClient constructor.

examples/Advanced/Advanced.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ void setup(){
1717
delay ( 500 );
1818
Serial.print ( "." );
1919
}
20-
21-
// Start the NTPClient after an WiFi connection is established
22-
timeClient.begin();
23-
2420
}
2521

2622
void loop() {

examples/Basic/Basic.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ void setup(){
1717
delay ( 500 );
1818
Serial.print ( "." );
1919
}
20-
21-
// Start the NTPClient after an WiFi connection is established
22-
timeClient.begin();
23-
2420
}
2521

2622
void loop() {

0 commit comments

Comments
 (0)