khoih-prog / NTPClient_Generic

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, nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. besides AVR, using ESP WiFi, WiFiNINA, Ethernet W5x00, ENC28J60, LAN8742A, ESP8266/ESP32 AT-command WiFi.
MIT License
30 stars 12 forks source link
alarm esp32 esp8266 mbed nrf52 ntp-client ntp-server pico-w portenta-h7 portentah7 rp2040 rpi-pico rtc rtl8720dn sam-due samd stm32 time timezone wt32-eth01

NTPClient_Generic Library

arduino-library-badge GitHub release GitHub contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Important Change from v3.7.0

Please have a look at HOWTO Fix Multiple Definitions Linker Error

From v3.7.2, you can use the new setUDP() function for auto-switching between WiFi and Ethernet UDP to update NTP time.

Check examples ESP_WiFi_ETH_NTPClient_Advanced and WT32_WiFi_ETH01_NTPClient_Advanced for a demo.



Why do we need this NTPClient_Generic library

Features

The NTPClient_Generic library is designed to work in conjunction with the Arduino Time library, which must also be installed on your system. This documentation assumes some familiarity with the Time library.

The primary goal of the NTPClient_Generic library is to enable the creation of an NTPClient to connect to NTP time-servers to get time and keep local time in sync. For ESP8266/ESP32, WT32_ETH01 (ESP32 + LAN8720), nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, RP2040-based boards (Nano_RP2040_Connect, RASPBERRY_PI_PICO), etc. besides AVR, using ESP WiFi, WiFiNINA, Ethernet W5x00, ENC28J60, LAN8742A, ESP8266/ESP32 AT-command WiFi. But whether hardware RTC or another time-keeping source is present is not mandatory, since the Time library library can function as a software RTC without additional hardware (although its accuracy is dependent on the accuracy of the microcontroller's system clock.)

The examples will demonstrate how to get the UTC time from NTP server, then update the DS3231 RTC or local clock to make sure the time is perfectly correct.

In the examples, the interval to get perfect time from the NTP server to update RTC and/or local clock is configurable to ensure the RTC and/or local clock accuracy.

This NTPClient_Generic library is based on and modified from Fabrice Weinberg's NTPClient Library to add functions, features and as well as support to many boards and shields.


Currently supported Boards

This NTPClient_Generic library currently supports these following boards:

  1. nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc.

  2. SAMD21

    • Arduino SAMD21: ZERO, MKRs, NANO_33_IOT, etc.
    • Adafruit SAMD21 (M0): ItsyBitsy M0, Feather M0, Feather M0 Express, Metro M0 Express, Circuit Playground Express, Trinket M0, PIRkey, Hallowing M0, Crickit M0, etc.
    • Seeeduino: LoRaWAN, Zero, Femto M0, XIAO M0, Wio GPS Board, etc.
  3. SAMD51

    • Adafruit SAMD51 (M4): Metro M4, Grand Central M4, ItsyBitsy M4, Feather M4 Express, Trellis M4, Metro M4 AirLift Lite, MONSTER M4SK Express, Hallowing M4, etc.
    • Seeeduino: Wio Terminal, Grove UI Wireless
  4. SAM DUE

  5. Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0)

  6. STM32F/L/H/G/WB/MP1 boards (with 32+K Flash)

    • Nucleo-144
    • Nucleo-64
    • Discovery
    • Generic STM32F0, STM32F1, STM32F2, STM32F3, STM32F4, STM32F7 (with 64+K Flash): x8 and up
    • STM32L0, STM32L1, STM32L4
    • STM32G0, STM32G4
    • STM32H7
    • STM32WB
    • STM32MP1
    • LoRa boards
    • 3-D printer boards
    • Generic Flight Controllers
    • Midatronics boards
  7. ESP32

  8. ESP8266

  9. AVR Mega1280, 2560, ADK.

  1. RP2040-based boards, such as Nano_RP2040_Connect, using Arduino mbed OS for Nano boards.

  2. RP2040-based boards, such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Arduino-mbed RP2040 core or Earle Philhower's arduino-pico core.

  3. WT32_ETH01 boards using ESP32-based boards and LAN8720 Ethernet

  4. RTL8720DN, RTL8722DM, RTL8722CSM, etc. boards

  5. Portenta_H7 using Murata WiFi or Vision-shield Ethernet

  6. RP2040W boards using CYW43439 WiFi, such as RASPBERRY_PI_PICO_W, using Earle Philhower's arduino-pico core.


Currently supported WiFi shields/modules

  1. WiFiNINA using WiFiNINA_Generic library
  2. WiFi101 using WiFi101 library v0.16.1+
  3. U-Blox W101, W102 using WiFiNINA_Generic library
  4. ESP826-AT command using WiFiEspAT library
  5. ESP8266/ESP32-AT command using ESP_AT_Lib library and ESP8266_AT_WebServer
  6. ESP32 and ESP8266 WiFi
  7. RTL8720DN, RTL8722DM, RTL8722CSM
  8. Portenta_H7 Murata WiFi
  9. RASPBERRY_PI_PICO_W CYW43439 WiFi

