17 #ifndef _SMING_CORE_NETWORK_NTP_CLIENT_H_ 18 #define _SMING_CORE_NETWORK_NTP_CLIENT_H_ 20 #include "UdpConnection.h" 21 #include "Platform/System.h" 27 #define NTP_PACKET_SIZE 48 29 #define NTP_MODE_CLIENT 3 30 #define NTP_MODE_SERVER 4 32 #define NTP_DEFAULT_SERVER F("pool.ntp.org") 33 #define NTP_DEFAULT_AUTOQUERY_SECONDS 30U // (10U * SECS_PER_MIN) 34 #define NTP_MIN_AUTOQUERY_SECONDS 10U 35 #define NTP_CONNECTION_TIMEOUT_MS 1666U 36 #define NTP_RESPONSE_TIMEOUT_MS 20000U 57 :
NtpClient(NTP_DEFAULT_SERVER, NTP_DEFAULT_AUTOQUERY_SECONDS, onTimeReceivedCb)
117 debug_d(
"NtpClient::startTimer(%u)", milliseconds);
124 debug_d(
"NtpClient::stopTimer()");
133 bool autoQueryEnabled =
false;
134 unsigned autoQuerySeconds = NTP_DEFAULT_AUTOQUERY_SECONDS;
void setAutoUpdateSystemClock(bool autoUpdateClock)
Enable / disable update of system clock.
Definition: NtpClient.h:94
Definition: UdpConnection.h:29
NtpClient(NtpTimeResultDelegate onTimeReceivedCb)
Instantiates NTP client object.
Definition: NtpClient.h:56
String server
IP address or Hostname of NTP server.
Definition: NtpClient.h:129
void setNtpServer(const String &server)
Set the NTP server.
Definition: NtpClient.h:76
NtpClient()
Instantiates NTP client object.
Definition: NtpClient.h:49
The string class.
Definition: WString.h:104
void onReceive(pbuf *buf, IPAddress remoteIP, uint16_t remotePort) override
Handle UDP message reception.
void setAutoQuery(bool autoQuery)
Enable / disable periodic query.
void internalRequestTime(IPAddress serverIp)
Send time request to NTP server.
void setAutoQueryInterval(unsigned seconds)
Set query period.
__forceinline void IRAM_ATTR startOnce()
Start one-shot timer running.
Definition: Timer.h:99
bool autoUpdateSystemClock
True to update system clock with NTP time.
Definition: NtpClient.h:132
Timer timer
Deals with timeouts, retries and autoquery updates.
Definition: NtpClient.h:135
NTP client class.
Definition: NtpClient.h:44
void IRAM_ATTR stop()
Stop timer.
void IRAM_ATTR setIntervalMs(uint32_t milliseconds=1000000)
Set timer interval.
Definition: IPAddress.h:37
void requestTime()
Request time from NTP server.
void startTimer(uint32_t milliseconds)
Start the timer running.
Definition: NtpClient.h:115
NtpTimeResultDelegate delegateCompleted
NTP result handler delegate.
Definition: NtpClient.h:131