Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::SimpleNTP Class Reference

#include <SimpleNTP.h>

Public Types

typedef void(* SyncTimeCallback) (time_t epoch)
 Callback function type for time synchronization events.
 

Public Member Functions

 SimpleNTP ()
 Default constructor.
 
void setSyncTimeCallback (SyncTimeCallback callback)
 Sets the callback function for time synchronization events.
 
time_t getNtpTime ()
 Requests and retrieves current time from NTP server.
 

Static Public Attributes

static constexpr const char * servers [] = {"time.google.com", "time.nist.gov", "pool.ntp.org"}
 Array of NTP server hostnames to try connecting to.
 

Member Typedef Documentation

◆ SyncTimeCallback

typedef void(* uniot::SimpleNTP::SyncTimeCallback) (time_t epoch)

Callback function type for time synchronization events.

This callback is triggered when time is successfully synchronized with an NTP server.

Parameters
epochThe current time as Unix timestamp (seconds since Jan 1, 1970)

Constructor & Destructor Documentation

◆ SimpleNTP()

uniot::SimpleNTP::SimpleNTP ( )
inline

Default constructor.

Initializes a SimpleNTP instance with no callback

Member Function Documentation

◆ getNtpTime()

time_t uniot::SimpleNTP::getNtpTime ( )
inline

Requests and retrieves current time from NTP server.

Connects to a randomly selected NTP server, sends a request packet, waits for and processes the response to extract the current time.

Return values
time_tCurrent time in seconds since Jan 1, 1970
0if time synchronization failed

◆ setSyncTimeCallback()

void uniot::SimpleNTP::setSyncTimeCallback ( SyncTimeCallback callback)
inline

Sets the callback function for time synchronization events.

Parameters
callbackFunction to be called when time is successfully synchronized

Member Data Documentation

◆ servers

const char* uniot::SimpleNTP::servers[] = {"time.google.com", "time.nist.gov", "pool.ntp.org"}
staticconstexpr

Array of NTP server hostnames to try connecting to.

One server is randomly selected during each sync attempt


The documentation for this class was generated from the following file: