Skip to content

NTP Service

suraj inamdar edited this page May 5, 2020 · 2 revisions

NTP Service

If your ESP8266 project has access to the Internet, you can get date and time (with a precision within a few milliseconds of UTC) for FREE. You don’t need any additional hardware.

NTP sets the clocks of computers to UTC, any local time zone offset or day light saving time offset is applied by the client.

This service internally uses SNTP apis to config and get time

Default ntp server

/**
 * NTP servers
 */
#define NTP_SERVER1     "pool.ntp.org"

Set timezone ( default to utc+5:30 )

If you are using this service be sure to make timezone changes according to your timezone

#define TZ              5.5       // (utc + TZ in hours)
#define TZ_MN           ((TZ)*60)
#define TZ_SEC          ((TZ)*3600)
#define DST_MN          0      // use 60 for summer time in some countries
#define DST_SEC         ((DST_MN)*60)

Service members

// Confiure with timezone and ntp server
void init_ntp_time( void );
// check whether time is in synce
bool is_ntp_in_sync( void );
// get time
time_t get_ntp_time( void );
Clone this wiki locally