6 #ifndef ACE_TIME_NTP_CLOCK_H
7 #define ACE_TIME_NTP_CLOCK_H
9 #if defined(ESP8266) || defined(ESP32) || defined(EPOXY_CORE_ESP8266)
12 #if defined(ESP8266) || defined(EPOXY_CORE_ESP8266)
13 #include <ESP8266WiFi.h>
20 #ifndef ACE_TIME_NTP_CLOCK_DEBUG
21 #define ACE_TIME_NTP_CLOCK_DEBUG 0
96 mLocalPort(localPort),
97 mRequestTimeout(requestTimeout) {}
110 const char* ssid =
nullptr,
111 const char* password =
nullptr,
120 acetime_t
getNow()
const override;
147 static const uint8_t kNtpPacketSize = 48;
153 static const int32_t kDaysToInternalEpochFromNtpEpoch = 36524;
156 void sendNtpPacket(
const IPAddress& address)
const;
159 const char*
const mServer;
160 uint16_t
const mLocalPort;
161 uint16_t
const mRequestTimeout;
163 mutable WiFiUDP mUdp;
165 mutable uint8_t mPacketBuffer[kNtpPacketSize];
166 bool mIsSetUp =
false;
Abstract base class for objects that provide and store time.
A Clock that retrieves the time from an NTP server.
const char * getServer() const
Return the name of the NTP server.
static acetime_t convertNtpSecondsToAceTimeSeconds(uint32_t ntpSeconds)
Convert an NTP seconds to AceTime seconds relative to the current AceTime epoch defined by Epoch::cur...
acetime_t readResponse() const override
Returns number of seconds since AceTime epoch (2000-01-01).
void setup(const char *ssid=nullptr, const char *password=nullptr, uint16_t connectTimeoutMillis=kConnectTimeoutMillis)
Set up the WiFi connection using the given ssid and password, and prepare the UDP connection.
static const uint16_t kLocalPort
Default port used for UDP packets.
static const char kNtpServerName[]
Default NTP Server.
static const uint16_t kConnectTimeoutMillis
Number of millis to wait during connect before timing out.
static const uint16_t kRequestTimeoutMillis
Request time out milliseconds.
NtpClock(const char *server=kNtpServerName, uint16_t localPort=kLocalPort, uint16_t requestTimeout=kRequestTimeoutMillis)
Constructor.
bool isResponseReady() const override
Return true if a response is ready.
bool isSetup() const
Return true if setup() suceeded.
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
void sendRequest() const override
Send a time request asynchronously.
static const uint16_t kRequestTimeout
Deprecated.