Currently supported Ethernet shields/modules

  1. W5x00 using Ethernet_Generic library
  2. W5x00 using Ethernet, EthernetLarge, Ethernet2 or Ethernet3 library
  3. ENC28J60 using EthernetENC or UIPEthernet library
  4. Teensy 4.1 built-in Ethernet using NativeEthernet library
  5. Teensy 4.1 built-in Ethernet using QNEthernet library
  6. LAN8742A using STM32Ethernet / STM32 LwIP libraries.
  7. LAN8720A in WT32-ETH01 using WebServer_WT32_ETH01
  8. Portenta_H7 Ethernet using Portenta_Ethernet library


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. ESP32 Core 2.0.5+ for ESP32-based boards. Latest release
  3. ESP8266 Core 3.0.2+ for ESP8266-based boards. Latest release. To use ESP8266 core 2.7.1+ for LittleFS.
  4. Arduino AVR core 1.8.5+ for Arduino (Use Arduino Board Manager) for AVR boards. GitHub release
  5. Teensy core v1.57+ for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards.
  6. Arduino SAM DUE core v1.6.12+ for SAM DUE ARM Cortex-M3 boards.
  7. Arduino SAMD core 1.8.13+ for SAMD ARM Cortex-M0+ boards. GitHub release
  8. Adafruit SAMD core 1.7.10+ for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). GitHub release
  9. Seeeduino SAMD core 1.8.3+ for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). Latest release
    1. Adafruit nRF52 v1.3.0+ for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, NINA_B302_ublox, etc. GitHub release
    2. Arduino Core for STM32 v2.3.0+ for STM32F/L/H/G/WB/MP1 boards. GitHub release
    3. ArduinoCore-mbed mbed_rp2040, mbed_nano, mbed_portenta core 3.4.1+ for Arduino (Use Arduino Board Manager) Portenta_H7, RP2040-based boards, such as Nano_RP2040_Connect, RASPBERRY_PI_PICO. GitHub release
    4. Earle Philhower's arduino-pico core v2.6.1+ for RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, etc. GitHub release
    5. Arduino AmebaD core 3.1.4+ for Realtek RTL8720DN, RTL8722DM and RTL8722CSM. GitHub release
  1. Time v1.6.1+. GitHub release

  2. For built-in LAN8742A Ethernet:

  3. For W5x00 Ethernet:

  4. For ENC28J60 Ethernet:

  5. WiFiNINA_Generic library v1.8.14-6+ to use WiFiNINA modules/shields. To install. check arduino-library-badge if using WiFiNINA for boards such as Nano 33 IoT, nRF52, Teensy, etc.

  6. WiFiWebServer library v1.9.5+ to use WiFi/WiFiNINA modules/shields. To install, check arduino-library-badge

  7. EthernetWebServer library v2.2.3+ to use Ethernet modules/shields on boards other than STM32F/L/H/G/WB/MP1. To install. check arduino-library-badge.

  8. EthernetWebServer_STM32 library v1.5.0+ to use Ethernet modules/shields on STM32F/L/H/G/WB/MP1 boards. To install, check arduino-library-badge.

  9. ESP8266_AT_WebServer library v1.5.4+ to use ESP8266-AT/ESP32-AT WiFi modules/shields. To install, check arduino-library-badge

  10. DS323x_Generic library v1.3.1+ to use examples using DS323x RTC modules/shields. To install, check arduino-library-badge

  11. Timezone_Generic library v1.10.1+ to use examples using Timezone. To install, check arduino-library-badge

  12. STM32RTC library v1.3.2+ to use STM32 examples using built-in STM32 RTC. GitHub release.

  13. WebServer_WT32_ETH01 library v1.5.1+ to use WT32_ETH01 (ESP32 + LAN8720). To install, check arduino-library-badge.

  14. WiFiWebServer_RTL8720 library v1.1.2+ to use Realtek RTL8720DN, etc. To install, check arduino-library-badge.

  15. Modified WiFi101 Library v0.16.1+ to use SAMD MKR1000, etc. boards with WiFi101.

  16. WiFiEspAT library v1.4.1+ if using ESP8288/ESP32-AT shields. GitHub release

  17. FlashStorage_SAMD library v1.3.2+ for SAMD21 and SAMD51 boards (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit Itsy-Bitsy M4, etc.). GitHub release

  18. FlashStorage_STM32F1 library v1.1.0+ for STM32F1/F3 boards. To install. check arduino-library-badge

  19. FlashStorage_STM32 library v1.2.0+ for STM32F/L/H/G/WB/MP1 boards. To install. check arduino-library-badge



Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for NTPClient_Generic, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

Another way to install is to:

  1. Navigate to NTPClient_Generic page.
  2. Download the latest release NTPClient_Generic-main.zip.
  3. Extract the zip file to NTPClient_Generic-main directory
  4. Copy whole NTPClient_Generic-main/src folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO

  1. Install VS Code
  2. Install PlatformIO
  3. Install NTPClient_Generic library by using Library Manager. Search for NTPClient_Generic in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


Packages' Patches

1. For Adafruit nRF52840 and nRF52832 boards

To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards, you have to copy the whole nRF52 Packages_Patches directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0).

Supposing the Adafruit nRF52 version is 1.3.0. These files must be copied into the directory:

Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z These files must be copied into the directory:

2. For Teensy boards

To be able to compile and run on Teensy boards, you have to copy the files in Packages_Patches for Teensy directory into Teensy hardware directory (./arduino-1.8.19/hardware/teensy/avr/boards.txt).

Supposing the Arduino version is 1.8.19. These files must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz These files must be copied into the directory:

3. For Arduino SAM DUE boards

To be able to compile and run on SAM DUE boards, you have to copy the whole SAM DUE directory into Arduino sam directory (~/.arduino15/packages/arduino/hardware/sam/1.6.12).

Supposing the Arduino SAM core version is 1.6.12. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:

4. For Arduino SAMD boards

To be able to compile, run and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards, you have to copy the whole Arduino SAMD Packages_Patches directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.13).

For core version v1.8.10+

Supposing the Arduino SAMD version is 1.8.13. Now only one file must be copied into the directory:

Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

For core version v1.8.9-

Supposing the Arduino SAMD version is 1.8.9. These files must be copied into the directory:

Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z

These files must be copied into the directory:

 ...\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)

Whenever the above-mentioned compiler error issue is fixed with the new Arduino SAMD release, you don't need to copy the Arduino.h file anymore.

5. For Adafruit SAMD boards

To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards, you have to copy the whole Adafruit SAMD Packages_Patches directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.10).

Supposing the Adafruit SAMD core version is 1.7.10. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:

6. For Seeeduino SAMD boards

To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards, you have to copy the whole Seeeduino SAMD Packages_Patches directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3).

Supposing the Seeeduino SAMD core version is 1.8.3. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:

7. For STM32 boards

7.1 For STM32 boards to use LAN8720

To use LAN8720 on some STM32 boards

you have to copy the files stm32f4xx_hal_conf_default.h and stm32f7xx_hal_conf_default.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system) to overwrite the old files.

Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:

7.2 For STM32 boards to use Serial1

To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards, you have to copy the files STM32 variant.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.

Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:

8. For RP2040-based boards using Earle Philhower arduino-pico core

8.1 To use BOARD_NAME

To be able to automatically detect and display BOARD_NAME on RP2040-based boards (RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc) boards, you have to copy the file RP2040 platform.txt into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).

Supposing the rp2040 core version is 1.4.0. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:

With core after v1.5.0, this step is not necessary anymore thanks to the PR Add -DBOARD_NAME="{build.board}" #136.

8.2 To avoid compile error relating to microsecondsToClockCycles

