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

Commit

Permalink
v3.7.5 fix bug causing wrong time
Browse files Browse the repository at this point in the history
### 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`
  • Loading branch information
khoih-prog committed Oct 23, 2022
1 parent 57df8a4 commit bf50ed8
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 232 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* 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.)
* 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.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
Expand All @@ -27,13 +27,13 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
RASPBERRY_PI_PICO board
ArduinoCore-mbed v3.0.1
RASPBERRY_PI_PICO_W board
arduinoCore-pico v2.6.1
OS: Ubuntu 20.04 LTS
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
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
Context:
I encountered an endless loop while trying to connect to Local WiFi.
I encountered a crash when using this library
Steps to reproduce:
1. ...
Expand Down
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

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

## Changelog

### 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](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)
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`

### Releases v3.7.4

1. Sync with [NTPClient releases v3.2.1](https://github.com/arduino-libraries/NTPClient/releases/tag/3.2.1)
Expand Down
127 changes: 86 additions & 41 deletions examples/ESP/ESP_NTPClient_Advanced/ESP_NTPClient_Advanced.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/****************************************************************************************************************************
ESP_NTPClient_Advanced.ino
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN boards using
a) Ethernet W5x00, ENC28J60, LAN8742A
b) WiFiNINA
c) ESP8266/ESP32 WiFi
d) ESP8266/ESP32-AT-command WiFi
e) WT32_ETH01 (ESP32 + LAN8720)
f) RTL8720DN
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN, RP2040 boards using
1) Ethernet W5x00, ENC28J60, LAN8742A
2) WiFiNINA
3) ESP8266/ESP32 WiFi
4) ESP8266/ESP32-AT-command WiFi
5) WT32_ETH01 (ESP32 + LAN8720)
6) RTL8720DN
7) Portenta_H7
8) RP2040W WiFi
Based on and modified from Arduino NTPClient Library (https://github.com/arduino-libraries/NTPClient)
to support other boards such as ESP8266/ESP32, SAMD21, SAMD51, Adafruit's nRF52 boards, SAM DUE, RTL8720DN, etc.
Expand Down Expand Up @@ -63,6 +65,8 @@ char timeServer[] = "0.ca.pool.ntp.org";
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);

int WiFiStatus = WL_IDLE_STATUS;

void setup()
{
Serial.begin(115200);
Expand All @@ -81,6 +85,8 @@ void setup()
Serial.print ( "." );
}

WiFiStatus = WL_CONNECTED;

Serial.print(F("\nESP_NTPClient_Advanced started @ IP address: "));
Serial.println(WiFi.localIP());

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

void updateStatus()
{
static unsigned long wifiStatus_timeout = 0;
static unsigned long updateStatus_timeout = 0;

#define WIFI_CHECK_INTERVAL 1000L
#define UPDATE_INTERVAL 10000L

if ((millis() > wifiStatus_timeout) || (wifiStatus_timeout == 0))
{
if (WiFi.status() != WiFiStatus)
{
WiFiStatus = WiFi.status();

if (WiFiStatus == WL_CONNECTED)
Serial.println("Changed, WiFiStatus = Connected");
else if (WiFiStatus == WL_DISCONNECTED)
Serial.println("Changed, WiFiStatus = Disconnected");
else if (WiFiStatus == WL_IDLE_STATUS)
Serial.println("Changed, WiFiStatus = Idle");
else if (WiFiStatus == WL_NO_SSID_AVAIL)
Serial.println("Changed, WiFiStatus = lost WiFi SSID");
else if (WiFiStatus == WL_CONNECTION_LOST)
Serial.println("Changed, WiFiStatus = lost WiFi connection");
else
{
Serial.print("Changed, WiFiStatus = "); Serial.println(WiFiStatus);
}
}

wifiStatus_timeout = millis() + WIFI_CHECK_INTERVAL;
}

// Send update request every UPDATE_INTERVAL (10) seconds: we don't need to send update request frequently
if ((millis() > updateStatus_timeout) || (updateStatus_timeout == 0))
{
timeClient.update();

if (timeClient.updated())
Serial.println("********UPDATED********");
else
Serial.println("******NOT UPDATED******");

Serial.println("UTC : " + timeClient.getFormattedUTCTime());
Serial.println("UTC : " + timeClient.getFormattedUTCDateTime());
Serial.println("LOC : " + timeClient.getFormattedTime());
Serial.println("LOC : " + timeClient.getFormattedDateTime());
Serial.println("UTC EPOCH : " + String(timeClient.getUTCEpochTime()));
Serial.println("LOC EPOCH : " + String(timeClient.getEpochTime()));

// Function test
// Without leading 0
Serial.println(String("UTC : ") + timeClient.getUTCHours() + ":" + timeClient.getUTCMinutes() + ":" + timeClient.getUTCSeconds() + " " +
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
// With leading 0
Serial.println(String("UTC : ") + timeClient.getUTCStrHours() + ":" + timeClient.getUTCStrMinutes() + ":" + timeClient.getUTCStrSeconds() + " " +
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
// Without leading 0
Serial.println(String("LOC : ") + timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds() + " " +
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());
// With leading 0
Serial.println(String("LOC : ") + timeClient.getStrHours() + ":" + timeClient.getStrMinutes() + ":" + timeClient.getStrSeconds() + " " +
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());

updateStatus_timeout = millis() + UPDATE_INTERVAL;
}
}

void loop()
{
timeClient.update();


if (timeClient.updated())
Serial.println("********UPDATED********");
else
Serial.println("******NOT UPDATED******");

Serial.println("UTC : " + timeClient.getFormattedUTCTime());
Serial.println("UTC : " + timeClient.getFormattedUTCDateTime());
Serial.println("LOC : " + timeClient.getFormattedTime());
Serial.println("LOC : " + timeClient.getFormattedDateTime());
Serial.println("UTC EPOCH : " + String(timeClient.getUTCEpochTime()));
Serial.println("LOC EPOCH : " + String(timeClient.getEpochTime()));

// Function test
// Without leading 0
Serial.println(String("UTC : ") + timeClient.getUTCHours() + ":" + timeClient.getUTCMinutes() + ":" + timeClient.getUTCSeconds() + " " +
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
// With leading 0
Serial.println(String("UTC : ") + timeClient.getUTCStrHours() + ":" + timeClient.getUTCStrMinutes() + ":" + timeClient.getUTCStrSeconds() + " " +
timeClient.getUTCDoW() + " " + timeClient.getUTCDay() + "/" + timeClient.getUTCMonth() + "/" + timeClient.getUTCYear() + " or " +
timeClient.getUTCDay() + " " + timeClient.getUTCMonthStr() + " " + timeClient.getUTCYear());
// Without leading 0
Serial.println(String("LOC : ") + timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds() + " " +
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());
// With leading 0
Serial.println(String("LOC : ") + timeClient.getStrHours() + ":" + timeClient.getStrMinutes() + ":" + timeClient.getStrSeconds() + " " +
timeClient.getDoW() + " " + timeClient.getDay() + "/" + timeClient.getMonth() + "/" + timeClient.getYear() + " or " +
timeClient.getDay() + " " + timeClient.getMonthStr() + " " + timeClient.getYear());

delay(10000);
updateStatus();
}
16 changes: 9 additions & 7 deletions examples/ESP/ESP_NTPClient_Basic/ESP_NTPClient_Basic.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/****************************************************************************************************************************
ESP_NTPClient_Bas.ino
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN boards using
a) Ethernet W5x00, ENC28J60, LAN8742A
b) WiFiNINA
c) ESP8266/ESP32 WiFi
d) ESP8266/ESP32-AT-command WiFi
e) WT32_ETH01 (ESP32 + LAN8720)
f) RTL8720DN
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN, RP2040 boards using
1) Ethernet W5x00, ENC28J60, LAN8742A
2) WiFiNINA
3) ESP8266/ESP32 WiFi
4) ESP8266/ESP32-AT-command WiFi
5) WT32_ETH01 (ESP32 + LAN8720)
6) RTL8720DN
7) Portenta_H7
8) RP2040W WiFi
Based on and modified from Arduino NTPClient Library (https://github.com/arduino-libraries/NTPClient)
to support other boards such as ESP8266/ESP32, SAMD21, SAMD51, Adafruit's nRF52 boards, SAM DUE, RTL8720DN, etc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/****************************************************************************************************************************
ESP_WiFi_ETH_NTPClient_Advanced.ino
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, boards using
a) Ethernet W5x00, ENC28J60, LAN8742A
b) WiFiNINA
c) ESP8266/ESP32 WiFi
d) ESP8266/ESP32-AT-command WiFi
e) WT32_ETH01 (ESP32 + LAN8720)
f) RTL8720DN
For AVR, ESP8266/ESP32, SAMD21/SAMD51, nRF52, STM32, SAM DUE, WT32_ETH01, RTL8720DN, RP2040 boards using
1) Ethernet W5x00, ENC28J60, LAN8742A
2) WiFiNINA
3) ESP8266/ESP32 WiFi
4) ESP8266/ESP32-AT-command WiFi
5) WT32_ETH01 (ESP32 + LAN8720)
6) RTL8720DN
7) Portenta_H7
8) RP2040W WiFi
Based on and modified from Arduino NTPClient Library (https://github.com/arduino-libraries/NTPClient)
to support other boards such as ESP8266/ESP32, SAMD21, SAMD51, Adafruit's nRF52 boards, SAM DUE, RTL8720DN, etc.
Expand Down
45 changes: 23 additions & 22 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NTPClient_Generic",
"version": "3.7.4",
"version": "3.7.5",
"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",
"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",
"authors":
Expand Down Expand Up @@ -39,7 +39,7 @@
{
"owner": "khoih-prog",
"name": "Timezone_Generic",
"version": ">=1.10.0",
"version": ">=1.10.1",
"platforms": ["*"]
},
{
Expand All @@ -52,61 +52,61 @@
"owner": "khoih-prog",
"name": "FlashStorage_SAMD",
"version": ">=1.3.2",
"platforms": ["*"]
"platforms": ["atmelsam"]
},
{
"owner": "khoih-prog",
"name": "FlashStorage_STM32",
"version": ">=1.2.0",
"platforms": ["*"]
"platforms": ["ststm32"]
},
{
"owner": "khoih-prog",
"name": "FlashStorage_STM32F1",
"version": ">=1.1.0",
"platforms": ["*"]
"platforms": ["ststm32"]
},
{
"owner": "khoih-prog",
"name": "FlashStorage_RTL8720",
"version": ">=1.1.0",
"platforms": ["*"]
"platforms": ["AmebaD"]
},
{
"owner": "khoih-prog",
"name": "WiFiNINA_Generic",
"version": ">=1.8.14-3",
"version": ">=1.8.14-6",
"platforms": ["*"]
},
{
"owner": "khoih-prog",
"name": "EthernetWebServer",
"version": ">=2.1.3",
"version": ">=2.2.3",
"platforms": ["*"]
},
{
"owner": "khoih-prog",
"name": "EthernetWebServer_STM32",
"version": ">=1.4.1",
"platforms": ["*"]
"version": ">=1.5.0",
"platforms": ["ststm32"]
},
{
"owner": "khoih-prog",
"name": "WiFiWebServer",
"version": ">=1.8.0",
"version": ">=1.9.5",
"platforms": ["*"]
},
{
"owner": "khoih-prog",
"name": "WebServer_WT32_ETH01",
"version": ">=1.4.1",
"platforms": ["*"]
"version": ">=1.5.1",
"platforms": ["espressif32"]
},
{
"owner": "khoih-prog",
"name": "WiFiWebServer_RTL8720",
"version": ">=1.1.1",
"platforms": ["*"]
"version": ">=1.1.2",
"platforms": ["AmebaD"]
},
{
"owner": "khoih-prog",
Expand All @@ -123,42 +123,43 @@
{
"owner": "stm32duino",
"name": "STM32Ethernet",
"version": ">=1.2.0",
"version": ">=1.3.0",
"platforms": ["ststm32"]
},
{
"owner": "stm32duino",
"name": "STM32duino RTC",
"version": ">=1.2.0",
"version": ">=1.3.2",
"platforms": ["ststm32"]
},
{
"owner": "uipethernet",
"name": "UIPEthernet",
"version": ">=2.0.11",
"version": ">=2.0.12",
"platforms": ["*"]
},
{
"owner": "jandrassy",
"name": "EthernetENC",
"version": ">=2.0.2",
"version": ">=2.0.3",
"platforms": ["*"]
},
{
"owner": "jandrassy",
"name": "WiFiEspAT",
"version": ">=1.3.2",
"version": ">=1.4.1",
"platforms": ["*"]
},
{
"owner": "khoih-prog",
"name": "Ethernet_Generic",
"version": "^2.1.0"
"version": "^2.6.1",
"platforms": ["*"]
},
{
"owner": "ssilverman",
"name": "QNEthernet",
"version": ">=0.14.0",
"version": ">=0.15.0",
"platforms": ["teensy"]
}
],
Expand Down
Loading

0 comments on commit bf50ed8

Please sign in to comment.