#299 Tricks to get NTP time for the ESP32 and the ESP8266 incl. Summer- and Daylight Saving time

#299 Tricks to get NTP time for the ESP32 and the ESP8266 incl. Summer- and Daylight Saving time

Andreas Spiess

4 года назад

79,929 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Janis Kisis
Janis Kisis - 14.11.2023 18:27

Thank you! A lot of useful information. Some comments:
time() function, if the initial connection to NTP server is successful, provides the correct result even Internet is not accessible. In other words- looks like the GetTimeReducedTraffic() idea is implemented INSIDE this function and therefore GetTimeReducedTraffic function() is useless. Another conclusion- time() cannot be used as an indicator of Internet presence

Ответить
Diogo Martins
Diogo Martins - 26.10.2023 08:44

Does the time keep counting internally after synchronization? I tested this and it shows the time when the request to the ntp server was made and it keeps showing the same time, until new data is received form ntp server, basically only shows the time that the ntp server sends. If the network goes down, there is no more time update, meaning, the clock keeps showing the same value. I thought this would receive the time from ntp server and then keep counting the time internally and periodically sync the time with the ntp server, like a computer does.

Ответить
Vaping Asylum
Vaping Asylum - 11.09.2023 16:42

Has esp8266 in title. Doesnt work with esp8266.

Ответить
Badusha shaik
Badusha shaik - 08.07.2023 18:30

NTP=MAD TIME REALLY MAD,....IT SHOWS DIFFRENT TIME EACH TIME

Ответить
SarahKchannel
SarahKchannel - 16.06.2023 15:14

For your comments on the start of the week. Only the western modern world starts on monday. All the arabic world starts on sunday ! With a very significant part of world not being western, nor christian - normal becomes some what relative ! ;)

Ответить
FLIGHTC0NTR0L
FLIGHTC0NTR0L - 07.05.2023 18:49

Great video!!

But how do i make the antenna??

Ответить
Philippe Champouret
Philippe Champouret - 24.03.2023 07:37

Hello. Do you have a schematic for the antenna connection with the ESP32 please ?

Ответить
feynthefallen
feynthefallen - 20.03.2023 01:44

As I watch this, I'm refactoring the code produced by two days of manic hacking about half a year ago. It was written with beer also.

Ответить
Halacs
Halacs - 09.03.2023 20:03

Hi, can you help me out please with some info about the antenna? I see the link to the ferrite rod but the link is broken and I guess I need not just the rod but a few turns of copper too. Thanks in advance!

Ответить
jim
jim - 05.03.2023 21:25

It was both useful and interesting, as always! I did want to point out that up to 3 NTP time servers can be specified in the "configTime" function, separated by commas.

Ответить
Admin TMilgart
Admin TMilgart - 04.11.2022 16:01

Thanks for the video. One question.... why are you using time.h instead of TimeLab.h (which is Arduino's time module)

Ответить
user001 SG
user001 SG - 13.07.2022 13:27

Nice video, many thanks. May be I haven't understood the main reason for using NTP server with ESP32 for time. So please allow me to ask: Why you didn't choose to use DCF77 directly? You don't have to worry about summer and winter time correction or the number of time you send request to NTP. With DCF77 you always have the right date and time. Is the main reason for your selecting the NTPserver is the ease of adapting the NTP structure and available ESP32 functions in the sketch? Please comment. Thanks

Ответить
undercrackers56
undercrackers56 - 11.07.2022 12:54

Michael Graff is quite correct. Use UTC time across the system, this avoids data logging complications when local clocks go back an hour. Then adjust the time when presenting to users at the point of consumption. Thus the locale of the source device can usually be inferred by user context. (The user can say in which timezone the data should be presented for any given device.)

Ответить
Mark Bowhill
Mark Bowhill - 09.07.2022 17:01

Jajajajajajaja, the sketch on the aknik/ESP32 is not in spanish, that's english and italian language with just comments on Spanish. My language is spanish but... i recognize that Spanish and Italian sound similar to the ears of a non-Latin speaker jejeje. Greetings from Venezuela (I am Uruguayan) and thanks for the video!!!

int ArrayImpulsi[60];
int ContaImpulsiParziale = 0;
int Ore,Minuti,Secondi,Giorno,Mese,Anno,DayOfW;

thats is Italian jeje

Ответить
PKAE Electronics
PKAE Electronics - 19.06.2022 15:47

LOL "you never know with the British" :)