Some libraries, such as Adafruit DHT-sensor-library, require the definition of microsecondsToClockCycles(). To be able to compile and run on RP2040-based boards, you have to copy the files in RP2040 Arduino.h into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).

Supposing the rp2040 core version is 1.4.0. This file must be copied to replace:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied to replace:

With core after v1.5.0, this step is not necessary anymore thanks to the PR Add defs for compatibility #142.

9. For Portenta_H7 boards using Arduino IDE in Linux

To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.), you have to copy the file portenta_post_install.sh into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh).

Then run the following command using sudo

$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh

This will create the file /etc/udev/rules.d/49-portenta_h7.rules as follows:

# Portenta H7 bootloader mode UDEV rules

SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"

Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory:

Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

10. For RTL8720DN boards using AmebaD core

To avoid compile error relating to PROGMEM, you have to copy the file Realtek AmebaD core pgmspace.h into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/arduino/avr/pgmspace.h).

Supposing the Realtek AmebaD core version is 3.1.4. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:

11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core

To avoid compile error relating to SAMD21/SAMD51, you have to copy the file ArduinoCore-fab-sam core pgmspace.h into ArduinoCore-fab-sam samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt).

Supposing the ArduinoCore-fab-sam samd core version is 1.7.0. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:

12. For Seeeduino RP2040 boards

To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino RP2040 (XIAO RP2040, Wio RP2040 Mini) boards, you have to copy the whole Seeeduino RP2040 Packages_Patches directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2).

Supposing the Seeeduino SAMD core version is 2.7.2. This file must be copied into the directory:

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:



Libraries' Patches

1. For application requiring 2K+ HTML page

If your application requires 2K+ HTML page, the current Ethernet library must be modified if you are using W5200/W5500 Ethernet shields. W5100 is not supported for 2K+ buffer. If you use boards requiring different CS/SS pin for W5x00 Ethernet shield, for example ESP32, ESP8266, nRF52, etc., you also have to modify the following libraries to be able to specify the CS/SS pin correctly.

2. For Ethernet library

To fix Ethernet library, just copy these following files into the Ethernet library directory to overwrite the old files:

3. For EthernetLarge library

To fix EthernetLarge library, just copy these following files into the EthernetLarge library directory to overwrite the old files:

4. For Ethernet2 library

To fix Ethernet2 library, just copy these following files into the Ethernet2 library directory to overwrite the old files:

To add UDP Multicast support, necessary for the UPnP_Generic library:

5. For Ethernet3 library

  1. To fix Ethernet3 library, just copy these following files into the Ethernet3 library directory to overwrite the old files:

6. For UIPEthernet library

To be able to compile and run on nRF52 boards with ENC28J60 using UIPEthernet library, you have to copy these following files into the UIPEthernet utility directory to overwrite the old files:

7. For fixing ESP32 compile error

To fix ESP32 compile error, just copy the following file into the ESP32 cores/esp32 directory (e.g. ./arduino-1.8.13/hardware/espressif/cores/esp32) to overwrite the old file:

8. For fixing ESP8266 compile error

To fix ESP8266 compile error such as

error: 'class EthernetClass' has no member named 'init'
Ethernet.init (USE_THIS_SS_PIN);

just rename the following file in ./arduino-1.8.13/hardware/esp8266com/esp8266/libraries/Ethernet directory



HOWTO Fix Multiple Definitions Linker Error

The current library implementation, using xyz-Impl.h instead of standard xyz.cpp, possibly creates certain Multiple Definitions Linker error in certain use cases.

You can use

#include <NTPClient_Generic.hpp>               //https://github.com/khoih-prog/NTPClient_Generic

in many files. But be sure to use the following #include <NTPClient_Generic.h> in just 1 .h, .cpp or .ino file, which must not be included in any other file, to avoid Multiple Definitions Linker Error

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <NTPClient_Generic.h>                //https://github.com/khoih-prog/NTPClient_Generic

Check multiFileProject for a demo how to avoid multiple-definitions linker error for multiple-file project



HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)

Please have a look at ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to have more detailed description and solution of the issue.

1. ESP32 has 2 ADCs, named ADC1 and ADC2

2. ESP32 ADCs functions

3.. ESP32 WiFi uses ADC2 for WiFi functions

Look in file adc_common.c

In ADC2, there're two locks used for different cases:

  1. lock shared with app and Wi-Fi: ESP32: When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed. ESP32S2: The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.

  2. lock shared between tasks: when several tasks sharing the ADC2, we want to guarantee all the requests will be handled. Since conversions are short (about 31us), app returns the lock very soon, we use a spinlock to stand there waiting to do conversions one by one.

adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.



Important Notes

  1. Code is restructured to provide flexibility to make it easy to support many more WiFi/Ethernet modules/shields in the future. Please delete the .cpp files, replaced by .hpp files, in the src directory, if *.cpp files still exist after installing new version.

  2. For Adafruit nRF52, use the SPI's pin as follows:

    • SS/CS = 10
    • SPI_MOSI = MO(SI)
    • SPI_MISO = MI(SO)
    • SPI_SCK = SCK
  3. For Adafruit SAMD21/SAMD51, use the SPI's CS/SS pin as follows:

    • Itsy-Bitsy M0/M4, Feather M0 (Express), Hallowing M0 Express, Zero, Metro M0 => use CS = 16 = pin A2
    • Feather M4 (SAMD51) => use SS/CS = 9
    • Grand Central M4 => use SS/CS = 53
    • Hallowing M4 => use SS/CS = 10
    • Metro M4 AirLift => use SS/CS = 36

To know the default CS/SS pins of not listed boards, check the related variant.h files in

~/.arduino15/packages/adafruit/hardware/samd/x.y.zz/variants/board_name/variant.h

  1. For Arduino SAM DUE, use the SPI's pin as follows:



Examples

ESP32/ESP8266 Boards

  1. ESP_NTPClient_Advanced
  2. ESP_NTPClient_Basic
  3. ESP_WiFi_ETH_NTPClient_Advanced New

Generic Boards with Ethernet

  1. Ethernet_NTPClient_Advanced
  2. Ethernet_NTPClient_Basic
  3. RTC_Ethernet_NTPClient
  4. TZ_NTP_Clock_Ethernet
  5. TZ_NTP_WorldClock_Ethernet

