Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit bf50ed8

Browse files
authored
v3.7.5 fix bug causing wrong time
### Releases v3.7.5 1. Fix bug causing time jumping back or forth when network has problem. Check [Time jumping back when connection is lost and forward when up #9](#9) and [Time jumping back 9 minutes #1](#1) 2. Modify example [ESP_NTPClient_Advanced](https://github.com/khoih-prog/NTPClient_Generic/tree/main/examples/ESP/ESP_NTPClient_Advanced) to demo the better way to use the library, without using long `delay()` 3. Add support to `RP2040W` boards using CYW43439 WiF 4. Optimize and clean up 5. Modify `platformio.ini` and `library.json` to reduce error with PIO 6. Update `Packages' Patches`
1 parent 57df8a4 commit bf50ed8

File tree

12 files changed

+592
-232
lines changed

12 files changed

+592
-232
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.2, ESP8266 core v3.0.2, ArduinoCore-mbed v3.0.1, etc.)
18+
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.5, ESP8266 core v3.0.2, ArduinoCore-mbed v3.4.1, etc.)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -27,13 +27,13 @@ Please ensure to specify the following:
2727

2828
```
2929
Arduino IDE version: 1.8.19
30-
RASPBERRY_PI_PICO board
31-
ArduinoCore-mbed v3.0.1
30+
RASPBERRY_PI_PICO_W board
31+
arduinoCore-pico v2.6.1
3232
OS: Ubuntu 20.04 LTS
33-
Linux xy-Inspiron-3593 5.13.0-40-generic #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
33+
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3434
3535
Context:
36-
I encountered an endless loop while trying to connect to Local WiFi.
36+
I encountered a crash when using this library
3737
3838
Steps to reproduce:
3939
1. ...

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v3.7.5](#releases-v375)
1516
* [Releases v3.7.4](#releases-v374)
1617
* [Releases v3.7.3](#releases-v373)
1718
* [Releases v3.7.2](#releases-v372)
@@ -32,6 +33,15 @@
3233

3334
## Changelog
3435

36+
### Releases v3.7.5
37+
38+
1. Fix bug causing time jumping back or forth when network has problem. Check [Time jumping back when connection is lost and forward when up #9](https://github.com/khoih-prog/NTPClient_Generic/issues/9) and [Time jumping back 9 minutes #1](https://github.com/khoih-prog/NTPClient_Generic/issues/1)
39+
2. Modify example [ESP_NTPClient_Advanced](https://github.com/khoih-prog/NTPClient_Generic/tree/main/examples/ESP/ESP_NTPClient_Advanced) to demo the better way to use the library, without using long `delay()`
40+
3. Add support to `RP2040W` boards using CYW43439 WiF
41+
4. Optimize and clean up
42+
5. Modify `platformio.ini` and `library.json` to reduce error with PIO
43+
6. Update `Packages' Patches`
44+
3545
### Releases v3.7.4
3646