Ответить
S.E. Ong
S.E. Ong - 16.06.2022 11:20

How is the ferrite rod antenna connected to the ESP32? any circuitry required? I have one from a DCF77 receiver and it has a capacitor between the 2 wires, I read this is called a tuned antenna. Do I just connect the 2 wires to the ESP32? Thank you

Ответить
Mark Latimer
Mark Latimer - 25.05.2022 02:38

"You never know with the British", sorry Mate I think you confusing us with the French.

Ответить
Konstantin Grigoriadis
Konstantin Grigoriadis - 05.05.2022 02:29

Guten Abend Andreas, Interessantes Video, habe gerade Gefunden! Welche Distanz ist Überbrückbar mit den DCF Sender mit der Ferrit Antenne als Sendeantenne ? Grüße aus Wien

Ответить
Johan Roets
Johan Roets - 20.04.2022 14:02

Great video again. Just one remark. Update NTP is only with configtime function. getlocaltime_r() in getNTPtime example code does not update ntp in my test. Did 24h test with example code clock was 2min behind. Restart updated time correct again. So update is done only when configtime is run and you have wifi of course. found nice extra (esp32)configTzTime(TZ_INFO,NTP_SERVER,NTP_SERVER2,NTP_SERVER3);//this updates via ntp and posix is integrated.

Ответить
ReDaLeRt
ReDaLeRt - 24.02.2022 00:12

How can I built the antenna for this project?

Ответить
drTERRRORRR
drTERRRORRR - 23.12.2021 18:19

Microcontrollers and LSD! This is the best fucking channel ever!

Ответить
john vincent napa
john vincent napa - 17.12.2021 12:20

How to add decimal places for the seconds for much more accurate timestamping

Ответить
Pramuka Sooriyapatabandige
Pramuka Sooriyapatabandige - 03.10.2021 05:19

Great Video ! Thank You. Can I know whether it is possible to store time when the ESP32 goes to deep sleep and retrieve it without getting NTP time ?

Ответить
MISC BITS
MISC BITS - 26.07.2021 23:50

WARNING: You should only poll a NTP server every 64 seconds at most frequent, backing off to hourly once you're happy with local clock stability

Polling every second is classified as abuse and can get you filtered
You should also run a NTP server in your local network and sync everything inside to that instead of the pool servers

Ответить
อดิศร สาการินทร์
อดิศร สาการินทร์ - 03.06.2021 06:16

Can you please send me an email to contact you?

Ответить
Sarwo Edi
Sarwo Edi - 02.06.2021 06:20

you are my favourite teacher

Ответить
wjn777
wjn777 - 19.05.2021 20:53

Useful and interesting, great video on handling time on an ESP. Thanks for sharing

Ответить
Stefano Zamprogno
Stefano Zamprogno - 01.05.2021 20:08

which Time.h library have you used ?

Ответить
TCBperformance
TCBperformance - 13.03.2021 12:18

Hello I have a very good explanation regarding Sunday being Zero, as it was the Jesuits to change the time system of God. It is also them that are behind making Sunday a Zero. Because they also want for Sunday is a day of no work! Therefore it is logical for "their diabolic mind" to have it as a 'Zero'. The correct way is to have Sunday as 1 and the count should be 1 to 7 as God has put in place, which makes the 7th day the day of the Lord! They have been planning things for centuries, it is now they are coming to full light for people to discover the evil behind them!.......... if u are part of a SS, it is time to leave very soon! not accusing, but just in case. Kind Regards, joe

Ответить
ajm640
ajm640 - 06.03.2021 11:41

