Page 1 of 1

Getting NTP localtime without config?

Posted: Tue Jul 16, 2024 5:03 pm
by rin67630
Hi, do we have a way to get NTP localtime without a manual configuration?
I mean with the callling IP, a geolocation can be done and out of that the time zone parameters TZ and DST_MN automatically derived, isn't it?

Re: Getting NTP localtime without config?

Posted: Tue Jul 16, 2024 5:48 pm
by lbernstone
Geolocation is a service provided by a 3rd party. Those services are generally not free (as in the GPL definition of free). They are free (as in beer), from many sites after a registration. Here's an example

My preference nowadays is to get the timezone and utc from a web client through a hidden element in a form. It's been on my list to make a demo of that. I'll post an example here when I extract that from a larger project (and convert it to arduino).

Re: Getting NTP localtime without config?

Posted: Tue Jul 16, 2024 7:55 pm
by rin67630
lbernstone wrote:
Tue Jul 16, 2024 5:48 pm
Geolocation is a service provided by a 3rd party. Those services are generally not free (as in the GPL definition of free). They are free (as in beer), from many sites after a registration. Here's an example

My preference nowadays is to get the timezone and utc from a web client through a hidden element in a form. It's been on my list to make a demo of that. I'll post an example here when I extract that from a larger project (and convert it to arduino).
Thank you!
That's a lot of stuff to just derive one's TZ and DST_MN.

In fact, I can get from another site my current timezone in a verbose form. e.g.: "Europe/Berlin".
Is it easier to get TZ and DST_MN from that?
Or have we got a way to call NTP with this info instead of TZ and DST_MN?

Regards
Laszlo

Re: Getting NTP localtime without config?

Posted: Thu Jul 18, 2024 3:30 am
by lbernstone

Re: Getting NTP localtime without config?

Posted: Thu Jul 18, 2024 3:55 am
by lbernstone
NTP uses UTC time. Always. Period.
The timezone can be set manually by calling

Code: Select all

    char tz[] = "HST10";
    setenv("TZ", tz, 1);
    tzset();
The strings that are recognized are compiled in the crossNG toolchain. I am pretty certain that all the ST/DT strings in my zones file are recognized. The city name strings may or may not be.

Re: Getting NTP localtime without config?

Posted: Fri Jul 19, 2024 11:28 am
by rin67630
lbernstone wrote:
Thu Jul 18, 2024 3:55 am
NTP uses UTC time. Always. Period.
Sure. We are speaking about about the ESP library, which needs TZ and DST values to get the local time.

Re: Getting NTP localtime without config?

Posted: Fri Jul 19, 2024 11:03 pm
by lbernstone
simpson_robot_never_worked.gif
simpson_robot_never_worked.gif (1.16 MiB) Viewed 1855 times

Re: Getting NTP localtime without config?

Posted: Sun Jul 21, 2024 4:53 pm
by rin67630
lbernstone wrote:
Fri Jul 19, 2024 11:03 pm
simpson_robot_never_worked.gif
Very intelligent post...