STM32F/L/H/G/WB/MP1 Boards with Ethernet

  1. BI_RTC_Alarm_Ethernet_NTPClient_STM32
  2. BI_RTC_Ethernet_NTPClient_STM32
  3. Ethernet_NTPClient_Advanced_STM32
  4. Ethernet_NTPClient_Basic_STM32
  5. RTC_Ethernet_NTPClient_STM32
  6. TZ_NTP_Clock_STM32_Ethernet
  7. TZ_NTP_WorldClock_STM32_Ethernet

Generic Boards with WiFiNINA

  1. NINA_NTPClient_Advanced
  2. NINA_NTPClient_Basic
  3. NINA_TZ_NTP_Clock
  4. NINA_TZ_NTP_WorldClock

WT32_ETH01 Boards

  1. WT32_ETH01_NTPClient_Advanced
  2. WT32_ETH01_NTPClient_Basic
  3. WT32_ETH01_TZ_NTP_Clock
  4. WT32_ETH01_TZ_NTP_WorldClock
  5. WT32_WiFi_ETH01_NTPClient_Advanced New

RTL8720DN Boards

  1. RTL8720DN_NTPClient_Advanced
  2. RTL8720DN_NTPClient_Basic
  3. RTL8720DN_TZ_NTP_Clock
  4. RTL8720DN_TZ_NTP_WorldClock

Portenta_H7 Boards with WiFi

  1. Portenta_H7_NTPClient_Advanced
  2. Portenta_H7_NTPClient_Basic

Portenta_H7 Boards with Ethernet

  1. Portenta_H7_NTPClient_Advanced
  2. Portenta_H7_NTPClient_Basic

General

  1. multiFileProject New


Example RTC_Ethernet_NTPClient

1. File RTC_Ethernet_NTPClient.ino

https://github.com/khoih-prog/NTPClient_Generic/blob/bf50ed80564ea39a2475eb2053e48734777d7131/examples/Generic/Ethernet/RTC_Ethernet_NTPClient/RTC_Ethernet_NTPClient.ino#L24-L394


2. File defines.h

https://github.com/khoih-prog/NTPClient_Generic/blob/bf50ed80564ea39a2475eb2053e48734777d7131/examples/Generic/Ethernet/RTC_Ethernet_NTPClient/defines.h#L20-L494



Debug Terminal Output Samples

1. Ethernet_NTPClient_Advanced on Adafruit NRF52840_FEATHER_EXPRESS with ENC28J60 using EthernetENC Library

Following is the debug terminal output when running example Ethernet_NTPClient_Advanced on Adafruit NRF52840_FEATHER_EXPRESS with ENC28J60 using EthernetENC Library

Starting Ethernet_NTPClient_Advanced on NRF52840_FEATHER with ENC28J60 using EthernetENC Library
NTPClient_Generic v3.7.5
[EWS] =========================
[EWS] Default SPI pinout:
[EWS] MOSI: 25
[EWS] MISO: 24
[EWS] SCK: 26
[EWS] SS: 5
[EWS] =========================
[EWS] Board : NRF52840_FEATHER , setCsPin: 10
=========================
Currently Used SPI pinout:
MOSI:25
MISO:24
SCK:26
SS:5
=========================
Using mac index = 3
You're connected to the network, IP = 192.168.2.79
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

2. NINA_NTPClient_Advanced on Arduino SAMD21 SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library

Following is the debug terminal output when running example NINA_NTPClient_Advanced on Arduino SAMD21 SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library

Starting NINA_NTPClient_Advanced on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
NTPClient_Generic v3.7.5
Connecting to: HueNet1

NTPClient_Advanced started @ IP address: 192.168.2.98
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

3. TZ_NTP_WorldClock_Ethernet on Adafruit NRF52840_FEATHER_EXPRESS with W5500 using Ethernet_Generic Library

Following is the debug terminal output when running example TZ_NTP_WorldClock_Ethernet on Adafruit NRF52840_FEATHER_EXPRESS with W5500 using Ethernet_Generic Library

Start TZ_NTP_WorldClock_Ethernet on NRF52840_FEATHER with W5x00 using Ethernet_Generic Library
NTPClient_Generic v3.7.5
[EWS] =========== USE_ETHERNET_GENERIC ===========
[EWS] Default SPI pinout:
[EWS] MOSI: 25
[EWS] MISO: 24
[EWS] SCK: 26
[EWS] SS: 5
[EWS] =========================
[EWS] Board : NRF52840_FEATHER , setCsPin: 10
=========================
Currently Used SPI pinout:
MOSI:25
MISO:24
SCK:26
SS:5
=========================
Using mac index = 17
You're connected to the network, IP = 192.168.2.80
********UPDATED********
Time updated. Next update in seconds : 3600

04:05:18 Sun 10 Apr 2022 AEST Sydney
21:05:18 Sat 09 Apr 2022 MSK  Moscow
20:05:18 Sat 09 Apr 2022 CEST Paris
19:05:18 Sat 09 Apr 2022 BST  London
18:05:18 Sat 09 Apr 2022 UTC  Universal Coordinated Time
14:05:18 Sat 09 Apr 2022 EDT  New York
13:05:18 Sat 09 Apr 2022 CDT  Chicago
12:05:18 Sat 09 Apr 2022 MDT  Denver
11:05:18 Sat 09 Apr 2022 MST  Phoenix
11:05:18 Sat 09 Apr 2022 PDT  Los Angeles

4. TZ_NTP_WorldClock_STM32_Ethernet on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

Following is the debug terminal output when running example TZ_NTP_WorldClock_STM32_Ethernet on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

Start TZ_NTP_WorldClock_STM32_Ethernet on NUCLEO_F767ZI, using LAN8742A Ethernet & STM32Ethernet Library
EthernetWebServer_STM32 v1.5.0
NTPClient_Generic v3.7.5
You're connected to the network, IP = 192.168.2.96
Retry Time update in seconds : 3
********UPDATED********
Time updated. Next update in seconds : 3600

04:05:18 Sun 10 Apr 2022 AEST Sydney
21:05:18 Sat 09 Apr 2022 MSK  Moscow
20:05:18 Sat 09 Apr 2022 CEST Paris
19:05:18 Sat 09 Apr 2022 BST  London
18:05:18 Sat 09 Apr 2022 UTC  Universal Coordinated Time
14:05:18 Sat 09 Apr 2022 EDT  New York
13:05:18 Sat 09 Apr 2022 CDT  Chicago
12:05:18 Sat 09 Apr 2022 MDT  Denver
11:05:18 Sat 09 Apr 2022 MST  Phoenix
11:05:18 Sat 09 Apr 2022 PDT  Los Angeles

