ropg / ezTime

ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
MIT License
327 stars 92 forks source link

How can I use my local NTP Server with Internet connection? #67

Closed x0tester0x closed 4 years ago

x0tester0x commented 4 years ago

I have a local NTP Server with Internet connection on my Network. The ESP8266, without Internet connection, is also on the same Network. How can the ESP8266 get the right Timezone from the local NTP Server?

ropg commented 4 years ago

I have a local NTP Server with Internet connection in my Network, The ESP8266, without Internet connection, is on the same Network. How can the ESP8266 get the right Timezone from the local NTP Server?

The timezone information does not come from the NTP server but from my own server (timezoned.rop.nl)

It's probably best if you find your timezone's POSIX information (the information that says what the timezone is called, what the offset to UTC is, and when the Daylight Savigs time starts and stops) and then use this information to set the timezone. If you say what timezone you are in I can give you the string.

x0tester0x commented 4 years ago

I'm in UTC+1. So I just have to set the Timezone, what I will get from you, and then I should get the right Time always from my own NTP Server?

ropg commented 4 years ago

I'm in UTC+1. So I just have to set the Timezone what I will get from you and then I should get the right time always from my own NTP Server?

It's best if you set the timezone such that the daylight savings time begins and ends at the right moment and all that. So where are you, geographically speaking?

x0tester0x commented 4 years ago

I'm in Italy.

ropg commented 4 years ago

In that case, try something like:

Timezone Italy;
Italy.setPosix("CET-1CEST,M3.5.0,M10.5.0/3");
Serial.println(Italy.dateTime());

This way your timezone has the correct name (CET or CEST) and switches to DST at the right date (last Sundays of March and October). Remember to change this if and when DST is abolished in a few years though...

x0tester0x commented 4 years ago

But how can I retirieve then the Time from my local NTP Server after I set the Timezone?

ropg commented 4 years ago

https://github.com/ropg/ezTime#setserver-and-setinterval

void setServer(String ntp_server = NTP_SERVER);

void setInterval(uint16_t seconds = 0);

By default, ezTime is set to poll pool.ntp.org about every 30 minutes. These defaults should work for most people, but you can change them by specifying a new server with setServer or a new interval (in seconds) with setInterval. If you call setInterval with an interval of 0 seconds or call it as setInterval(), no more NTP queries will be made.