A modern, non-blocking, lightweight, NTP client library for Arduino and ESP32-based boards, with support for Kiss-o'-Death (KoD) reporting.
- Fully non-blocking time updates
- Handles NTP KoD (Kissβo'-Death) codes
- Supports both domain and IP-based server configuration
- Configurable poll intervals, response timeouts, and retry delays
- Minimal resource usage
- I won't provoke an NTP server to test KoD reporting, but Anthropic Claude Sonnet 4 checked and confirmed that it will work.
- Download the latest release.
- Unzip into your Arduino
libraries/
folder. - Restart the Arduino IDE.
- update() MUST be in loop().
Or install directly via Arduino Library Manager (when published).
#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTP2.h>
WiFiUDP udp;
NTP2 ntp(udp);
void setup() {
Serial.begin(115200);
WiFi.begin("SSID", "password");
while (WiFi.status() != WL_CONNECTED) delay(1000);
ntp.begin(); // Uses default pool.ntp.org server
}
void loop() {
NTPStatus status = ntp.update();
if (status == NTP_CONNECTED) {
Serial.println(ntp.epoch());
}
delay(1000);
}
Check the examples/NTP2_Basic
sketch for full usage.
NTP_CONNECTED
β Valid response receivedNTP_IDLE
β Waiting or processingNTP_BAD_PACKET
β Invalid or no responseNTP_KOD_*
β Kiss-o'-Death response (rate-limiting, denial, etc.)
ntp.updateInterval(ms); // Set poll interval
ntp.responseDelay(ms); // Time to wait before reading response
ntp.retryDelay(ms); // Retry delay after failure or KoD
ntp.forceUpdate(); // Force an immediate query
Mitch Feig
π§ [email protected]
MIT License. See LICENSE
file for details.