5. RTC_Ethernet_NTPClient on Adafruit NRF52840_FEATHER_EXPRESS with ENC28J60 using EthernetENC Library

Following is the debug terminal output when running example RTC_Ethernet_NTPClient on Adafruit NRF52840_FEATHER_EXPRESS with ENC28J60 using EthernetENC Library

Start RTC_Ethernet_NTPClient on NRF52840_FEATHER with ENC28J60 using EthernetENC Library
NTPClient_Generic v3.7.5
[EWS] =========================
[EWS] Default SPI pinout:
[EWS] MOSI: 25
[EWS] MISO: 24
[EWS] SCK: 26
[EWS] SS: 5
[EWS] =========================
[EWS] Board : NRF52840_FEATHER , setCsPin: 10
=========================
Currently Used SPI pinout:
MOSI:25
MISO:24
SCK:26
SS:5
=========================
Using mac index = 0
You're connected to the network, IP = 192.168.2.94
============================
18:15:32 Sat 09 Apr 2022 UTC
14:15:32 Sat 09 Apr 2022 EDT
********UPDATED********
RTC updated. Next update in seconds : 3600
============================
18:15:41 Sat 09 Apr 2022 UTC
14:15:41 Sat 09 Apr 2022 EDT
============================
18:15:50 Sat 09 Apr 2022 UTC
14:15:50 Sat 09 Apr 2022 EDT
============================

6. RTC_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

Following is the debug terminal output when running example RTC_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

Start RTC_Ethernet_NTPClient_STM32 on NUCLEO_F767ZI, using LAN8742A Ethernet & STM32Ethernet Library
EthernetWebServer_STM32 v1.5.0
NTPClient_Generic v3.7.5
You're connected to the network, IP = 192.168.2.105
Retry RTC update in seconds : 3
********UPDATED********
RTC updated. Next update in seconds : 3600
============================
22:17:23 Wed 27 Apr 2022 UTC
18:17:23 Wed 27 Apr 2022 EDT
============================
22:17:33 Wed 27 Apr 2022 UTC
18:17:33 Wed 27 Apr 2022 EDT

7. ESP_NTPClient_Advanced on ESP8266_NODEMCU_ESP12E

Following is the debug terminal output when running example ESP_NTPClient_Advanced on ESP8266_NODEMCU_ESP12E.

Starting ESP_NTPClient_Advanced on ESP8266_NODEMCU_ESP12E
NTPClient_Generic v3.7.5
Connecting to: HueNet1
....
ESP_NTPClient_Advanced started @ IP address: 192.168.2.69
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

8. ESP_NTPClient_Advanced on ESP32_DEV

Following is the debug terminal output when running example ESP_NTPClient_Advanced on ESP32_DEV.

Starting ESP_NTPClient_Advanced on ESP32_DEV
NTPClient_Generic v3.7.5
Connecting to: HueNet1
....
ESP_NTPClient_Advanced started @ IP address: 192.168.2.101
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

9. Ethernet_NTPClient_Advanced on SAM DUE with W5100 using Ethernet_Generic Library

Following is the debug terminal output when running example Ethernet_NTPClient_Advanced on SAM DUE with W5100 using Ethernet_Generic Library

Starting Ethernet_NTPClient_Advanced on SAM DUE with W5x00 using Ethernet_Generic Library
NTPClient_Generic v3.7.5
[EWS] =========== USE_ETHERNET_GENERIC ===========
[EWS] Default SPI pinout:
[EWS] MOSI: 75
[EWS] MISO: 74
[EWS] SCK: 76
[EWS] SS: 10
[EWS] =========================
[EWS] Board : SAM DUE , setCsPin: 10
_pinCS = 0
W5100 init, using SS_PIN_DEFAULT = 10, new ss_pin = 10, W5100Class::ss_pin = 10
W5100::init: W5100, SSIZE =4096
=========================
Currently Used SPI pinout:
MOSI:75
MISO:74
SCK:76
SS:10
=========================
Using mac index = 6
You're connected to the network, IP = 192.168.2.71
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

10. BI_RTC_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

Following is the debug terminal output when running example BI_RTC_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library to demonstrate the usage of STM32 built-in RTC

Start BI_RTC_Ethernet_NTPClient_STM32 on NUCLEO_F767ZI, using LAN8742A Ethernet & STM32Ethernet Library
EthernetWebServer_STM32 v1.5.0
NTPClient_Generic v3.7.5
You're connected to the network, IP = 192.168.2.96
Retry RTC update in seconds : 3

Updating Time for STM32 RTC
********UPDATED********
RTC updated. Next update in seconds : 3600
============================
18:15:41 Sat 09 Apr 2022 UTC
14:15:41 Sat 09 Apr 2022 EDT
============================
18:15:50 Sat 09 Apr 2022 UTC
14:15:50 Sat 09 Apr 2022 EDT

11. BI_RTC_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with ENC28J60 using EthernetENC Library

Following is the debug terminal output when running example BI_RTC_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with ENC28J60 using EthernetENC Library to demonstrate the usage of STM32 built-in RTC

Start BI_RTC_Ethernet_NTPClient_STM32 on NUCLEO_F767ZI, using ENC28J60 & EthernetENC Library
NTPClient_Generic v3.7.5
[EWS] Board : NUCLEO_F767ZI , setCsPin: 10
[EWS] Default SPI pinout:
[EWS] MOSI: 11
[EWS] MISO: 12
[EWS] SCK: 13
[EWS] SS: 10
[EWS] =========================
BYou're connected to the network, IP = 192.168.2.97

Updating Time for STM32 RTC
********UPDATED********
RTC updated. Next update in seconds : 3600
============================
22:18:43 Wed 27 Apr 2022 UTC
18:18:43 Wed 27 Apr 2022 EDT
============================
22:18:53 Wed 27 Apr 2022 UTC
18:18:53 Wed 27 Apr 2022 EDT

12. BI_RTC_Alarm_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

Following is the debug terminal output when running example BI_RTC_Alarm_Ethernet_NTPClient_STM32 on STM32F7 Nucleo-144 NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library to demonstrate the usage of STM32 built-in RTC Alarm function

