Just for the record, you would NOT WANT the time servers to implement daylight savings time or other features. It is totally correct to have a global UTC time network, and then for local presentation do the work to implement time zones and daylight savings. It is not a weakness that NTP only uses UTC, it is a feature.
@sstorholm5 жыл бұрын
And no leap second smearing either :)
@AndreasSpiess5 жыл бұрын
I would have liked a function call in addition to GMT where you can get local time...
@highkicker115 жыл бұрын
@@AndreasSpiess it becomes useless the moment you want more then a signal to set the clock its just to make all the clocks on the WAN all beat at the same time. if you have to add more calculation to it to get the local time or even daylight savings from the server you add milliseconds to the sync pulse thus you create a desync. the whole reasons to have a distributed network of ntp server pools is that you have a server with the lowest latency. if for instance you would only have a ntp server in Hawaii and the whole world would have to sync with it. the pure latency on the other side of the world would trow the whole network off.
@LeifNelandDk5 жыл бұрын
@@AndreasSpiess If you have mqtt in your project, then fetch the timezone string from there. Or use one of the "private use" options in DHCP, option number 224-254
@jtauscher5 жыл бұрын
@@var67 IP ?
@chrispaul78904 жыл бұрын
Andreas, your videos are AWESOME! I'm an electronics / home automation hobbyist and you have already solved many challenges I have run into. You are my favorite KZbin publisher hands down. Thank You!
@AndreasSpiess4 жыл бұрын
Thank you! I am glad you like my channel.
@HelmutTschemernjak5 жыл бұрын
I figured out that there are also problems with the configTime() function. It works asynchronously and gets the NTP time, however: - During the period it gets the time it sets the ESP32 time to zero! - You don’t know when it is finished. - Existing app variables e.g. service startup time must be adjusted to have proper time statistics after time changes. I did the following to overcome this. I save the current UTC time and count in parallel seconds while calling configTime(). After two seconds I verify if the time() changed by more than 3 seconds, if yes the new NTP time has been set, otherwise I restore the clock to the value before calling configTime() plus the seconds since then. Existing variables of my app like startup time of my services, etc. I adjust. Thank you for the great videos, now I understand even more of the the TZ magic string. Regards from Hannover, Germany.
@AndreasSpiess5 жыл бұрын
I try to check the year to find out when the NTP time arrived. Concerning the time() function: A Patreon with an own NTP server found out that the ESP only calls the NTP server every hour. In between it keeps the time with the internal counter. So you might not compare real NTP time if you call time(). But otherwise it is a good idea to compare two different sources to find "the truth"
@HelmutTschemernjak5 жыл бұрын
@@AndreasSpiess I am using a separate ESP32 64.bit to track the time independent of the time() function, for this case. My software updates the time once a week via NTP, I did not know that the ESP32 is doing it automatically. I will investigate into it further.
@dougmanatt43175 жыл бұрын
It is wonderful how you dig into things that I find useful, do all the work of finding out the details and then present it all nicely wrapped up so I can use it almost without any hard thinking! Thanks!
@AndreasSpiess5 жыл бұрын
That is my part of the deal. You did your part in writing this comment. Thank you very much!
@sstorholm5 жыл бұрын
A quick note from a NTP pool server operator. You do not want to excessively poll public NTP servers. Most implement some sort of blacklisting if a client constantly demands time from them. Ideally, you should ask for time quite often in the beginning to sync your own local clock, and then back off as your confidence in your local clock increases. If you look at the “ntpq -p” commands output on a Linux box running NTP, you’ll see this behavior quite clearly. As time goes on, the time to the next query increases. The reason we’re so stingy with bandwidth is that when you’re already giving away time for free, we’d like to give it away to as many people as possible. Also, good work that you implemented the DNS-name for the pool instead of just the IP of some random server, that’s very important since the amount of available servers can vary very much, here in Finland for example we have something between 17 and 50 NTP servers in the pool at any time...
@AndreasSpiess5 жыл бұрын
Thank you for the info. We have indications that the function time() only calls the NTP server once an hour. Could you check and confirm that with your knowledge? Then we would not need any manual throttling.
@NiHaoMike645 жыл бұрын
Has the number of requests per hour increased steeply thanks to IoT devices?
@sstorholm5 жыл бұрын
@@AndreasSpiess I'm not close to a computer with the Arduino IDE installed, and the time.h library seems to be very hard to find online for some reason. However, every reference I can find seems to have a parameter in the library that sets the update timer, usually between 1 and 5 minutes. A normal NTP client (without ibrust och burst set) will start off trying to poll the server every 64 seconds, and will slowly increase this interval as it gets more into sync, eventually maxing out at 1024 seconds. So any device that has a polling interval of more than 500-ish seconds is in my point of view "in compliance" with the not so clearly stated NTP Pool guidelines. Setting the polling interval to 3600 seconds should be more than enough for any device that need only 100 ms precision, as NTP is designed to give precision in the millisecond resolution with a polling interval of 1024. If you need better then that, there's always PTP. :)
@sstorholm5 жыл бұрын
@@NiHaoMike64 It's rather hard, as the pool load balances all traffic to the pool servers depending on physical location of the client, as well as a factor that you set for your server. So mine see around 70 kbps constantly, but I'm in a quite "low server population" area, with a rather high "client population". The better IoT vendors usually follow the NTP pool guidelines and request a separate "vendor name" in the pool, and send all their clients there, so that they can direct their clients better towards pool servers provided by them. But IoT has definitely had quite a large impact, since there's always from time to time some vendor that gets raked over the coals for polling time every second from the general pool. :)
@klassichd105 жыл бұрын
Thanks for the insights in time handling. I made good experience using the ntp Server in my router instead of creating Internet traffic and CO2 emissions. All of my ESPs and most other devices have the same time reference - my router. Best sync, and avoiding traffic.
@AndreasSpiess5 жыл бұрын
Good idea. The Adaption to local time might still be necessary.
@klassichd105 жыл бұрын
@@AndreasSpiess Yes indeed, it is. The router does not make any conversion. My IP list contains > 60 Units. So using router (Fritzbox) as NTP server helps a lot avoiding traffic.
@LeifNelandDk5 жыл бұрын
@@klassichd10 yes, it is not considered "polite" to have all the clients on a network poll a remote NTP-server. You are, as you do, supposed to query the local timeserver. I wonder how many systems honour the NTP-server option from DHCP, but it should be fairly easy to implement in standard routers.
@tin20015 жыл бұрын
@@LeifNelandDk Windows didn't in the past... Would just use NIST or whatever the other default was regardless. I ended up setting up a firewall redirect on my home LAN, and a fake DNS entry for time.nist.gov at work. In both instances, they pointed to the local NTP server.
@christopherguy12175 жыл бұрын
The tm time structure came from UNIX which was from Bell Labs. The months and weekday values start at zero to facilitate retrieval of the names which are stored in string arrays and arrays in C are always 0 based for the index. In this way you can use these values directly as the index to the arrays of the months or weekdays without any additional work.
@AndreasSpiess5 жыл бұрын
Good to know. Thank you!
@kallewirsch22635 жыл бұрын
Also Doing arithmetic is much simpler E.g. You start with a Tuesday, which has code 2 13 days later .... what weekday is it? simple: ( 2 + 13 ) % 7 = 15 % 7 = 1 So it is a Monday, since Monday has code 1 In fact it is most of the time quite the opposite. The real question should be: Why the heck do you insist on 1 based indices? They just make life more complicated.
@AndreasDelleske4 жыл бұрын
Yep and IF they had started with 1, some idiot (tm) would try to set it to 0.
@MegaBarmaglot5 жыл бұрын
Btw, "LSD was first synthesized on November 16, 1938 by Swiss chemist Albert Hofmann at the Sandoz Laboratories in Basel, Switzerland".
@dd03565 жыл бұрын
another guy with the swiss accent changed the world, without youtube.
@AndreasSpiess5 жыл бұрын
Of course I know that. I once worked for Sandoz. It is located 20km from here. But I cannot always mention that a Swiss invented it ;-)
@klassichd105 жыл бұрын
@@AndreasSpiess apropos Sandoz: some years (or decades) ago, a read the books of Roland E. Best, who was with Sondoz These days. Very fine and helpful books! Was he a colleague of you?
@miscbits63993 жыл бұрын
VMS uses an epoch starting on 00:00:00 of November 17, 1858 (base date of the U.S. Naval Observatory's ephemerides) Some OSes use - Modified Julian Day zero - May 23, 1968 as epoch start Macs start in 1904 Windows NT and COBOL uses 1 January 1601 - (the first year of the 400-year Gregorian calendar cycle) whilst some other systems use 5 October 1582 - the actual date of the transition from Julian to Gregorian calendars "Standards are wonderful, there are so many to choose from"
@AndreasSpiess3 жыл бұрын
Thank you for this interesting info. I did not know that there are several such standards! Now I know I have to be cautious.
@FuchsHorst5 жыл бұрын
I'm a simple man, I run everything on UTC, then adjusting offsets when aggregating or displaying datetimes
@AndreasSpiess5 жыл бұрын
Nothing different here, I think. Just already written by somebody else and ready to use...
@AndersJackson5 жыл бұрын
That is how you actually use time and date calculation properly. Java has JUST start getting time and date calculation right. And one can't call Java a young language...
@jim5148 Жыл бұрын
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.
@AndreasSpiess Жыл бұрын
Good to know. Thank you!
@asiw5 жыл бұрын
As usual, an excellent contribution to the maker world. Perfect level of detail and information. I had given up with NTP time servers and just poll my local Raspberry Pi as this seem to deal with the daylight saving issues.
@AndreasSpiess5 жыл бұрын
How do you poll it from the Raspberry?
@davefiddes5 жыл бұрын
Good video on an important topic. Glad you fixed the example on Github. It's OK to call time() as often as you like the SNTP library used by the ESP Arduino core only calls it once an hour. Another thing that is useful to know is that if you have a well configured router that issues NTP servers in its DHCP and/or DHCPv6 responses your time server will be automatically configured. This will override any in your sketch unless you take steps to turn this behaviour off (a bad idea normally).
@AndreasSpiess5 жыл бұрын
Thank you for the info. I assume it still is I’m GMT and you still need the time zone adjustment?
@davefiddes5 жыл бұрын
@@AndreasSpiess Yep. The SNTP client functions exactly the same. You need to call configTime() to specify the local timezone and DST offset and enable the SNTP client. You can continue to specify servers here too but they will be overridden by whatever is in the DHCP response. I find this very helpful in reducing the configuration information that needs to be set up and stored on each device.
@TheJanisK Жыл бұрын
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
@AndreasSpiess Жыл бұрын
You are right, time() runs off the internal clock if not connected to the internet. However, this is not very precise (for a Swiss ;-) )
@laverdanick5 жыл бұрын
Thank you for making another interesting and informative video Andreas. Computer time is a complex subject. I am often working nights over the clock change and it is always a concern whether any new system among the several thousand servers we have will throw up errors. At least this year we are spared the leap second addition. Mind you it is always depressing to watch the clock roll back and realise you have to work that hour all over again.
@AndreasSpiess5 жыл бұрын
There is still hope that we will stop this nonsense ;-)
@owengill105Ай бұрын
Thanks for sharing your great work with the community.
@AndreasSpiessАй бұрын
You are welcome!
@SheeplessNW65 жыл бұрын
As far as I recall, struct tm was present in Bell Labs 7th edition Unix, so it came from New Jersey, not California. There were possibly still hippies involved, though.
@AndreasSpiess5 жыл бұрын
I knew a few of my viewers have more details. Let’s wait till the Californians comment...
@dougmanatt43175 жыл бұрын
From California -- I cannot chime in on whether the origin was California or New Jersey, but I can say that in might have been a botanical rather than LSD regardless of the location of origin
@AndrewBeals5 жыл бұрын
Surely you've seen Dennis Ritchie's beard.
@undercrackers562 жыл бұрын
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.)
@AndreasSpiess2 жыл бұрын
I think (hope) this is standard in all applications where you expect this issue. I remember the time where this created headaches...
@travishayes66785 жыл бұрын
tm_mon and tm_wday conveniently begin at 0 for efficiently indexing into an array of strings to get the printable name. tm_mday starts at 1 because it isn't generally used as an array index.
@AndreasSpiess5 жыл бұрын
Aha. Thank you for the explanation.
@emhowl5 жыл бұрын
I am ashamed, as a 61 year old physicist, to say I'd never heard of Unix time. Thank you for opening my eyes.
@AndreasSpiess5 жыл бұрын
We have a similar age and I also did not know it until recently ;-)
@nashaut76355 жыл бұрын
It is worth noting that any machine in any network can act as an NTP service - type "man ntp.conf" on a *NIX machine. This is even the recommended way of setting a time reference for any local "organization" to avoid stressing the internet time servers... as well as the querying IP address being banned/blocked :-D. So any machine with a low enough stratum number can be setup as an NTP server, which can be synchronized with internet time servers using NTP... or using a mere GPS when no internet connection is available.
@AndreasSpiess5 жыл бұрын
Thank you for the comment. I did not know that fact.
@nashaut76355 жыл бұрын
@@AndreasSpiess It's my pleasure :-).
@_mumbler_5 жыл бұрын
Perfect. I created a solution for my projects but this is much cleaner and simpler.
@AndreasSpiess5 жыл бұрын
:-)
@scharkalvin5 жыл бұрын
TimeT has already been converted to 64 bit in some unix libraries. So 2038 won't be the end of time, at least not for systems running on 64 bit processors.
@AndreasSpiess5 жыл бұрын
Good to know. Thanks!
@Davvg5 жыл бұрын
Y292277026.596K
@MalagasOnFire5 жыл бұрын
Good introduction on the timezone implementation for the ESP and NTP server. Now the fun part... Lucy in the Skyyyy with Diamonds :P Half of the structure POSIX starts from number 1 and the other starts from 0, maybe some was with LSD and the other with magic mushrooms. UTC grants timming for all purposes and host needs to implement DST in its SW: It can be done using automatic using Wi-Fi, GPRS , GNSS ... to acquire the timezone or input manually in the region settings, and if has timezones incorporated.
@mrtom645 жыл бұрын
I now get my time/date from the 'date' section of a web-page header. The advantages are that it is just a simple call to any web page, so no restrictions on how often you call it, (its just a web page). DST is already calculated for you, (the timezone + offset is written at the end) and it's a lot less code! (No extra time libraries required!) Parsing the info from a single 'date' string is pretty simple to do and gives you everything you need....and if you use a well-known search engine for the header info then you also have the advantage of 'leap smearing'....they use their own public NTP server. (I was under the impression this is also a Stratum 1 server but I'm struggling to find that info now.) I adjusted the code from the link below to give me just the 'date' info: techtutorialsx.com/2018/06/08/esp8266-arduino-getting-http-response-headers/
@AndreasSpiess5 жыл бұрын
Interesting idea... Thank you.
@wjn7773 жыл бұрын
Useful and interesting, great video on handling time on an ESP. Thanks for sharing
@AndreasSpiess3 жыл бұрын
Glad you enjoyed it!
@resnbl14 жыл бұрын
BTW: most time zone strings are defined by "#include ", at least in the ESP8266 libraries (I have not looked into ESP32's yet).
@AndreasSpiess4 жыл бұрын
Thank you for the tip!
@accdiabolus7 ай бұрын
Watching it during unix 1,714,253,105. Never gets old.
@AndreasSpiess7 ай бұрын
???
@accdiabolus7 ай бұрын
2:34 tempus fugit
@vidaroni5 жыл бұрын
Don't underestimate the power of a having a "system/localtime" MQTT topic for the devices to subscribe to. :)
@AndreasSpiess5 жыл бұрын
Good idea!
@ScruffR705 жыл бұрын
4:51 - actually we are 1 or 2 hours ahead of UTC. These numbers mean UTC is 1 or 2 hours behind local time. In a UTC time string CET & CEST are denoted by the Thh:mm:ss.ms+1:00 and Thh:mm:ss.ms+2:00 time suffix.
@AndreasSpiess5 жыл бұрын
Thank you for clarification.
@dogastus5 жыл бұрын
Thanks for a very informative (as usual!) video. I made a clock a while ago which ran off NTP but couldn't work out how to easily make it automatically change in response to DST so I cheated and added a switch! I'll have to revisit my code now.
@AndreasSpiess5 жыл бұрын
Should be simple. But never change a running SW ;-)
@dogastus5 жыл бұрын
@@AndreasSpiess That's wise thoughts from a wise man :-)
@Markus-idea5 жыл бұрын
Another trick to get the NTP time into the IoT devices is to use the main router as the NTP server within your local network. For example Fritzbox can do that. What are the advantages to do so? - security: the devices don't need to have full internet access (like in my case I have all my smarthome devices blocked from accessing the internet) but they can still get the acurate time all the time and immediately from the router directly - availability: assuming that the router always has the latest acurate timing received from a public NTP server it can provide that time always to any of the connected devices without needing all of them run public NTP requests at all - proper synchronization of all smarthome devices: if the router would have the wrong time, then ALL connected devices work with the same time and don't run asynchronously The Fritzbox allows a setting for how often it should run the public NTP request => no danger for any connected devices to overshoot the request limits and getting blacklisted. It works very well with whatever kind of device in my case. ESP8266, ESP32, Raspberry, Android, Linux, Windows. Even Tasmota runs perfectly with this method. It is amazingly simple. In the Fritzbox you define the public NTP server plus the frequency for updating from it. And you activate the function of Fritzbox becoming the local network NTP server by symply clicking the related checkbox. The local NTP address is (with Fritzbox routers): fritz.box That is the name for the NTP server you must enter in the NTP settings of each device. As simple as that. No further hassle with any additional settings. Whenever a smarthome device boots up and connects with the router, it will immediately receive the correct time right away - even without being connected to the internet. Works all fine for me (I am a bit paranoid when it comes to internet security)
@AndreasSpiess5 жыл бұрын
Thank you for the tip!
@stefanmarinescu50865 жыл бұрын
Fabulous!!! Just recently we had switched to winter Time and my Code did not know how to adjust itself.... Embaresement in front of wife :) now you saved me :)
@AndreasSpiess5 жыл бұрын
So you are her hero from now on ;-) In this case you do not need to mention the source of your knowledge...
@WacKEDmaN5 жыл бұрын
thanks Andreas, ive been using NTP in most of my esp8266 and esp32 projects, but i never knew about the TZ_info string...i always just used it as "GMT+10" and changed it when daylight savings started or ends... but the complete string with daylight savings start and end dates seems alot better.. i also tend to load the NTP time into the inbuilt clock and only update it once every 24hrs (or if the micro reboots)
@AndreasSpiess5 жыл бұрын
We do some investigations. It seems, that the time function also calls only every hour the time server. So we would not need the second function.
@WacKEDmaN5 жыл бұрын
@@AndreasSpiess you may want to look into the functions, setSyncProvider(getNTPtime) and setSyncInterval(86400); ...they are built into the time library and are usable with ESP's
@renelefebvre535 жыл бұрын
Bravo, la structure tm a toujours été pour moi un véritable casse-tête et je suis sûr que vous avez trouvé la véritable raison de ce problème : Unix + beer + canabis + LSD (+ easy girls) ===> struct tm !!
@AndreasSpiess5 жыл бұрын
Le casse-tête peut être encore plus facile si tu bois une bière toi-même.
@shamrock19615 жыл бұрын
I think the term "tm" came from the phrase "time management." It was during the beer and LSD era when programmers thought they would show off their alleged creativity and muck up the facts enough to make up stuff like a lot of the programmers did. This was the time of Fortran, BASIC...etc programming languages. Like everything else in programming programmers must have created names for their language using strange names from the local phone book, variations of languages such as pig Latin, olde English and French. There's my explanation and I drank no beer or dropped acid to arrive at my conclusions. I probably had yogurt earlier to clear my head and digestive tract. Pretty straight forward wouldn't you say??? 😃😄👍🍵☕🍕 Thanks for being a great teacher Andreas..
@AndreasSpiess5 жыл бұрын
And maybe they had valid reasons and nobody remembers, why... Their resources were very limited back then.
@ajm64093 жыл бұрын
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.
@AndreasSpiess3 жыл бұрын
Thank you for your explanation!
@rickhunt31835 жыл бұрын
That's a good presentation, but you certainly like doing things the hard way. I personally would have used a GPS module with the ESP32 and saved complexity and myself from writing a ton of code. A GPS based clock would be totally self adjusting. I'm sure you could have figured it out pretty easy. Too bad you didn't grow up with me during the 80's in South Carolina. We would have been drinking, fighting, going to wild parties and building computers every weekend. I hope you have a great evening.
@AndreasSpiess5 жыл бұрын
My lab is in the basement. So GPS is not a good solution for me :-(
@pjohnson212115 жыл бұрын
gotta say the decoding of the time string was the best part of the video :-)
@AndreasSpiess5 жыл бұрын
Thank you!
@avejst5 жыл бұрын
Great video as always Great project👍 Thanks for sharing👍😀
@AndreasSpiess5 жыл бұрын
You are welcome! Many comments suggest it was interesting for many viewers.
@Mesyu5 жыл бұрын
The weird numbering was standard in the US. We built Stirling cryogenerators which were also used in high end (super) computers. They invariably counted 4 cilinders as number 0,1, 2 and 3...
@AndreasSpiess5 жыл бұрын
Interesting! So you love complex numbering systems. We Europeans also need a much easier system for distances etc ;-)
@Mesyu5 жыл бұрын
@@AndreasSpiess No I don't. Like you I am European (Dutch) and prefer our metric system starting with a one.
@abhijitborah5 жыл бұрын
Needed this tutorial, thanks a lot.
@AndreasSpiess5 жыл бұрын
You are welcome!
@yuvalpp5 ай бұрын
Thank you for the enlightening video! I'm exploring ways to synchronize two ESP32 devices to generate a sync signal every 100ms. I can tolerate an error margin of 5-10ms, but the closer to zero, the better. My plan is to use WiFi, with one ESP32 acting as the master Access Point (AP) and the other as the slave. Since I don't have access to the internet and I'm not concerned with the actual real-time clock, my focus is purely on maintaining synchronization between the two devices. I'd love to hear any ideas or suggestions on how I could implement this!
@AndreasSpiess5 ай бұрын
Look at ESP-Now as the WiFi protocol. It is less complex and faster.
@therealblujuice5 жыл бұрын
Thank you for this video. Filled a few gaps in my misunderstanding 😜
@AndreasSpiess5 жыл бұрын
You are welcome!
@squalazzo5 жыл бұрын
why do seconds go from 0 to 61??? at 8:00
@AndreasSpiess5 жыл бұрын
I did not check the asterisks :-(
@hotgluegunguy5 жыл бұрын
This is to allow for leap seconds which may be added to UTC, because the defined time as measured by atomic clocks doesn't exactly match the observed solar time. Over time this discrepancy would otherwise accumulate an offset between UTC and solar time.
@sstorholm5 жыл бұрын
@@hotgluegunguy That was what I thought initially, but leap seconds count to 23:59:60, not 23:59:61, so I can't understand the need for a 61th second? Maybe it's there as room for expansion if they ever needed to add two at the same time?
@hotgluegunguy5 жыл бұрын
@@sstorholm I think you're right. Simply future proofing.
@hotgluegunguy5 жыл бұрын
@@sstorholm Actually, doing some quick research, I noticed that in the first year of leap seconds being introduced (1972), two leap seconds were added. One on June 30 and one on Dec 31. So the ability to add two leap seconds might be for software that only adjusts for leap seconds once a year, say Dec 31 after 23:59:59. Just a guess though.
@SittingDuc5 жыл бұрын
Year 2038 is only for signed 31 bit systems. Declare time_t as uint32 and have no problems until 2106. No problems except when you talk to the 31-bit computers ;)
@christopherguy12175 жыл бұрын
Gerard Sharp no, int is signed 32 bit so you'll go in to negative values past 2038.
@benhetland5765 жыл бұрын
Well, as per the applicable standards, the time_t is proclaimed to be of "some signed integral type", and some of the API functions return for instance (time_t)-1 as an error indicator. So even though the type is supposed to be able to represent times before 1970, the exact times 1969-12-31T23:59:59Z and 1970-01-01T00:00:00Z can be problematic or ambiguous; the former because it can actually be an error, and the latter because 0 is often used as a default initial value or to indicate other conditions such as "no time" or "missing time data".
@tin20015 жыл бұрын
Times prior to 1970 need to be represented... Not often, but it does happen.
@miscbits63993 жыл бұрын
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
@AndreasSpiess3 жыл бұрын
You are right, of course. This is why I mention that calling it every hour is sufficient (9:28). But I did not warn :-(
@IvanIvan19745 жыл бұрын
I guess the unusual formats @7:57 are due to the week day calculations. The formula is used with Sunday=0. Check: de.wikipedia.org/wiki/Wochentagsberechnung
@AndreasSpiess5 жыл бұрын
Maybe you are right. Back then, one byte was more valuable than today...
@TheKetsa5 жыл бұрын
Weren't we supposed to get rid of summer / winter time soon??
@AndreasSpiess5 жыл бұрын
I do not know how long this will take...
@r1273m5 жыл бұрын
"Changing the Clocks" as we call it in the UK was introduced here during WW1. It was abandoned for a few years during the late 1960's but reintroduced due to concerns about children going to school in the dark. They then had to come home in the dark.... There was also opposition from the farming community. Should Corbyn win the election time would cease to have any relevance, we would no longer be able to afford to buy an ESP8266!! Bob
@LeifNelandDk5 жыл бұрын
@@r1273m I think you are confused. 1: Corbyn wants the people to show they no longer believe the lies from BJ and the other brexit-scammers, and get a new referendum. 2: If BJ wins and he really gets UK out of EU, then the pound will fall even lower than already, and everything will be more expensive. But you still have the chance of reverting the mistake before UK falls into the abyss of despair on its own outside EU.
@dougmanatt43175 жыл бұрын
Define "We" !!!
@r1273m5 жыл бұрын
@@LeifNelandDk This really old English guy is anything but confused. 1. I have lived under several Labour Governments, not an experience I want to repeat. 2. We have had a referendum, the British people have made their decision. Labour and Lib Dems want to ignore that vote. Maybe if they should win we just ignore the result and have another election. 3. We lived very well without the EU before we joined, don't forget we are British, the ones who along with our allies saved Europe twice in the 20th C from German forces. 4. Countries such as Switzerland are not in the EU, maybe you should ask Andreas if he feels deprived by that. Regards from Bob
@marcusone15 жыл бұрын
Great video, thanks!! I found a library that worked well, but would have liked this a month ago :) as it seems simpler... That said, an issue I had with NTP was connection reliability. For some reason, I would often get no response from the NTP servers (or some error i couldn't figure out) Wasn't hitting them often, and even tried setting up my own NTP server. Didn't cause much of an issue until when the ESP restarts, it needs the time ASAP, and would of course display the wrong time until it could get a response. Instead, I now use MQTT to get the Time from a NodeRed machine that responds and send the UTC code back on another topic. Another option I thought of was to fetch a simple web page and grab the time from the headers, or again, have the http respond with json that contained the details i need.
@AndreasSpiess5 жыл бұрын
My sketch checks if the year is ok to decide whether data arrived from the server. But using MQTT is also a good way.
@christopheralexander87635 жыл бұрын
LOL Brits will create own time zone after Brexit. Made me spray my coffee - too funny. :)
@AndreasSpiess5 жыл бұрын
:-))
@AlunJones5 жыл бұрын
It's going to be GMT - 50 years :-(
@sonovoxx5 жыл бұрын
^^^^ This!!!
@ollyalme5 жыл бұрын
Or maybe they'll just keep it as is. You know, like before EU ;)
@darkstar21115 жыл бұрын
It should be 1.61h difference, one "imperial" hour, not metric one.
@realbss15 жыл бұрын
Hello Andreas, just for the records :Starting at 4:50 you state Switzerland would be behind UTC, as far as I know Switzerland is one hour AHEAD of UTC (at least it was true until now, don't know what will happen if the EU stops that stupid winter/summertime switching one day), not behind as you mentioned in the video - might be different for the area of Bern but this is a different story :D. So the correct term would be UTC+1h = CET (aka MEZ) and UTC+2h = CEST (aka MESZ). Same for Germany ... However the definition string you mention is quite simple to understand and defines the timezone CET to be one hour ahead of UTC (reverse logic !) meaning CET-1 is what you need to get UTC ( CET -1h = UTC) and CEST-2 (CEST - 2h = UTC) is again UTC ... Switching time in March (M3 at 2:00) and October (M10 at 3:00), every time in the "5th week" (= in reality last week of the month). As usual the challenge is to not get into a recursive loop while switching back from summer to winter time (as you switch back at 3:00 to 2:00 and will have a next 3:00 the same day after doing that) ...
@AndreasSpiess5 жыл бұрын
You are right. My explanation is wrong. At least the function should work ;-)
@BerndFelsche5 жыл бұрын
Finally a way to synchronize DCF clocks in Australia. 😎 P.S. I'd check the drift between NTP server requests and keep doubling until it becomes significant... Limited to about once a day, (32 hours) maximum.
@AndreasSpiess5 жыл бұрын
We do investigations. It looks that time() does not call the server every time. Only every hour. Which would make the second function obsolete...
@sonovoxx5 жыл бұрын
Oh no! Time!!! Einstein himself would have an apoplexy trying to deal with programming time! Since working on a system recording real time data across many time zones a number of years ago, I became convinced that time really doesn't exist! Lol! So go on - timestamp your data and see how many variables you have to include to separate out or synchronise each piece of data (and don't forget the duplicated data that occurs when the clocks goes back at different times in different time zones!)!
@AndreasSpiess5 жыл бұрын
Fortunately I usually do not go below 1 sec precision in one time zone. This makes it a little simpler...
@sethrd9995 жыл бұрын
Its an insanity made by silly humans unfortunately. UTC or GMT is the way out but it apparently is still to hard for the normal's out there. There is absolutely no reason for the time changes any longer this is 2019 going on 2020 not 1600's where perhaps farming was tied to day light hours. Its a tireless legacy that needs to just go away, but if you need to do these calculations you would do them on your backend system. Fortunately for me I use Java mostly so Joda Time takes care of this in 3 lines of Java. It was a good fix for those that need to do this on the embedded side, there is more info on how to adjust for drift using the pool of ntp servers on pool.ntp.org another way to get time if you have an iot out there with a GPS is to sync time with that as GPS time has to be accurate, this is also an epoch and works very nicely with the rtc library for most clocks.
@sonovoxx5 жыл бұрын
@@sethrd999 unfortunately GPS time does not match UTC either, and while the offset is trivial, your original data is always the reference, not the backend calculations, so if you record GPS and convert to UTC, you now may have to hold the history of calculations that determine the offset between the two at the time the data was recorded. The more critical a timestamp is to your data, the more time itself starts to look like an amorphous beast!
@benhetland5765 жыл бұрын
@@sonovoxx You're right, and having had to deal with timestamps in the past similar to what you have, I second your concerns about how complex temporal calculations really are, especially when we live on a wobbly ball of dirt and water that doesn't even have a well-behaved rotation! Regardless of this, let's also not forget that POSIX time is not the same as UTC, nor is it GPS time, nor TAI. It is close but not quite UT1 either. Furthermore, the time_t value used with the header (not ) in C and C++ is not necessarily the POSIX time value, although I have yet to see an implementation that didn't use it. Most modern libraries also have switched to 64-bit time_t a long time ago by now, but of course the exception is most likely in this very field of micro controllers that we are dealing with on this channel. :-)
@sonovoxx5 жыл бұрын
@@benhetland576 stop right now... you're bringing back all the nightmares! 🙉🙉🙉😂
@Roetsgent2 жыл бұрын
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.
@AndreasSpiess2 жыл бұрын
Maybe the example code has an error. But it should be easy to debug...
@petermeiner35745 жыл бұрын
Yes Andreas, for us it's normal: Monday is day 1 in the week. But over the big pond they thinkl different about that. My Canadian Colleague told me, he can't believe, that Sunday could not be the first day in the week. I have no glue, why they decide to this counts. Also in the Bible, sunday was the last day of the first week... So, i agree, beer or much stronger things causes this weired situation.
@AndreasSpiess5 жыл бұрын
They usually have Sunday as 1 AFAIK. Not 0
@petermeiner35745 жыл бұрын
@@AndreasSpiess your right, more confusion happend ;-)
@michaelgraff69785 жыл бұрын
I think the code doesn't roll over a day properly. If it is transmitting the day, won't it be off when the current time is 23:59, in that it will transmit 24:00? This also will break for leap seconds, but those are thankfully rare. (It is totally possible for tm_sec to be from 0 to 60, for instance, when a leap second is introduced...)
@AndreasSpiess5 жыл бұрын
I did not check the rollover, because my DCF77 transmitter would correct it after a while. But maybe somebody else checks it.
@benhetland5765 жыл бұрын
@@AndreasSpiess I had an inspection of the code too, and I must agree with @Michael Graff that the rollover must be wrong... To fix it at that point in the code where the "next minute" is currently added, however, would introduce a cascade of propagation of value overflows all up to the year! (And you must deal with leap year calculations too.) A much simpler solution would be to simply add 60 sec to the time_t now right before it is sent into the localtime function. It will take care of the complexities. Now the global timevalue will contain the next minute's time instead of the current minute, but that is probably exactly what you want there anyway. :-)
@DE-iv8if5 жыл бұрын
04:52 CET and CEST _behind_ UTC??? Really??? Sounds confusing.. I thought Germany is _ahead_ UTC, 1 (CET) Hour or 2 (CEST) Hours during "Day Light Saving" Time.. which actually is (or at least was) the Standard Time for Turkey.. So Germany during "Daylight Saving" Time "runs" at turkish (Standard) Time.. :/ However, Turkey now , seems to have allways "Summer" Time... However, 10:00 UTC would be 11:00 CET or 12:00 CEST I thought..
@DE-iv8if5 жыл бұрын
The ntpclient Timezone String (or the POSIX Timezone String in general?) seems to work this Way, that Timezones in the East (ahead of UTC) are usually "negative" like "CET-1" (UTC+1) or so, it seems and Timezones _behind_ UTC (and in the West) are _usually_ positive, so for them, usually just the Number is enough.. like "HAW10" for "Hawaii" (UTC-10) for Example. At least, that is how it looks like at the Moment to me..
@AndreasSpiess5 жыл бұрын
I do not know. Maybe another LSD trip ;-)
@EkelundDK5 жыл бұрын
Vielen danke, Andreas. I've created a ntp clock on an oled screen, but had some trouble with the date, as it was American with the month first, but as a Dane, that's just silly to me. I'll try your code, and maybe just update every minute, to not call the server too often. Anyway, thanks again.
@AndreasSpiess5 жыл бұрын
No problem with the sever calls. We found out that time() only calls the server every hour.
@matthiasklein96085 жыл бұрын
The reason for starting at zero might simply be that the values are calculated mod 7 or mod 12.Why bother to add 1 to the result. Moreover, finally, you willoutput day and month names. And array indexing starts at 0, too...
@AndreasSpiess5 жыл бұрын
I do not bother adding something if I know. But when I first saw the numbers I started to search for my mistakes :-(
@evanr19405 жыл бұрын
Sunday is the first day of the week in the US
@j100015 жыл бұрын
Whether Sunday or Monday is considered the first day of the week has a very long (and somewhat muddled) history indeed-well before ISO decreed a standard in the 1970s. In the US, Sunday is still considered the first day (in disregard of ISO). It also doesn’t matter as much here as in Europe because we don’t refer to dates using the week-of-the-year + day structure, but just stick with month + date structure. Interesting discussion and links here on Stack Exchange: history.stackexchange.com/questions/35979/when-did-europeans-make-sunday-rather-than-saturday-the-seventh-day
@valdisblack15415 жыл бұрын
08:20 this is OK to start counting from zero ;D and Sunday is the 1st day of week because of national standards. I have another question: why on earth they use int variables to store numbers like day or hour??? use byte variable! save some memory!
@christopherguy12175 жыл бұрын
Valdis Black Because int is the native memory size and requires only one clock cycle for access, byte requires additional clock cycles to isolate from the bytes returned during memory access.
@zeero4ever5 жыл бұрын
@@christopherguy1217 Maybe it would be better to say "native memory size for ESPs" as they are 32bit processors, whereas for a classic arduino, byte (= uint8_t) would be the better choice
@johnjoyce5 жыл бұрын
Zeero unfortunately the number of bits in the word length of a processor does not directly define the native types available in C and C++. This is precisely why we have sizeof operator...
@chrisdavis31285 жыл бұрын
Andreas, the link to the DCF77 github page gives lovely 404 error. :( Will you be uploading the code?
@AndreasSpiess5 жыл бұрын
Works now. Repo was private. Sorry...
@chrisdavis31285 жыл бұрын
Awsome, thanks. Such a *
@doreenclaywalker5 жыл бұрын
Many program's in the early days start every count with the 0...so you have more until you reach the end of the range. In a time where memory-space is expensive that was a big issue. Also indexes in programming languages start many times with 0 as first element. That doesn't mean they must be out of their mind to used this 'golden rule to start' also on month counts. So you are absolutly right.
@AndreasSpiess5 жыл бұрын
I agree in general. Here I had my problems with consistency. and there was no need to start with 0 as no number reaches even 255... And they are all int.
@zeero4ever5 жыл бұрын
@@AndreasSpiess I coud see a problem with uninitialized systems trying to get undefined month 0 if it was done otherwise.
@bryngerard43345 жыл бұрын
What is the impact on power consumption when using time functions or are they enabled by default?
@AndreasSpiess5 жыл бұрын
I assume it is only there with the time.h library. Otherwise it would not know where to call...
@davefiddes5 жыл бұрын
They should be pretty minimal. When you enable SNTP by calling the configTime() function the SNTP client will only call the server once an hour after the initial synchronisation. It uses the very efficient timer mechanism within the LwIP library used by the ESP family for their TCP/IP stack. There are no additional threads for example. There will be a bit more memory usage but not much. The code for SNTP is pretty much always there whether you use it or not. I've been fixing/updating SNTP support in the ESP32 and ESP8266 Arduino libraries recently which is why I come to know all this...;)
@maxkremmel4 жыл бұрын
Hallo Andreas, ich gehe mal davon aus du kommen aus dem deutschsprachigen Raum der Schweiz..... Ich verwende deine Library für einen Funkuhr mit Timer und Wecker Funktion. Es klappt auch ganz gut nur hin und wieder bekomme ich 7:28Uhr als Zeit angezeigt und es scheint als ob diese Uhrzeit genau so direkt vom TimerServer mir zugeschickt wird. Vielleicht bist du ja auch schon mal über diesen Bug gestolpert und hast einen Tipp für mich. Gruß Max
@AndreasSpiess4 жыл бұрын
Nein, bis jetzt nicht. Aber ich kontrolliere das nicht. Ich verwende das Programm für meinen DCF77 Sender.
@maxkremmel4 жыл бұрын
@@AndreasSpiess Ich habe nun einen google zeitserver ausgewählt und jetzt habe ich das problem nicht mehr
@Gunhed5074 жыл бұрын
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... ;)
@AndreasSpiess4 жыл бұрын
Congratulations!
@joinedupjon5 жыл бұрын
IIRC There was a period before the early 90's where the UKs GMT/BST switchover dates were defined in a less computer friendly way than they are currently (almost as if you can't rely on politicians to make your life easier). instead of last sunday it was the sunday after the 4th saturday. un*x sysadmins had to install a patch when we switched over to 'always last Sunday'
@AndreasSpiess5 жыл бұрын
Interesting. Maybe the next patch will become necessary when these changes stop ;-)
@vascosantosonfire5 жыл бұрын
Good video, can you please provide de diagram of the DCF77 antenna, resistors values, etc... Tanks
@AndreasSpiess5 жыл бұрын
Maybe you watch the video I mentioned?
@user001sg92 жыл бұрын
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
@AndreasSpiess2 жыл бұрын
I thought I mentioned the reason: I do not get DCF77 reception in my basement :-(
@KonstantinGrigoriadis2 жыл бұрын
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
@AndreasSpiess2 жыл бұрын
Ein Meter oder so.
@battlecoder5 жыл бұрын
Interesting video, as always! "tm" never seemed that weird to me, to be fair. I've extensively used that structure back in my network/server/socket programming days. The only field from that structure that I always found "weird" was "mday", which starts at 1 instead of 0 like all others. (Fine, year starts at 1900, but that's basically 0 from a "century" point of view). Minor correction about Aknik's code: His variable names are most likely in Italian (or what looks like Italian to me). Or at least 100% not Spanish. That much I can tell.
@AndreasSpiess5 жыл бұрын
I think it is no problem if you know the definitions of the structure. I searched for my mistakes when I first got the results :-( Concerning Italian: Obviously I mixed them. Thank you.
@tekniktdr5 жыл бұрын
Agree too. To me it absolutely looks like Italian. As you say, not Spanish for sure.
@leef_me81125 жыл бұрын
Andreas, your videos are always a thumbs up, because you provide a well planned video. You include a coarse level overview and then give a level 2 and 3 view of the information. Thank you for using Arduino code. **I think you have a verbal "typo" at **5:12**, you say "at one o'clock in the night", but the value shown is **2:00:00**.** Which is correct?
@AndreasSpiess5 жыл бұрын
One is in UTC
@SEOng-gs7lj2 жыл бұрын
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
@AndreasSpiess2 жыл бұрын
Did you watch my video #287 shown in this video?
@SEOng-gs7lj2 жыл бұрын
@@AndreasSpiess I did, but I'm not sure if I could just replace the ESP32 single wire antenna with the ferrite antenna and its capacitor, or should i take any precautions with the circuitry?
@AndreasSpiess2 жыл бұрын
@@SEOng-gs7lj You can add a transistor if you want.
@epedja4 жыл бұрын
You mentioned video with actual build of transmitter but I cannot find link to it. Can you post a link?
@AndreasSpiess4 жыл бұрын
Search for DCF77
@philippechampouret Жыл бұрын
Hello. Do you have a schematic for the antenna connection with the ESP32 please ?
@AndreasSpiess Жыл бұрын
Did you watch video #287 mentioned in the video?
@scottdc69715 жыл бұрын
A very interesting and useful video, thank you Andreas!
@AndreasSpiess5 жыл бұрын
You are welcome!
@MrLeri094 жыл бұрын
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?
@AndreasSpiess4 жыл бұрын
This should work. Maybe a few windings...
@admintmilgart85852 жыл бұрын
Thanks for the video. One question.... why are you using time.h instead of TimeLab.h (which is Arduino's time module)
@AndreasSpiess2 жыл бұрын
I do no longer remember why :-(
@halacs Жыл бұрын
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!
@AndreasSpiess Жыл бұрын
I updated the link.
@halacs Жыл бұрын
@@AndreasSpiess Thanks! Can you help me how to toll the cable on it to make the antenna ready? Sorry if I misised this information in your video.
@SarahKchannel Жыл бұрын
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 ! ;)
@AndreasSpiess Жыл бұрын
I agree with your statement, but do not remember my statement in the video. Maybe it was a (bad) joke :-(
@SarahKchannel Жыл бұрын
@@AndreasSpiess Its not meant to be a complain either ;) And the video is old - like you and me - when we discovered time, it was still analog :)
@AndreasSpiess Жыл бұрын
@@SarahKchannel No worries. I treated it as an addition ;-) BTW, I always wondered why in Arabic countries, they start their weekend with Friday, which seems to be similar to our Sunday, and then add Saturday the day after. Do you know, why?
@SarahKchannel Жыл бұрын
@@AndreasSpiess well the answer to that is quiet long winded, it includes christian, judaic and muslim faith. In islam per se, there is no weekend day off - day of rest, that was predominantly a jewish tradition - Shabbat. Which starts Friday and carries over into saturday. In islam firday prayers are the most significant, apart from the 5 prayers per day. It is significant in the sense, that it is a coming together, like a community and family matter to have this. Now even the western christian weekend was not 2 days until like the early 1900s. For most part of history it was 'just' sunday. Post world war, to boost the spending and economy, along with social well-fare, two days weekends where introduced, including Shabbat / Saturday to accommodate jewish traditions. When I came to the middle east - 20 years ago - some countries had thursday and friday off. Which was then realigned with western economic interests, like banking. Leaving friday as the predominant day off, but even that is slowly changing. Where like Dubai a few years back has started to amend that, to again accommodate international financial trade with the western world. So it has some biblical context, like the creation / genesis. Where god created the world in 6 days and rested on the 7th (sabath). On an related note, the arabs have a different calendar too, where the Arabic lunar year is about 11 - 12 days shorter then the solar gregorian calendar. Leading to Ramadan being every year few days earlier... etc etc etc
@SarahKchannel Жыл бұрын
@@AndreasSpiess and without knowing for sure, in old times christians, jews and muslims lived in close proximity. Sharing most likely places of worship. I would assume that each fraction was given or found their day of the week to worship. In old Damascus you can still find today Christian churches that are back to back with islamic mosques. Even sharing door between them - unthinkable in todays Europe !
@drTERRRORRR3 жыл бұрын
Microcontrollers and LSD! This is the best fucking channel ever!
@AndreasSpiess3 жыл бұрын
This was a common combination 60 years ago ;-)
@drTERRRORRR3 жыл бұрын
@@AndreasSpiess I truly envy you,man.
@resnbl15 жыл бұрын
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...
@AndreasSpiess5 жыл бұрын
I also saw this command. But it seems to work without ;-)
@pramukasooriyapatabandige76643 жыл бұрын
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 ?
@AndreasSpiess3 жыл бұрын
The ESP32 has RTC memory which keeps its content during deep sleep. But your clock will be the same if the ESP comes back from sleep. So you would have to correct the time.
@recklessroges5 жыл бұрын
Does this support the NTP Drift function?
@AndreasSpiess5 жыл бұрын
I do not know this function.
@davefiddes5 жыл бұрын
No. The SNTP protocol (a subset of NTP really) doesn't calculate local oscillator drift. The client updates the time every hour and it will jump the system time to whatever the update says the new time is. There is no clever slewing of time drift as you get in bigger OS like Linux. It's a bit much for an embedded device like an ESP.
@Electronieks3 жыл бұрын
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)
@AndreasSpiess3 жыл бұрын
This is a general ESP32 question. I never use fixed IP on the ESP, I fix the addresses on my router.
@Electronieks3 жыл бұрын
@@AndreasSpiess okay , i found a walkaround by using this : WiFi.config(ip, gateway, subnet, dns , dns ); //This is important for ntp! Include dns1 and dns2 when configuring!
@MultiVincent793 жыл бұрын
How to add decimal places for the seconds for much more accurate timestamping
@AndreasSpiess3 жыл бұрын
Please keep in mind that you get the time across the internet with various routes. Below one second accuracy is not easy. If you need it, I would go for a GPS module. They are much more precise.
@stevenalexander72593 жыл бұрын
@@AndreasSpiess but can you use millis function to add decimal for millisecond ? i've been looking around and does'nt get the answer yet... thankyou.
@FLIGHTC0NTR0L Жыл бұрын
Great video!! But how do i make the antenna??
@AndreasSpiess Жыл бұрын
I showed the video where I built a transmitter.
@PTReDaLeRtPT2 жыл бұрын
How can I built the antenna for this project?
@AndreasSpiess2 жыл бұрын
It was said in the video: The antenna is from another video.
@DavidGlaude5 жыл бұрын
Andreas, you are about 1125 KM away from Anthorn Radio Station that broadcast the UK time, and you are about 300 kM away from DCF77 source in Germany. I was wondering if you could make the test to get both signal on two separate radio controlled clock side by side. Or on the same clock that can be configured. Are you too far away (you said 2000Km for DCF77)? Is this related to curvature of earth or something blocking you? Maybe you could discuss how far it goes the way you explained Lora distance? Maybe you are not interested in UK time... Could you detect discrepancy if one goes wrong and the other stay right? That could be interesting video, at least for me. :-)
@AndreasSpiess5 жыл бұрын
These signals are propagated through the stratosphere. This is why they are generally better during night. So the distance the signal travels is always slightly different.
@DavidGlaude5 жыл бұрын
@@AndreasSpiess Thanks. Being somewhere in the triangle between Anthorn (UK MSF60 at 60kHz) Frankfurt (DCF77) and Allouis in France (162kHz), I should be fine then. If ever Europe disagree on Daylight Saving, I should be able to get all of those. Because of you, I am trying to put Ikea BURRIG Radio-controlled wall clock in my Xmas list, but this is not available Europe wide. It is available from Ikea Switzerland, but not in Belgium. I may have to do import. Your project is very interesting, please keep us update and share your ESP32 code.
@MeisterQ5 жыл бұрын
Ive build a Neopixle Clock with a 60 LED circle and a esp8266 with the NTPClient Library. I assume it requests every second from the NTP Server (But its my Fritzbox). So im having alot of traffic i think. Or does the NTPClient library only update on "update();" ? I have no clue.
@tin20015 жыл бұрын
Automatic SNTP updates occur every hour on ESP32 from what I remember. Simply reading the time does not cause a new request.
@MeisterQ5 жыл бұрын
@@tin2001 Would be nice. How can i figure it out? Turning off the WiFi and see what is happening?
@AndreasSpiess5 жыл бұрын
@Andreas: Tin2001 is right. It was proven by a viewer.
@MeisterQ5 жыл бұрын
@@AndreasSpiess thank you alot!
@emmanuelr66985 жыл бұрын
This is so cool, I'm not sure where you find your inspiration! 😉
@AndreasSpiess5 жыл бұрын
From problems I have to solve ;-)
@simonmarkham16075 жыл бұрын
Hi Andreas. I Love this channel. find it's my 'goto' for all things ESP. At the start of your listing, you state 'getTimeReducedTraffic(int ms) where ms is the the time between two physical NTP server calls' should this be seconds?, And are the lines ' 'getTimeReducedTraffic(3600)' and 'getNTPtime(10);' mutualy exclusive. I thought UTC had its roots in astronomy and was agreed to be Jan 1, 1900.
@AndreasSpiess5 жыл бұрын
Yes, the two lines are mutually exclusive. And if you go there, you will see that the second one became obsolete.
@simonmarkham16075 жыл бұрын
@@AndreasSpiess Thanks for the confirmation & update.
@BerndKircher5 жыл бұрын
Hello, am I the only one that gets an error when compiling the NTP_Example sketch? (OS: Ubuntu, Arduino IDE 1.8.10, selected board: Heltec Wifi Lora 32). Error Message: NTP_Example:41:18: error: Time.h: No such file or directory. Which liabrary do I have to add to the sketch?
@AndreasSpiess5 жыл бұрын
It was a typo. time.h has to be in small caps for the UNIX guys. I corrected it now.
@BerndKircher5 жыл бұрын
@@AndreasSpiess Thank you! I have already fixed that in my code. I have found another issue: in showTime you set localTime->mday to 7 if it's 0 (sunday) - but this should be applied to localTime->wday (week day) . Maybe you're a bit of a hippie too ;-)
@AndreasSpiess5 жыл бұрын
Should also be corrected by mow
@WagonLoads4 жыл бұрын
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..
@AndreasSpiess4 жыл бұрын
To measure the time difference and adjust seems to be the right way for me.
@WagonLoads4 жыл бұрын
@@AndreasSpiess I got it working within +/-1 second of NTP time..
@WagonLoads4 жыл бұрын
My current problem. I was able to get year, hours, mins and secs from epoch, but I wasn't sure how to get month, day and day of week. Here is the code I have working so far... // timestamp1 = millis();// Placed on line after data fetched from server int timestamp2 = millis(); int yy = epyear;// epyear = secsSince1900/secsinyear-100; int mm = epmonth;// don't know how int dd = 18;// don't know how int dow = 6;// Day of week// don't know how int hr = (epoch % 86400L) / 3600; int mn = ((epoch % 3600) / 60); int sec = (epoch % 60); sec = sec +((timestamp2 - timestamp1)/2); if(sec >60){sec = sec - 60;} if (!flag){ rtc.set(sec, mn, hr, dow, dd, mm, yy);// This line sets the clock flag = 1; } rtc.refresh(); if(sec != rtc.second()) { Serial.print("ntp: "); Serial.print(sec); Serial.print(" rtc: "); Serial.print(rtc.second()); }else { Serial.print(" > "); }
@WagonLoads4 жыл бұрын
after running my test for 24 hours, I found out that my RTC gained 7 seconds in a 24 hour period. Does the DS1307 have an internal register to adjust it's internal clock speed? I thought the Ds1307 was supposed to be accurate to within 6 seconds a year, not 7 seconds a day.. Which is highly unacceptable.
@yuu.relief5 жыл бұрын
just wonder. If function time() on (arduino core) time.cpp always call SNTP (need internet connection), then ESP8266 doesn't have any internal clock ( i mean counter)? if that so, should i count it manually? or function sntp_get_current_timestamp(); inside time(); only sync current time. (not always call SNTP)
@AndreasSpiess5 жыл бұрын
I made some comments on Github. The NTP server is only called every hour.
@yuu.relief5 жыл бұрын
@@AndreasSpiess So, as your note in github "So there is no need for the function getTimeReducedTraffic()"
@diogomartins9101 Жыл бұрын
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.
@AndreasSpiess Жыл бұрын
I just checked my device. It reads the NTP time every minute. But this is an old video and I do no more remember the details
@diogomartins9101 Жыл бұрын
@@AndreasSpiess does it keep counting the time like an offline clock when the network goes down? If the network goes down, the clock freezes. The EZtime library keeps ticking even when the network goes down. I´m gonna use the EZ library, I was not aware of it at the time I wrote that.
@AndreasSpiess Жыл бұрын
@@diogomartins9101 I do not know. My network is always up 😞
@diogomartins9101 Жыл бұрын
@@AndreasSpiess my project location does not have a good wifi signal, there will be connection losses, for sure, and the project includes a logger, so time tracking is essencial... It's in a farm...
@molodez_tom5 жыл бұрын
Great Video as always Andreas. Is there any documentation for esp commands "configTime" and time()?
@AndreasSpiess5 жыл бұрын
I did not find something ready made. Time() is a unix function.
@feynthefallen Жыл бұрын
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.
@AndreasSpiess Жыл бұрын
So good luck ;-)
@zambumm5 жыл бұрын
good video. but isnt using time as described as in the "simpletime" example in arduino for esp32 much simpler? i use a slightly modified even shorter version of this example and it works well and is less code and more readable.
@AndreasSpiess5 жыл бұрын
Are you sure your example automatically changes times in spring and in autumn? This is the point of this video.