Andreas, no beer or drugs were involved with "struct tm". The ISO 8601 standard that establishes Monday as the first day of the week was first published in 1988 almost two decades after "struct tm" was defined. In the United States, where the code was written, Sunday is considered the first day of the week (again pre- ISO 8601). As you are aware, the C programming language uses zero-based arrays thus the tm_mon and tm_wday can be (are) used to index arrays for converting to character (string) representation as in strftime(). January and Sunday therefore have zero values in tm_mon and tm_wday respectively.

Ответить
Electronieks
Electronieks - 26.02.2021 00:45

hello the code works , but if i want to change the code with fixed ip address , then the ntp doesnt work anymore


this line breakes everything then
WiFi.config(ip, dns, gateway, subnet); (on esp32 wroom)

Ответить
Hua-Ming Huang
Hua-Ming Huang - 05.01.2021 03:13

Thanks for the helpful tutorial!
One question, how can I properly add milliseconds after the UNIX timestamp (i.e., the variable "now")?
Say 1537422385 -> 1537422385"321"

Now I have figure out how to obtain the milliseconds:
struct timeval tv;
gettimeofday(&tv, NULL);
int64_t milliseconds = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;

But don't have an idea how to derive the desired output.

I thank you very much in advance!!

Ответить
Leri Buiglishvili
Leri Buiglishvili - 31.12.2020 17:50

Got my first radio controlled watch. Got my esp32, now wondering can I use just wire as an antenna if I wrap it around my watch?

Ответить
WagonLoads
WagonLoads - 18.12.2020 23:32

Gotta question? Maybe someone out there done this. I just found out how to set the time on a DS1307 RTC(Real Time Clock) and it works, but I have issues with it.. To set the time using the example they give, requires perfect timing at the time of upload to get the RTC to the correct time. My best effort gets me 12 seconds from true time. I was thinking of trying to use NTP to sync the RTC to the NTP server, but that also requires adjusting for network delays..

I am shooting for 1 sec accuracy, because I don't know if 1uS is possible. I was thinking of using the millis() function to get offsets of both time sources, then use the difference of the offsets to adjust the RTC to true NTP time.

Has anyone else solved this problem. I want to try to get both time readings to match..

Ответить
zwicknagel
zwicknagel - 04.11.2020 18:24

Andreas, your script on wemos d1 mini don't work correct! I copied your sketch, changed only the credentials, but time is 8 hours in the future! I'm from munich and have the same timezone as you! any suggestions?

Ответить
doggo
doggo - 06.08.2020 03:18

Thank

Ответить
Abdulaziz El-Feky
Abdulaziz El-Feky - 05.05.2020 12:57

Thank you , it's very helpful

Ответить
epedja
epedja - 17.03.2020 17:27

You mentioned video with actual build of transmitter but I cannot find link to it. Can you post a link?

Ответить
Matthias Mueller
Matthias Mueller - 03.02.2020 16:27

I got my own in Iceland running now! \o/
Finding and sorting out the hardware problems took some effort without an oscilloscope and the resistor values are different, when your coil has 198millihenry... ;)

Ответить
S Shah
S Shah - 23.12.2019 13:42

What modification is needed for WWVB.

Ответить
Tom Freier
Tom Freier - 20.12.2019 22:03

Great Video as always Andreas. Is there any documentation for esp commands "configTime" and time()?

Ответить
Jim Watt
Jim Watt - 29.11.2019 00:43

Don't worry about the British inventing a new time zone. Think what the initials in GMT mean, and why longitude 0 is at the Greenwich observatory. Hint: GMT is based on astronomical time which is not as accurate as atomic clocks which is why its replaced with UTC.

Ответить
resnbl1
resnbl1 - 28.11.2019 22:14

I just went through the same exercise for an ESP8266 project, and eventually came up with pretty much the same solution as presented here, but with one minor difference: after the setenv(...) call, the examples I referenced included a call to tzset(). I'm not sure what this does, or if it is needed, but it hasn't hurt my code...

Ответить