Start BI_RTC_Alarm_Ethernet_NTPClient_STM32 on NUCLEO_F767ZI with LAN8742A Ethernet & STM32Ethernet Library
EthernetWebServer_STM32 v1.5.0
NTPClient_Generic v3.7.5
You're connected to the network, IP = 192.168.2.88
Retry RTC update in seconds : 3

Updating Time for STM32 RTC
********UPDATED********
=======RTC ALARM SET========
18:13:52 Sat 09 Apr 2022 UTC
14:13:52 Sat 09 Apr 2022 EDT
============================
RTC updated. Next update in seconds : 3600
============================
18:13:28 Sat 09 Apr 2022 UTC
14:13:28 Sat 09 Apr 2022 EDT
============================
18:13:37 Sat 09 Apr 2022 UTC
14:13:37 Sat 09 Apr 2022 EDT
============================
18:13:47 Sat 09 Apr 2022 UTC
14:13:47 Sat 09 Apr 2022 EDT
*****RTC ALARM ACTIVATED*****
*****RTC ALARM ACTIVATED*****
============================
18:13:56 Sat 09 Apr 2022 UTC
14:13:56 Sat 09 Apr 2022 EDT
============================
18:14:05 Sat 09 Apr 2022 UTC
14:14:05 Sat 09 Apr 2022 EDT

13. NINA_NTPClient_Basic on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library

Following is the debug terminal output when running example NINA_NTPClient_Basic on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library

Starting NINA_NTPClient_Basic on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
NTPClient_Generic v3.7.5
Connecting to: HueNet1

NINA_NTPClient_Basic started @ IP address: 192.168.2.153
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

14. Ethernet_NTPClient_Advanced on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

Following is the debug terminal output when running example Ethernet_NTPClient_Advanced on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

Starting Ethernet_NTPClient_Advanced on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library
NTPClient_Generic v3.7.5
[EWS] =========== USE_ETHERNET_GENERIC ===========
[EWS] Default SPI pinout:
[EWS] MOSI: 19
[EWS] MISO: 16
[EWS] SCK: 18
[EWS] SS: 17
[EWS] =========================
[EWS] RPIPICO setCsPin: 17
=========================
Currently Used SPI pinout:
MOSI:19
MISO:16
SCK:18
SS:17
========
=========================
Using mac index = 10
You're connected to the network, IP = 192.168.2.94
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

15. Ethernet_NTPClient_Advanced on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

Following is the debug terminal output when running example Ethernet_NTPClient_Advanced on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

Starting Ethernet_NTPClient_Advanced on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library
NTPClient_Generic v3.7.5
[EWS] =========== USE_ETHERNET_GENERIC ===========
[EWS] Default SPI pinout:
[EWS] MOSI: 19
[EWS] MISO: 16
[EWS] SCK: 18
[EWS] SS: 17
[EWS] =========================
[EWS] RPIPICO setCsPin: 17
=========================
Currently Used SPI pinout:
MOSI:19
MISO:16
SCK:18
SS:17
=========================
Using mac index = 5
You're connected to the network, IP = 192.168.2.123
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

16. NINA_TZ_NTP_WorldClock on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library

Following is the debug terminal output when running example NINA_TZ_NTP_WorldClock on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library

Starting NINA_TZ_NTP_WorldClock on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
NTPClient_Generic v3.7.5
Connecting to WPA SSID: HueNet1
You're connected to the network, IP = 192.168.2.153
********UPDATED********
Time updated. Next update in seconds : 3600

04:05:18 Sun 10 Apr 2022 AEST Sydney
21:05:18 Sat 09 Apr 2022 MSK  Moscow
20:05:18 Sat 09 Apr 2022 CEST Paris
19:05:18 Sat 09 Apr 2022 BST  London
18:05:18 Sat 09 Apr 2022 UTC  Universal Coordinated Time
14:05:18 Sat 09 Apr 2022 EDT  New York
13:05:18 Sat 09 Apr 2022 CDT  Chicago
12:05:18 Sat 09 Apr 2022 MDT  Denver
11:05:18 Sat 09 Apr 2022 MST  Phoenix
11:05:18 Sat 09 Apr 2022 PDT  Los Angeles

17. WT32_ETH01_TZ_NTP_WorldClock on ESP32_DEV with ETH_PHY_LAN8720

Following is the debug terminal output when running example WT32_ETH01_TZ_NTP_WorldClock on ESP32_DEV with ETH_PHY_LAN8720

Starting WT32_ETH01_TZ_NTP_WorldClock on ESP32_DEV with ETH_PHY_LAN8720
WebServer_WT32_ETH01 v1.5.1
NTPClient_Generic v3.7.5
ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232
FULL_DUPLEX, 100Mbps
WT32_ETH01_TZ_NTP_WorldClock started @ IP address: 192.168.2.232
********UPDATED********
Time updated. Next update in seconds : 3600

04:05:18 Sun 10 Apr 2022 AEST Sydney
21:05:18 Sat 09 Apr 2022 MSK  Moscow
20:05:18 Sat 09 Apr 2022 CEST Paris
19:05:18 Sat 09 Apr 2022 BST  London
18:05:18 Sat 09 Apr 2022 UTC  Universal Coordinated Time
14:05:18 Sat 09 Apr 2022 EDT  New York
13:05:18 Sat 09 Apr 2022 CDT  Chicago
12:05:18 Sat 09 Apr 2022 MDT  Denver
11:05:18 Sat 09 Apr 2022 MST  Phoenix
11:05:18 Sat 09 Apr 2022 PDT  Los Angeles

18. WT32_ETH01_NTPClient_Advanced on ESP32_DEV with ETH_PHY_LAN8720

Following is the debug terminal output when running example WT32_ETH01_NTPClient_Advanced on ESP32_DEV with ETH_PHY_LAN8720

Starting WT32_ETH01_NTPClient_Advanced on ESP32_DEV with ETH_PHY_LAN8720
WebServer_WT32_ETH01 v1.5.1
NTPClient_Generic v3.7.5
ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232
FULL_DUPLEX, 100Mbps
WT32_ETH01_NTPClient_Advanced started @ IP address: 192.168.2.232
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

19. RTL8720DN_TZ_NTP_WorldClock on Rtlduino RTL8720DN

Following is the debug terminal output when running example RTL8720DN_TZ_NTP_WorldClock on Rtlduino RTL8720DN