3747
1. Sync with [NTPClient releases v3.2.1](https://github.com/arduino-libraries/NTPClient/releases/tag/3.2.1)

examples/ESP/ESP_NTPClient_Advanced/ESP_NTPClient_Advanced.ino

Lines changed: 86 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/****************************************************************************************************************************
22
ESP_NTPClient_Advanced.ino
33
4-
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN boards using
5-
a) Ethernet W5x00, ENC28J60, LAN8742A
6-
b) WiFiNINA
7-
c) ESP8266/ESP32 WiFi
8-
d) ESP8266/ESP32-AT-command WiFi
9-
e) WT32_ETH01 (ESP32 + LAN8720)
10-
f) RTL8720DN
4+
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN, RP2040 boards using
5+
1) Ethernet W5x00, ENC28J60, LAN8742A
6+
2) WiFiNINA
7+
3) ESP8266/ESP32 WiFi
8+
4) ESP8266/ESP32-AT-command WiFi
9+
5) WT32_ETH01 (ESP32 + LAN8720)
10+
6) RTL8720DN
11+
7) Portenta_H7
12+
8) RP2040W WiFi
1113
1214
Based on and modified from Arduino NTPClient Library (https://github.com/arduino-libraries/NTPClient)
1315
to support other boards such as ESP8266/ESP32, SAMD21, SAMD51, Adafruit's nRF52 boards, SAM DUE, RTL8720DN, etc.
@@ -63,6 +65,8 @@ char timeServer[] = "0.ca.pool.ntp.org";
6365
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
6466
NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);
6567

68+
int WiFiStatus = WL_IDLE_STATUS;
69+
6670
void setup()
6771
{
6872
Serial.begin(115200);
@@ -81,6 +85,8 @@ void setup()
8185
Serial.print ( "." );
8286
}
8387

88+
WiFiStatus = WL_CONNECTED;
89+
8490
Serial.print(F("\nESP_NTPClient_Advanced started @ IP address: "));
8591
Serial.println(WiFi.localIP());
8692

@@ -89,40 +95,79 @@ void setup()
8995
Serial.println("Using NTP Server " + timeClient.getPoolServerName());
9096
}
9197

98+
void updateStatus()
99+
{
100+
static unsigned long wifiStatus_timeout = 0;
101+
static unsigned long updateStatus_timeout = 0;
102+
103+
#define WIFI_CHECK_INTERVAL 1000L
104+
#define UPDATE_INTERVAL 10000L
105+
106+
if ((millis() > wifiStatus_timeout) || (wifiStatus_timeout == 0))
107+
{
108+
if (WiFi.status() != WiFiStatus)
109+
{
110+
WiFiStatus = WiFi.status();
111+
112+
if (WiFiStatus == WL_CONNECTED)
113+
Serial.println("Changed, WiFiStatus = Connected");
114+
else if (WiFiStatus == WL_DISCONNECTED)
115+
Serial.println("Changed, WiFiStatus = Disconnected");
116+
else if (WiFiStatus == WL_IDLE_STATUS)
117+
Serial.println("Changed, WiFiStatus = Idle");
118+
else if (WiFiStatus == WL_NO_SSID_AVAIL)
119+
Serial.println("Changed, WiFiStatus = lost WiFi SSID");
120+
else if (WiFiStatus == WL_CONNECTION_LOST)
121+
Serial.println("Changed, WiFiStatus = lost WiFi connection");
122+
else
123+
{
124+
Serial.print("Changed, WiFiStatus = "); Serial.println(WiFiStatus);
125+
}
126+
}
127+
128+
wifiStatus_timeout = millis() + WIFI_CHECK_INTERVAL;
129+
}
130+
131+
// Send update request every UPDATE_INTERVAL (10) seconds: we don't need to send update request frequently
132+
if ((millis() > updateStatus_timeout) || (updateStatus_timeout == 0))
133+
{
134+
timeClient.update();
135+
136+
if (timeClient.updated())
137+
Serial.println("********UPDATED********");
138+
else
139+
Serial.println("******NOT UPDATED******");
140+
141+
Serial.println("UTC : " + timeClient.getFormattedUTCTime());
142+
Serial.println("UTC : " + timeClient.getFormattedUTCDateTime());
143+
Serial.println("LOC : " + timeClient.getFormattedTime());
144+
Serial.println("LOC : " + timeClient.getFormattedDateTime());
145+
Serial.println("UTC EPOCH : " + String(timeClient.getUTCEpochTime()));
146+
Serial.println("LOC EPOCH : " + String(timeClient.getEpochTime()));
147+
148+
// Function test
149+
// Without leading 0
150+
Serial.println(String("UTC : ") + timeClient.getUTCHours() + ":" + timeClient.getUTCMinutes() + ":" + timeClient.getUTCSeconds() + " " +
151+
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
152+
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
153+
// With leading 0
154+
Serial.println(String("UTC : ") + timeClient.getUTCStrHours() + ":" + timeClient.getUTCStrMinutes() + ":" + timeClient.getUTCStrSeconds() + " " +
155+
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
156+
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
157+
// Without leading 0
158+
Serial.println(String("LOC : ") + timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds() + " " +
159+
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
160+
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());
161+
// With leading 0
162+
Serial.println(String("LOC : ") + timeClient.getStrHours() + ":" + timeClient.getStrMinutes() + ":" + timeClient.getStrSeconds() + " " +
163+
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
164+
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());
165+
166+
updateStatus_timeout = millis() + UPDATE_INTERVAL;
167+
}
168+
}
169+
92170
void loop()
93171
{
94-
timeClient.update();
95-
96-
97-
if (timeClient.updated())
98-
Serial.println("********UPDATED********");
99-
else
100-
Serial.println("******NOT UPDATED******");
101-
102-
Serial.println("UTC : " + timeClient.getFormattedUTCTime());
103-
Serial.println("UTC : " + timeClient.getFormattedUTCDateTime());
104-
Serial.println("LOC : " + timeClient.getFormattedTime());
105-
Serial.println("LOC : " + timeClient.getFormattedDateTime());
106-
Serial.println("UTC EPOCH : " + String(timeClient.getUTCEpochTime()));
107-
Serial.println("LOC EPOCH : " + String(timeClient.getEpochTime()));
108-
109-
// Function test
110-
// Without leading 0
111-
Serial.println(String("UTC : ") + timeClient.getUTCHours() + ":" + timeClient.getUTCMinutes() + ":" + timeClient.getUTCSeconds() + " " +
112-
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
113-
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
114-
// With leading 0
115-
Serial.println(String("UTC : ") + timeClient.getUTCStrHours() + ":" + timeClient.getUTCStrMinutes() + ":" + timeClient.getUTCStrSeconds() + " " +
116-
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
117-
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
118-
// Without leading 0
119-
Serial.println(String("LOC : ") + timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds() + " " +
120-
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
121-
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());
122-
// With leading 0
123-
Serial.println(String("LOC : ") + timeClient.getStrHours() + ":" + timeClient.getStrMinutes() + ":" + timeClient.getStrSeconds() + " " +
124-
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
125-
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());
126-
127-
delay(10000);
172+
updateStatus();
128173
}

examples/ESP/ESP_NTPClient_Basic/ESP_NTPClient_Basic.ino

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/****************************************************************************************************************************
22
ESP_NTPClient_Bas.ino
33
4-
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN boards using
5-
a) Ethernet W5x00, ENC28J60, LAN8742A
6-
b) WiFiNINA
7-
c) ESP8266/ESP32 WiFi
8-
d) ESP8266/ESP32-AT-command WiFi
9-
e) WT32_ETH01 (ESP32 + LAN8720)
10-
f) RTL8720DN
4+
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN, RP2040 boards using
5+
1) Ethernet W5x00, ENC28J60, LAN8742A
6+
2) WiFiNINA
7+
3) ESP8266/ESP32 WiFi
8+
4) ESP8266/ESP32-AT-command WiFi
9+
5) WT32_ETH01 (ESP32 + LAN8720)
10+
6) RTL8720DN
11+
7) Portenta_H7
12+
8) RP2040W WiFi
1113
1214
Based on and modified from Arduino NTPClient Library (https://github.com/arduino-libraries/NTPClient)
1315
to support other boards such as ESP8266/ESP32, SAMD21, SAMD51, Adafruit's nRF52 boards, SAM DUE, RTL8720DN, etc.

examples/ESP/ESP_WiFi_ETH_NTPClient_Advanced/ESP_WiFi_ETH_NTPClient_Advanced.ino

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/****************************************************************************************************************************
22
ESP_WiFi_ETH_NTPClient_Advanced.ino
33
4-
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, boards using
5-
a) Ethernet W5x00, ENC28J60, LAN8742A
6-
b) WiFiNINA
7-
c) ESP8266/ESP32 WiFi
8-
d) ESP8266/ESP32-AT-command WiFi
9-
e) WT32_ETH01 (ESP32 + LAN8720)
10-
f) RTL8720DN
4+
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN, RP2040 boards using
5+
1) Ethernet W5x00, ENC28J60, LAN8742A
6+
2) WiFiNINA
7+
3) ESP8266/ESP32 WiFi
8+
4) ESP8266/ESP32-AT-command WiFi
9+
5) WT32_ETH01 (ESP32 + LAN8720)
10+
6) RTL8720DN
11+
7) Portenta_H7
12+
8) RP2040W WiFi
1113
1214
Based on and modified from Arduino NTPClient Library (https://github.com/arduino-libraries/NTPClient)
1315
to support other boards such as ESP8266/ESP32, SAMD21, SAMD51, Adafruit's nRF52 boards, SAM DUE, RTL8720DN, etc.

library.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "NTPClient_Generic",
3-
"version": "3.7.4",
3+
"version": "3.7.5",
44
"keywords": "timing, device, control, communication, iot, ntp, rtc, wifi, wifinina, ethernet, time, rp2040, nano-rp2040-connect, SAM DUE, SAMD, nRF52, STM32, ESP32, ESP8266, wt32-eth01, rtl8720, rpi-pico",
55
"description": "Library for NTPClient to connect to an NTP time-server. Get time from a NTP time-server and keep it in sync. For ESP8266/ESP32, WT32-ETH01 (ESP32 + LAN8720), nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, RTL8720DN, RP2040-based (Nano_RP2040_Connect, RASPBERRY_PI_PICO) boards, etc. besides AVR, using ESP WiFi, WiFiNINA, Ethernet W5x00, ENC28J60, LAN8742A, ESP8266/ESP32 AT-command WiFi",
66
"authors":
@@ -39,7 +39,7 @@
3939
{
4040
"owner": "khoih-prog",
4141
"name": "Timezone_Generic",
42-
"version": ">=1.10.0",
42+
"version": ">=1.10.1",
4343
"platforms": ["*"]
4444
},
4545
{
@@ -52,61 +52,61 @@
5252
"owner": "khoih-prog",
5353
"name": "FlashStorage_SAMD",
5454
"version": ">=1.3.2",
55-
"platforms": ["*"]
55+
"platforms": ["atmelsam"]
5656
},
5757
{
5858
"owner": "khoih-prog",
5959
"name": "FlashStorage_STM32",
6060
"version": ">=1.2.0",
61-
"platforms": ["*"]
61+
"platforms": ["ststm32"]
6262
},
6363
{
6464
"owner": "khoih-prog",
6565
"name": "FlashStorage_STM32F1",
6666
"version": ">=1.1.0",
67-
"platforms": ["*"]
67+
"platforms": ["ststm32"]
6868
},
6969
{
7070
"owner": "khoih-prog",
7171
"name": "FlashStorage_RTL8720",
7272
"version": ">=1.1.0",
73-
"platforms": ["*"]
73+
"platforms": ["AmebaD"]
7474
},
7575
{
7676
"owner": "khoih-prog",
7777
"name": "WiFiNINA_Generic",
78-
"version": ">=1.8.14-3",
78+
"version": ">=1.8.14-6",
7979
"platforms": ["*"]
8080
},
8181
{
8282
"owner": "khoih-prog",
8383
"name": "EthernetWebServer",
84-
"version": ">=2.1.3",
84+
"version": ">=2.2.3",
8585
"platforms": ["*"]
8686
},
8787
{
8888
"owner": "khoih-prog",
8989
"name": "EthernetWebServer_STM32",
90-
"version": ">=1.4.1",
91-
"platforms": ["*"]
90+
"version": ">=1.5.0",
91+
"platforms": ["ststm32"]
9292
},
9393
{
9494
"owner": "khoih-prog",
9595
"name": "WiFiWebServer",
96-
"version": ">=1.8.0",
96+
"version": ">=1.9.5",
9797
"platforms": ["*"]
9898
},
9999
{
100100
"owner": "khoih-prog",
101101
"name": "WebServer_WT32_ETH01",
102-
"version": ">=1.4.1",
103-
"platforms": ["*"]
102+
"version": ">=1.5.1",
103+
"platforms": ["espressif32"]
104104
},
105105
{
106106
"owner": "khoih-prog",
107107
"name": "WiFiWebServer_RTL8720",
108-
"version": ">=1.1.1",
109-
"platforms": ["*"]
108+
"version": ">=1.1.2",
109+
"platforms": ["AmebaD"]
110110
},
111111
{
112112
"owner": "khoih-prog",
@@ -123,42 +123,43 @@
123123
{
124124
"owner": "stm32duino",
125125
"name": "STM32Ethernet",
126-
"version": ">=1.2.0",
126+
"version": ">=1.3.0",
127127
"platforms": ["ststm32"]
128128
},
129129
{
130130
"owner": "stm32duino",
131131
"name": "STM32duino RTC",
132-
"version": ">=1.2.0",
132+
"version": ">=1.3.2",
133133
"platforms": ["ststm32"]
134134
},
135135
{
136136
"owner": "uipethernet",
137137
"name": "UIPEthernet",
138-
"version": ">=2.0.11",
138+
"version": ">=2.0.12",
139139
"platforms": ["*"]
140140
},
141141
{
142142
"owner": "jandrassy",
143143
"name": "EthernetENC",
144-
"version": ">=2.0.2",
144+
"version": ">=2.0.3",
145145
"platforms": ["*"]
146146
},
147147
{
148148
"owner": "jandrassy",
149149
"name": "WiFiEspAT",
150-
"version": ">=1.3.2",
150+
"version": ">=1.4.1",
151151
"platforms": ["*"]
152152
},
153153
{
154154
"owner": "khoih-prog",
155155
"name": "Ethernet_Generic",
156-
"version": "^2.1.0"
156+
"version": "^2.6.1",
157+
"platforms": ["*"]
157158
},
158159
{
159160
"owner": "ssilverman",
160161
"name": "QNEthernet",
161-
"version": ">=0.14.0",
162+
"version": ">=0.15.0",
162163
"platforms": ["teensy"]
163164
}
164165
],

0 commit comments

Comments
 (0)