Starting RTL8720DN_TZ_NTP_WorldClock on Rtlduino RTL8720DN
WiFiWebServer_RTL8720 v1.1.1
NTPClient_Generic v3.7.5
Current Firmware Version = 1.0.0
Attempting to connect to SSID: HueNet_5G
TZ_NTP_Clock_RTL8720DN started @ IP address: 192.168.2.111
Retry Time update in seconds : 3
********UPDATED********
Time updated. Next update in seconds : 3600

04:05:18 Sun 10 Apr 2022 AEST Sydney
21:05:18 Sat 09 Apr 2022 MSK  Moscow
20:05:18 Sat 09 Apr 2022 CEST Paris
19:05:18 Sat 09 Apr 2022 BST  London
18:05:18 Sat 09 Apr 2022 UTC  Universal Coordinated Time
14:05:18 Sat 09 Apr 2022 EDT  New York
13:05:18 Sat 09 Apr 2022 CDT  Chicago
12:05:18 Sat 09 Apr 2022 MDT  Denver
11:05:18 Sat 09 Apr 2022 MST  Phoenix
11:05:18 Sat 09 Apr 2022 PDT  Los Angeles

20. Portenta_H7_NTPClient_Advanced on PORTENTA_H7_M7 with WiFi

Following is the debug terminal output when running example Portenta_H7_NTPClient_Advanced on on PORTENTA_H7_M7 with Murata WiFi

Starting Portenta_H7_NTPClient_Advanced on PORTENTA_H7_M7
NTPClient_Generic v3.7.5
Connecting to: HueNet1
Portenta_H7_NTPClient_Advanced started @ IP address: 192.168.2.104
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

21. Portenta_H7_NTPClient_Advanced on PORTENTA_H7_M7 with Ethernet

Following is the debug terminal output when running example Portenta_H7_NTPClient_Advanced on on PORTENTA_H7_M7 with Vision-shield Ethernet

Starting Portenta_H7_NTPClient_Advanced using Ethernet on PORTENTA_H7_M7
NTPClient_Generic v3.7.5
Portenta_H7_NTPClient_Basic started @ IP address: 192.168.2.111
Using NTP Server 0.ca.pool.ntp.org
******NOT UPDATED******
UTC : 00:00:01
UTC :  0: 0: 1 Thu  1 Jan 1970
LOC : 02:28:17
LOC :  2:28:17 Sun  7 Feb 2106
UTC EPOCH : 1
LOC EPOCH : 4294952897
UTC : 0:0:1 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:01 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:17 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:17 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 17:51:56
UTC : 17:51:56 Sat  9 Apr 2022
LOC : 13:51:56
LOC : 13:51:56 Sat  9 Apr 2022
UTC EPOCH : 1649526716
LOC EPOCH : 1649512316
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
UTC : 17:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022
LOC : 13:51:56 Sat 9/4/2022 or 9 Apr 2022

22. ESP_WiFi_ETH_NTPClient_Advanced on ESP32_DEV with W5x00 using Ethernet_Generic Library

Following is the debug terminal output when running example ESP_WiFi_ETH_NTPClient_Advanced on ESP32_DEV with W5x00 using Ethernet_Generic Library to demonstrate how to to use the new setUDP() function for auto-switching between WiFi and Ethernet UDP to update NTP time.

Starting ESP_WiFi_ETH_NTPClient_Advanced on ESP32_DEV with W5x00 using Ethernet_Generic Library
EthernetWebServer v2.2.3
NTPClient_Generic v3.7.5
Connecting to: HueNet1
...................
WiFi failed to connect      <=====  Start without WiFi to use Ethernet UDP
.[EWS] =========== USE_ETHERNET_GENERIC ===========
[EWS] Default SPI pinout:
[EWS] MOSI: 23
[EWS] MISO: 19
[EWS] SCK: 18
[EWS] SS: 5
[EWS] =========================
[EWS] ESP32 setCsPin: 22
_pinCS = 0
W5100 init, using SS_PIN_DEFAULT = 22, new ss_pin = 10, W5100Class::ss_pin = 22
W5100::init: W5500, SSIZE =8192
=========================
Currently Used SPI pinout:
MOSI:23
MISO:19
SCK:18
CS/SS:22
=========================
Using mac index = 11
Connected! IP address: 192.168.2.125
Using NTP Server 0.ca.pool.ntp.org
****WIFI Status****
WiFi Failed
******NOT UPDATED******
UTC : 00:00:13
UTC :  0: 0:13 Thu  1 Jan 1970
LOC : 02:28:29
LOC :  2:28:29 Sun  7 Feb 2106
UTC EPOCH : 13
LOC EPOCH : 4294952909
UTC : 0:0:13 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:13 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:29 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:29 Sun 7/2/2106 or 7 Feb 2106
****WIFI Status****
WiFi Failed
********UPDATED********       <=====  Updated using Ethernet UDP
UTC : 04:14:00
UTC :  4:14: 0 Thu 24 Feb 2022
LOC : 00:14:00
LOC :  0:14: 0 Thu 24 Feb 2022
UTC EPOCH : 1645676040
LOC EPOCH : 1645661640
UTC : 4:14:0 Thu 24/2/2022 or 24 Feb 2022
UTC : 04:14:00 Thu 24/2/2022 or 24 Feb 2022
LOC : 0:14:0 Thu 24/2/2022 or 24 Feb 2022
LOC : 00:14:00 Thu 24/2/2022 or 24 Feb 2022
****WIFI Status****
WiFi Failed
****WIFI Status****
WiFi Failed
****WIFI Status****
WiFi Failed
****WIFI Status****
WiFi Failed
****WIFI Status****
WiFi Failed
********UPDATED********
UTC : 04:15:00
UTC :  4:15: 0 Thu 24 Feb 2022
LOC : 00:15:00
LOC :  0:15: 0 Thu 24 Feb 2022
UTC EPOCH : 1645676100
LOC EPOCH : 1645661700
UTC : 4:15:0 Thu 24/2/2022 or 24 Feb 2022
UTC : 04:15:00 Thu 24/2/2022 or 24 Feb 2022
LOC : 0:15:0 Thu 24/2/2022 or 24 Feb 2022
LOC : 00:15:00 Thu 24/2/2022 or 24 Feb 2022
****WIFI Status****
WiFi OK
NTP => WiFi          <=====  Switch back to use WiFi UDP as WiFi is OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
********UPDATED********    <=====  Updated using WiFi UDP
UTC : 04:16:00
UTC :  4:16: 0 Thu 24 Feb 2022
LOC : 00:16:00
LOC :  0:16: 0 Thu 24 Feb 2022
UTC EPOCH : 1645676160
LOC EPOCH : 1645661760
UTC : 4:16:0 Thu 24/2/2022 or 24 Feb 2022
UTC : 04:16:00 Thu 24/2/2022 or 24 Feb 2022
LOC : 0:16:0 Thu 24/2/2022 or 24 Feb 2022
LOC : 00:16:00 Thu 24/2/2022 or 24 Feb 2022
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
********UPDATED********
UTC : 04:16:10
UTC :  4:16:10 Thu 24 Feb 2022
LOC : 00:16:10
LOC :  0:16:10 Thu 24 Feb 2022
UTC EPOCH : 1645676170
LOC EPOCH : 1645661770
UTC : 4:16:10 Thu 24/2/2022 or 24 Feb 2022
UTC : 04:16:10 Thu 24/2/2022 or 24 Feb 2022
LOC : 0:16:10 Thu 24/2/2022 or 24 Feb 2022
LOC : 00:16:10 Thu 24/2/2022 or 24 Feb 2022
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
********UPDATED********
UTC : 04:17:10
UTC :  4:17:10 Thu 24 Feb 2022
LOC : 00:17:10
LOC :  0:17:10 Thu 24 Feb 2022
UTC EPOCH : 1645676230
LOC EPOCH : 1645661830
UTC : 4:17:10 Thu 24/2/2022 or 24 Feb 2022
UTC : 04:17:10 Thu 24/2/2022 or 24 Feb 2022
LOC : 0:17:10 Thu 24/2/2022 or 24 Feb 2022
LOC : 00:17:10 Thu 24/2/2022 or 24 Feb 2022
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK
********UPDATED********
UTC : 04:18:10
UTC :  4:18:10 Thu 24 Feb 2022
LOC : 00:18:10
LOC :  0:18:10 Thu 24 Feb 2022
UTC EPOCH : 1645676290
LOC EPOCH : 1645661890
UTC : 4:18:10 Thu 24/2/2022 or 24 Feb 2022
UTC : 04:18:10 Thu 24/2/2022 or 24 Feb 2022
LOC : 0:18:10 Thu 24/2/2022 or 24 Feb 2022
LOC : 00:18:10 Thu 24/2/2022 or 24 Feb 2022
****WIFI Status****
WiFi OK
****WIFI Status****
WiFi OK


Debug

Debug is enabled by default on Serial. To disable, add at the beginning of sketch

/* Comment this out to disable prints and save space */
#define NTP_DBG_PORT                Serial

// Debug Level from 0 to 4
#define _NTP_LOGLEVEL_              0

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the board's core, dependent libraries or this library version.

Sometimes, the library will only work if you update the core to the newer or older version because some function compatibility.



Issues

Submit issues to: NTPClient_Generic issues



TO DO

  1. Bug Searching and Killing
  2. Add more examples

DONE

  1. Add support to Arduino SAMD21 (ZERO, MKR, NANO_33_IOT, etc.) and FlashStorage
  2. Add support to Adafruit SAMD21 (Itsy-Bitsy M0, Metro M0, Feather M0 Express, etc.) and FlashStorage.
  3. Add support to Adafruit SAMD51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, etc.) and FlashStorage.
  4. Add support to Adafruit nRF52 ( Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc. and LittleFS.
  5. Add support to SAM DUE.
  6. Add support to Ethernet W5x00, using either Ethernet, Ethernet2, or EthernetLarge library
  7. Add support to Ethernet ENC28J60, using UIPEthernet library
  8. Add support to Seeeduino SAMD21/SAMD51: LoRaWAN, Zero, Femto M0, XIAO M0, Wio GPS Board, Wio Terminal, Grove UI Wireless and FlashStorage.
  9. Add support to EthernetENC
    1. Add support to AVR Mega, UNO, Nano.
    2. Add support to Arduino Nano_RP2040_Connect using Arduino mbed OS for Nano boards.
    3. Add support to RP2040-based boards, such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Earle Philhower's arduino-pico core.
    4. Add support to RP2040-based boards, such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Arduino-mbed RP2040 core
    5. Add Version String and Table-of-Contents
    6. Add support to WT32_ETH01 boards using ESP32-based boards and LAN8720 Ethernet
    7. Add support to RTL8720DN, RTL8722DM, RTL8722CSM, etc. boards
    8. Add support to Add support to Potenta_H7 using Murata WiFi of Vision-Shield Ethernet
    9. Fix multiple-definitions linker error.
    10. Fix getUTCEpochMillis() bug
    11. Add setUDP() function to enable auto-switching between WiFi and Ethernet UDP instances.
    12. Add new examples ESP_WiFi_ETH_NTPClient_Advanced and WT32_WiFi_ETH01_NTPClient_Advanced to use the new setUDP() function for auto-switching between WiFi and Ethernet UDP to update NTP time.
    13. Use Ethernet_Generic library as default for W5x00 Ethernet.
    14. Support SPI2 for ESP32
    15. Add support to SPI1 for RP2040 using arduino-pico core
    16. Add example multiFileProject to demo how to avoid multiple-definitions linker error for multiple-file project
    17. Sync with NTPClient releases v3.2.1
    18. Fix bug causing time jumping back or forth when network has problem


Contributions and Thanks

Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.

  1. Based on and modified from the Fabrice Weinberg's NTPClient Library.
  2. Thanks to good work of Miguel Alexandre Wisintainer for initiating, inspriring, working with, developing, debugging and testing.
  3. Thanks to bmcdonnell to make PR in Add packet validity checks #4 leading to v3.3.0
  4. Thanks to DavidSteinmann to report the getUTCEpochMillis() bug and propose the bug fix in getUTCEpochMillis() not returning correct value #7 leading to v3.7.1
  5. Thanks to argo9 to make PR in added setUDP function #8 leading to v3.7.2
  6. Thanks to iBuilderBY to report the bug with steps to duplicate in Time jumping back when connection is lost and forward when up #9 leading to v3.7.5
FWeinb
⭐️ Fabrice Weinberg

tcpipchip
Miguel Wisintainer

bmcdonnell
bmcdonnell

DavidSteinmann
DavidSteinmann

argo9
argo9

iBuilderBY
iBuilderBY


Contributing

If you want to contribute to this project:


License


Copyright