Tech Note 122 - ESP8266/ESP32 NTP Time - The Simple Way

  Рет қаралды 14,315

G6EJD - David

G6EJD - David

Күн бұрын

Пікірлер: 142
@jcdock
@jcdock 4 жыл бұрын
Its good to know I can always rely on this channel to explain things in a way that makes sense.
@rodneytapit5636
@rodneytapit5636 2 жыл бұрын
Crystal clear tutorial with code that worked for me right out of the box on an ESP-01. Thanks Dave for your diligence in presenting these great tutorials - very much appreciated.
@stephencrowsen8537
@stephencrowsen8537 4 жыл бұрын
Thanks David, You were an answer to lots of prays. I spent weeks and weeks trying trying to get the time right, and you did it so simply. I had all but given up on trying to have time printed for New Zealand and thought I'd have to print out times with "UTC" attached to them. Cheers.
@Sophie333C
@Sophie333C 3 жыл бұрын
Great tutorial that includes both the NTP Time and OLED display. Not only does it include both, but gives a lot of detail on implementation.👍👍👍👍👍
@petersvideos8022
@petersvideos8022 3 жыл бұрын
Thank you one of the best presentation, easiest to follow and implement idea's I have seen on KZbin for any topic. The Github code provided worked out of the box which in my experience is rare. Well done.
@leythecg
@leythecg 3 жыл бұрын
one of the best channels of its kind on youtube! Competence together with clear and accurate explanations! Thanks for that!
@davewreski6900
@davewreski6900 3 жыл бұрын
David, Words cannot thank you for all your hard work and sharing these with US ( Me included !) Dave W.
@maciejrak4226
@maciejrak4226 5 жыл бұрын
Excellent material! The time stamp is a crucial component of the most time-related designs. Manually setting the time generates unnecessary complexity of a system and does not guarantee accuracy. The internet helps here a lot. Thank you, Dave, for saving my time and providing a ready-to-use solution.
@G6EJD
@G6EJD 5 жыл бұрын
And never have to worry about DST again😊
@maciejrak4226
@maciejrak4226 5 жыл бұрын
Too many time synchronisation events in a time unit might generate unnecessary traffic and, even more importantly, may violate service usage policies of some NTP providers. Could you, please, advise which of the discussed functions gets the time via NTP and/or how to explicitly control the period/frequency of syncing with the time server(s)?
@G6EJD
@G6EJD 5 жыл бұрын
Maciej Rak, time(now) gets the new/updated value which is then converted to the tm time structure, you could get an update once a minute or hour, but if your going to display real time there is no answer as every call seeks an NTP update. Unix time is a 32/bit unsigned integer that counts up in seconds so you can get now value then write that to an integer and increment that via a 1-sec interrupt, then every so often get an NTP update to keep it synchronised maybe once a day. Actually my example protupe has been running for 2-days without any service interruption so I’m not sure time servers care in the grand scheme of how many devices world wide are requesting a time sync.
@G6EJD
@G6EJD 5 жыл бұрын
Out of interest I've added a RTC version that updates at a user defined update interval, currently set to 60-seconds, but could be any value.
@maciejrak4226
@maciejrak4226 5 жыл бұрын
Thank you for adding this functionality!
@saeedala4673
@saeedala4673 5 жыл бұрын
Interesting and useful, as all your TN's are! Waiting for the next one already ;)
@marcrives279
@marcrives279 5 жыл бұрын
Very nice POSIX Time Zone format explanation; thanks a lot! Remember NTP should not be used too frequently (see polling interval theme). I had problems with sensors waking up every 5'.
@G6EJD
@G6EJD 5 жыл бұрын
Indeed yes, but in my experience few servers invoke any form of usage limit, and in most applications time would be obtained relatively slowly.
@cesarcasqueroperis1252
@cesarcasqueroperis1252 Жыл бұрын
EXCELENTE , muy claro, funciona en cualquier Arduino y ESPxx, gracias por facilitarnos en el aprendizaje. EXCELLENT, very clear, it works on any Arduino and ESPxx, thanks for making it easy for us to learn.
@patilabhijeetj
@patilabhijeetj 3 жыл бұрын
Simply awesome and really helpful. Definitely it's my next project on the updated list. Thank you for sharing this.
@sblantipodi
@sblantipodi 5 жыл бұрын
Discovered this channel now. Wow! Congrats man. You made an awesome job here. Thanks for it.
@wjn777
@wjn777 4 жыл бұрын
Great video, clear explanation, and so much better than using a third party library - thank you for sharing
@kobedde
@kobedde 5 жыл бұрын
Clearly explained. Very useful video. Thank you Dave.
@poepflater
@poepflater 4 жыл бұрын
thank you for taking the time to upload to git
@markludwig5805
@markludwig5805 3 жыл бұрын
I started looking into NTP for ESP8266 by watching Ralph Bacon's KZbin video. With all due respect yours is SUPER. How often does the ESP request Time from the NTP pool? If the WiFi later goes down will the internal clock of the ESP be keeping proper time? Thanks....great video.
@G6EJD
@G6EJD 3 жыл бұрын
You can specify the time server pool and the offset (in seconds, can be changed later with setTimeOffset() ). Additionaly you can specify the update interval (in milliseconds, can be changed using setUpdateInterval() ). NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); would be a typical definition.
@markludwig5805
@markludwig5805 3 жыл бұрын
@@G6EJD Your reply seems to be related to the NTPClient Library which we're not using. I understand the default update interval for configTime is 60 minutes. So how would I change the update interval to be 24 hours? Also is there a way to read back the update interval or determine how long before the next update? Thanks for your time...KA0SLK.
@G6EJD
@G6EJD 3 жыл бұрын
@@markludwig5805 yes, default update time is 1-hour, here’s the complete documentation: docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html with an example.
@G6EJD
@G6EJD 3 жыл бұрын
BTW, if the ESP32 is in sleep mode, the on-chip clock source is an RC timer (150KHz) based unit with a typical error (most run too fast) of 20-secs per hour, based on a wide sample of reports I’ve had with my weather station 20-secs is typical, this is probably why Espressif set the 1-hour update time. When the cpu is running and using (generally) a xtal clock source, some are ceramic based), I generally get no better than 2-sec accuracy per 12-hour this is because most xtals are 40+ppm or worst. 73
@gracc46
@gracc46 2 жыл бұрын
Awesome.Very useful indeed.Thanks heaps.
@BradR86
@BradR86 3 жыл бұрын
Thank you for this. This looks very promising. I'm building a datalogging device, and the numerous NTP solutions out there have been a bit janky and given me interesting results.... I'm still pretty new to programming ESP's so pardon my ignorance, but with the daylight savings info in the POSIX codes, does the time library automatically take care of updating the time as daylight savings falls? Or do I have to write code that looks at that info and advances the time? I'm confused by what you mean by "You can make your own DST codes".
@G6EJD
@G6EJD 3 жыл бұрын
Yes the posix codes take care of all DST functions such as moving time at 01:00 forwards or backwards on the first or last Sunday of the months so if you look at the code you can probably identify 3 and 10 as months /4 means 4th Sunday /5 means last Sunday of the month, google will reveal the codes, so yes you can easily define your own.
@BradR86
@BradR86 3 жыл бұрын
@@G6EJD Excellent News. This has just saved me from a bunch of bs. Just disovered your channel, and these tutorials look very handy. Definitely using this method for all my NTP needs in the things I'm building.
@G6EJD
@G6EJD 3 жыл бұрын
@@BradR86 reliable too
@2112user
@2112user 3 жыл бұрын
Thank you for the video, I mean really, THANK YOU. Just starting off in learning to write code and yours was the only video I've watched on it that helped me see it. I wonder if you could do a video expanding on time in a sketch. I'm in the USA and just need time (no days or years) so %r should be all I need. So how do we use this %r to say turn on/off a light or relay at a set time of the day? Something like this? "if %r> 7am then pin 1 high, else pin 1 low" "if %r >7pm then pin 1 low, else pin 1 high" Or would we had to state (int) ontime and offtime = 7am/pm. Been struggling to ultimately learn to do this, so any help in getting me to see it would be greatly appreciated.
@G6EJD
@G6EJD 3 жыл бұрын
Hi, you can’t use %r as that return unix time that advances every 1-sec. just use %h which will return just hours of the current time then you can use the expression if hour >= 7 then
@2112user
@2112user 3 жыл бұрын
@@G6EJD Ok, that make sense. I was just looking over your examples. I'll be giving it a go tonight. Long story short, heater killed her fish, so learned to use an ESP32 and relay to limit the temp and show current temp on a small OLED (better than those stickers). Figured I could have it do lights too IF I could learn how.... Thank you again, very glad I found your video and will be following you.
@G6EJD
@G6EJD 3 жыл бұрын
strftime(hour_output, 30, "%H", localtime(&now)); // Formats time as: 14 String currentHour = hour_output; If (currentHour >= “7”) …do this else; do…that
@2112user
@2112user 3 жыл бұрын
@@G6EJD Thank you, I'm going to FINALLY have time to look at it today for a while. Briefly had time yesterday, but not enough to really do anything.....
@2112user
@2112user 3 жыл бұрын
@@G6EJD Had some time last night to look into this, figured I'd start with you 1306 sample sketch. Make sure I could get time and display it before going further (editing anything). Kind of got stuck there. IDK if the library for the OLED changed, the link in the code vs what came up were different, but I did use/try it anyway. Got nothing on the OLED and the serial just showed dots. My I2C are pins 22 and 21 (ESP23S) and I did try putting those in where indicated. I say I wonder about the library because the Adafruit SSD1306, and their I2C example (what I used for my temp relay) work, and work without adjusting pins (not sure how that it though). I tried to use that library instead, but many of the strings failed in compiling afterwards.... Tried a few other "bring this n that over and hope" things, but that's where I ended last night. Figured I'd ask before heading out, if you had any ideas or a link to maybe the original library if the one linked to in the code has indeed changed (braking this example in the process).
@mikecarvill6467
@mikecarvill6467 3 жыл бұрын
Thanks David, That fixed it. Mike
@AndyShrimpton-GaaTech
@AndyShrimpton-GaaTech 3 жыл бұрын
hi dave for the life of me i cant get the correct time just 01-01-70 , so looks like some kind of default setting, and time 00:00:00. installed your github onto esp8266 with oled screen. Update ESP_RTC_with_NTP_Synchronisation_SSD1306_OLED.ino prints the same on the serial monitor it joins my wifi . been playing around all morning, but cant get it to change. this is above my pay grade. what should i look at. thanks Andy
@G6EJD
@G6EJD 3 жыл бұрын
Ok m, have you changed anything in the code apart from WiFi credentials? Is will show you the IP address to confirm a connection. Do you think your router is blocking outside connections, everything else’s operates ok on the WiFi?
@AndyShrimpton-GaaTech
@AndyShrimpton-GaaTech 3 жыл бұрын
@@G6EJD router possibly. do you know what port if any the NTP servers use
@G6EJD
@G6EJD 3 жыл бұрын
Does your phone or pc get the time ok?
@AndyShrimpton-GaaTech
@AndyShrimpton-GaaTech 3 жыл бұрын
@@G6EJD windows pc it has the correct time. Is they another way to check. Trying now to install another router
@G6EJD
@G6EJD 3 жыл бұрын
@@AndyShrimpton-GaaTech OK so there are no router blocks, it uses the same NTP access. Your getting a known good IP address on the serial monitor port?
@rodneytapit5636
@rodneytapit5636 Жыл бұрын
Hi Dave, I was wondering how the two functions configTime(...) and time(&now) work together. Specifically, configTime() is called once in setup() does that mean every time time() is called in loop() it will hit the NTP server? My question is how often is the NTP server accessed and which function takes care of that, is it automatic or can it be controlled? Hope you are keeping well Dave.
@G6EJD
@G6EJD Жыл бұрын
Hi Rodney, config time is called just once to set the ntp parameters which are stored in rtc flash ram, then the ESP32 rtc is started and is essentially a counter set to the current UNIX time value and increments every second, then the ESP32 code maintains a clock, which gets its clock source from (depending on settings) the ESP32 resistor-capacitor controlled RTC clock, so it’s not very accurate, many seconds of gain or loss every day. It is possible to set the clock source to a 32khz xtal (if fitted to the board) but not in the Arduino IDE, then clock drift is a few seconds per day about the same a watch. So to maintain accurate time a call to NTP is made which updates the RTC counter with the current UNIX time. It only needs to be called say every hour, but for experimentation frequently calling NTP is ok. So in essence it’s an ESP32 timer (one of the four) and it is set to increment every second fed by an RC clock in the ESP32. The timer value being set by the NTP call for the UNIX time value.
@rodneytapit5636
@rodneytapit5636 Жыл бұрын
@@G6EJD Your reply has made the finer details much clearer, thank you. One final question when you say "So to maintain accurate time a call to NTP is made which updates the RTC counter with the current UNIX time" what determines when the NTP request is made, is it automatic or the result of calling a function. If automatic how can the frequency be changed say to once per day, etc, instead of hourly. Edit: I just found this function uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 () which returns a value (seconds * 1000) to override the default sntp default update period of one hour. I've verified it works at least on an ESP8266.
@gpTeacher
@gpTeacher 3 жыл бұрын
Thanks for your help David. Am I correct in my understanding that with the example the NTP server is only called ONCE to set the time iside the ESP32 and then from then on the time is updated from within the ESP32? Please confirm or correct my erroneous understanding. I'd ideallly like to poll the NTP server at startup only and then provide current time without having to constantly poll the NTP server inside loop(). Thank you again for a great explanation. Gord
@G6EJD
@G6EJD 3 жыл бұрын
You have to establish the NTP connection, get the current time, then yes the ESP32 maintains the time, but the RTC clock source in the ESP32 is very inaccurate, that is it runs at about 150KHHz and is subject to a lot of drift, many seconds per day, typically +/- 20-secs per day, so you do need to periodically get a new value from the NTP servers. If the on-board xtal is enabled then the clock accuracy will be about +/- 3-secs per day, about the same as a quartz watch.
@gpTeacher
@gpTeacher 3 жыл бұрын
@@G6EJD Thanks very much for your help and explanation David. Best wishes.
@AndyShrimpton-GaaTech
@AndyShrimpton-GaaTech 4 жыл бұрын
Hi Dave new to this coding just starting at 55. Your video are very clear and full of info. I have esp8266 with DHT11 and oled screen which is working fine, i even have it publishing to a webpage. I have used your code to add the time. In my void loop where the dht11 reading are taken if i increase the delay between reading/screen refresh to 2000, it effects the clock (seconds increase only every two seconds as expected) as the screen is only updated once per 2 seconds. How or where should i put your clock code so the delay in reading the DHT does not effect the clock. I think i need to learn how not to use delays and instead interrupts. as i have learn delays are bad for programming anything other than very simple code. Learning loads and having fun, though stress full at time (LOL)
@G6EJD
@G6EJD 4 жыл бұрын
Andy, I’m pleased you hear your enjoying coding microcontrollers, yes the effect your seeing is programmatically correct as the 2-sec delay indeed halts all updating, there are a number of factors here you should consider, one is not getting time too frequently as NTP servers will block you eventually for too many requests, so best to leave the ESP8266 internal interrupts to increment the so called UNIX time value every second (now) and then occasionally get a new value from NTP services say every 20-mins in seconds if that’s your count, next the DHT is quite a slow sensor and you could introduce an interrupt that every 10-mins or 1-min or whatever gets a new reading from the DHT, see my video on interrupts set a timer interrupt to trigger every day 10-mins and when it does read the sensor to a global variable, now your void loop need contain no delays at all, there will always be some jitter in the screen update routine as during the DHT reading which can take a second or so, the main programme flow is bring interrupted, but it’s better than using delays, it’s all part of programming a Von Neumann architecture cpu, if we had 2-CPU’s the task of reading the sensor could be allotted to the second cpu, and the two exchange or use a common set of variables to exchange the data. In a way what you are trying to counter is a perfect way to add to your learning as it’s the next step in programming. Hope this helps. BTW also see my video on memory allocation for interrupt routines and whilst the compiler in its latest guise will say, interrupt routines need to reside in ISR RAM (interrupt service routine) to stop interactions and crashing, usually solved by prefixing the function with IRAM or some other prefixes eg IRAM void DHT_Reading()...
@stevenbense3504
@stevenbense3504 4 жыл бұрын
Just discovered your channel. Thank you for the excellent tutorials. Once the setenv has been set using a time zone string, does it need to be changed when the switch happens to DST? Or is it simply setup to match whatever the current setting is and then it will automatically change when the DST date and time comes round.
@G6EJD
@G6EJD 4 жыл бұрын
Steven, once Setenv is set there’s no need to adjust date-time again and the NTP services will follow the rules adjusting time forward and back in Spring / Autumn continuously.
@stevenbense3504
@stevenbense3504 4 жыл бұрын
@@G6EJD Thank you for clearing this up.
@eduardovillar2211
@eduardovillar2211 3 жыл бұрын
Hi David, I'm trying to asing values of the function in integers, in order to per exemple, compare with other integers to create a alarm clock... as I'm not too much expert I just do it using the follow way but i'm pretty sure that instead is working it is not the best wise method: #include // or #include for ESP32 #include int hora; /// integers for futher handling hour minute and second int minuto; int segundo; void setup(){ Serial.begin(115200); WiFi.begin("****","***"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // See github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); } void loop(){ Serial.println(get_time()); Serial.print(hora); Serial.print(":"); Serial.print(minuto); Serial.print(":"); Serial.println(segundo); } String get_time(){ time_t now; time(&now); char time_output[30]; char datohora[3]; //collect only data desired in char format char datoomin[3]; char datosecon[3]; // See www.cplusplus.com/reference/ctime/strftime/ for strftime functions strftime(time_output, 30, "%a %d-%m-%y %T", localtime(&now)); strftime(datohora, 3,"%H", localtime(&now)); //repeat the function each time as is needed for extract the value desired ( hour ,min and second) strftime(datoomin, 3, "%M", localtime(&now)); strftime(datosecon, 3, "%S", localtime(&now)); hora=atoi(datohora); // convert the char in integer for further handling minuto=atoi(datoomin); segundo=atoi(datosecon); return String(time_output); // returns Sat 20-Apr-19 12:31:45 } system is working and I am able to handle the hour, minute and second as I decide (time variables in spanish) but as I mention I fell that it is not the best method. What is your opinion?? thanks for your videos and great support.
@G6EJD
@G6EJD 3 жыл бұрын
It looks good, I can’t see much you could change. I’d keep it as it is, you might save only 1 or 2 lines at most. You’ve done well.
@eduardovillar2211
@eduardovillar2211 3 жыл бұрын
@@G6EJD thanks for support. I will integrate the code with a TFT colour display, now are really cheap and not so slow, so it could be considered as the lcd monocrome displays replacement.
@Freeno83
@Freeno83 4 жыл бұрын
Very quick and useful. thanks alot!
@brendanfurlong7868
@brendanfurlong7868 3 жыл бұрын
Hi David ,first thanks for a great tutorial :-) I'm using an ESP32 DEV c and a little ssd1036 . Compiles and uploads fine via Ardunio IDE . If I open the serial monitor I can see it joining the WIFI and it scrolls the correct time but nothing on the little oled . The only change I made was to add the line SSD1306 display(0x78, SDA, SCL); after the #include "SSD1306.h" . I'm wired up to pin 22 for SCL and 21 for SDA . I previouly had a little clock running with this setup but wrong time of course . Any dea what I could be doing wrong ? rgds B (p.s very new to esp32 etc )
@G6EJD
@G6EJD 3 жыл бұрын
What size is the display 0.96 or 1,3”’ has the display ever worked? What board type are you selecting in the ide
@brendanfurlong7868
@brendanfurlong7868 3 жыл бұрын
@@G6EJD 0.96 ssd1306 display . Board selected is DOIT ESP32 .Also used standard ESP32 dEV ..I verified the screen is ok by using this example and it works without modification on both boards selected ..github.com/lexus2k/lcdgfx/blob/master/examples/direct_draw/clock/clock.ino ...thanks for the reply btw :-)
@G6EJD
@G6EJD 3 жыл бұрын
@@brendanfurlong7868 use the same constructor if it works ok: DisplaySSD1306_128x64_I2C display(-1);
@theUsesOFnot
@theUsesOFnot 5 жыл бұрын
Strange result. The first time I call gettime in the loop it returns Thu 01 01 70 11:00:11. after that the date and time is correct. why this happens?
@G6EJD
@G6EJD 5 жыл бұрын
It takes about 500mS to establish a connection to the time server, you can add a small delay to wait for the connection to prevent this, some networks are slower than others, yours is towards the slower end, that’s the connection between the ESP and your router access point and the the time to get to the NTP server, you can measure the delay from say a PC to the ntp server with a ping server-address to optimise the delay setting, but usually a simple delay(500); after the get time function resolves the issue.
@G6EJD
@G6EJD 5 жыл бұрын
For the ESP32 there is also an option to automatically wait until time has been obtained without adding a fixed delay, so it will wait until time is set then move on, waiting for a maximum defined amount of time, I can let you know how to do that if you need it.
@theUsesOFnot
@theUsesOFnot 5 жыл бұрын
@@G6EJD thx for that. i added the following code which seems to do the trick: while (time(nullptr)
@G6EJD
@G6EJD 5 жыл бұрын
struct tm timeinfo; char time_output[30], day_output[30], update_time[30]; while (!getLocalTime(&timeinfo, 10000)) { // Wait for 10-sec for time to synchronise Serial.println("Failed to obtain time"); return false; }
@alnoorratansi9364
@alnoorratansi9364 2 жыл бұрын
Great Tutorial, how would you parse hours, minutes, sec to send it sync the RTC(ds 3707)
@G6EJD
@G6EJD 2 жыл бұрын
It’s actually quite easy, there is a function in the Adafruit rtc library just fill the parameter with the current time and call it, you can then keep the rtc synchronised says every day or whatever period is required.
@G6EJD
@G6EJD 2 жыл бұрын
rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); so it’s CCYY, Month, Day, Hr, Min, Sec
@etk4257
@etk4257 4 жыл бұрын
Dave, very helpfull. Thanks. Do you know a way to setup strftime() to provide native language strings? I found a header file langinfo.h at the source files for the esp8266 but I could not figure out where to supply the translated strings for month names / weekday names or even find the original English strings. That would be really nice! Thanks.
@G6EJD
@G6EJD 4 жыл бұрын
I’ve done the same searching as you, but for some reason there has never been a solution or easy conversion but there should be! C++ supports this, but in this case it’s a compiler shortfall, just never been implemented it seems. You can do a string.replace(“Mon”,”Lyn”); etc but you’d need quite a few, 19 or more! Or you can fprint and give it parameters to do the conversion, but either way it’s clumsy. I’ll try some more to find a solution as I’d like to solve it.
@G6EJD
@G6EJD 4 жыл бұрын
I notice PY supports setlocale
@etk4257
@etk4257 4 жыл бұрын
@@G6EJD I found this document explaining how to change a language settings parameter on Debian: ccollins.wordpress.com/2009/01/06/how-to-change-date-formats-on-ubuntu/ Particularly in the directory /usr/share/i18n/locales there are all the language dependant settings. Now we need to tell the compiler for the ESP8266 about some other language file. But I am afraid that isn far beyond my current knowledge ...
@EasyOne
@EasyOne 3 жыл бұрын
exit status 1 call of overloaded 'String(IPAddress)' is ambiguous
@G6EJD
@G6EJD 3 жыл бұрын
Serial.println("WiFi connected to address: "+String(WiFi.localIP()));
@santorcuato
@santorcuato 5 жыл бұрын
Real simple way. Thanks Dave!
@spielautomat9751
@spielautomat9751 5 жыл бұрын
thanks old man :) ur right on time.
@qsdrfghgujfddyffguff
@qsdrfghgujfddyffguff 3 жыл бұрын
good working with node mcu
@tycstahX
@tycstahX 5 жыл бұрын
Great stuff! I wonder how bad the accuracy of a project could get with only a daily NTP resync. (trying to avoid using a RTC)
@G6EJD
@G6EJD 5 жыл бұрын
Robert Olson not tried that. You can print the value of the Unix formatted clock (32-bit integer) day at a designated time then wait say 12-hours and compare, maybe requires more time.
@norberthartmann5075
@norberthartmann5075 5 жыл бұрын
Thanks ! sommer / winter time OK - shown ?
@vtech8716
@vtech8716 5 жыл бұрын
Thanks a lot, good tutorial as always
@mareksukup9592
@mareksukup9592 5 жыл бұрын
Hello, thank you for this movie - it helps me a lot.
@TheUnofficialMaker
@TheUnofficialMaker 2 жыл бұрын
Thanks so much!
@MPElectronique
@MPElectronique 5 жыл бұрын
Hi Dave! Thanks as usual. Do you know where i can fetch the atomic clock from the internet ? Thanks. Marc.
@G6EJD
@G6EJD 5 жыл бұрын
Marc, not sure what you mean, most NTP servers are locked to an atomic clock anyway, the NIST servers are all synchronised to atomic sources tf.nist.gov/tf-cgi/servers.cgi
@MPElectronique
@MPElectronique 5 жыл бұрын
@@G6EJD im looking for the fort collin in colorado..
@G6EJD
@G6EJD 5 жыл бұрын
You can use 'time-a-wwv.nist.gov' or 'time-b-wwv.nist.gov' or 'time-c-wwv.nist.gov' or 'time-d-wwv.nist.gov' just place one or more or all in the server address section separated by commas and place each in quotes
@G6EJD
@G6EJD 5 жыл бұрын
Don't forget that NTP measures the time delay between you and a server and removes that delay from the time it supplies you so that time and the server wherever it is and you are identical so for absolute accuracy yes pick an NTP server that uses an atomic clock, but what ever time source is used your device and the remote server will be the same time.
@sshah876
@sshah876 4 жыл бұрын
Excellent project, I wish I could use a bigger display i.e Max7219.
@fredvanderreijden8759
@fredvanderreijden8759 5 жыл бұрын
In the ESP_Simple_Clock.ino got an error at line 69 // Serial.println("WiFi connected to address: "+String(WiFi.localIP())); Compiler Error "call of overloaded 'String(IPAddress)' is ambiguous In the ESP_RTC_with_NTP_Synchronisation_SSD1306_OLED.ino got an error at line 91 // Serial.println("WiFi connected to address: " + String(WiFi.localIP())); Compiler Error "call of overloaded 'String(IPAddress)' is ambiguous I use Arduino IDE 1.8.9 AND ESP cores 2.5.0 for ESP8266
@G6EJD
@G6EJD 5 жыл бұрын
If your getting that error then you copied the text via a browser and your source code contains unseen characters, did you download the zip containing the source code?
@fredvanderreijden8759
@fredvanderreijden8759 5 жыл бұрын
@@G6EJD Dear Sir, I have the code via github.com/G6EJD/ESP_Simple_Clock_Functions downloaded and unzipped the zip. Everything goes well with the ESP32, but with the ESP8266 I get the error code.
@ardlab7972
@ardlab7972 4 жыл бұрын
Is the esp time ever synced again or only once in setup?
@rvegeta
@rvegeta 3 жыл бұрын
I tried the code but it's not working, it only prints 01-01-70, can someone help me? (just changed the Wi-Fi configuration) Also, what's the TZ for Venezuela? I can't find it anywhere and I need this to make timestamps in my sensor...
@G6EJD
@G6EJD 3 жыл бұрын
Try it as published first, you can get the TZ string from the posix site I listed in the comments TZ = "4" works for me
@mikecarvill6467
@mikecarvill6467 3 жыл бұрын
Hi David, I tried to input a comment to you yesterday but now I don't see it's the first time in my 79 years that I've commented on a website so bare with me please. My comment yesterday was related to error message "call of overloaded 'String(IPAddress)' is ambiguous" using a ESP8266 I have now got loaded on the only ESP 32 that I have which happens to be a AI thinker ESP32-CAM and it displays time date. My Arduino IDE is v 1.8.13 and I think this line gives you the core version for my ESP 8266 Users\mikec\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/WString.h:63:18: note: String::String(char) explicit String(char c); Can you help. Mike
@G6EJD
@G6EJD 3 жыл бұрын
The compiler has been changed, try this: Serial.println("WiFi connected at: " + WiFi.localIP().toString());
@qsdrfghgujfddyffguff
@qsdrfghgujfddyffguff 3 жыл бұрын
@@G6EJD yes error solved
@williammiller7543
@williammiller7543 5 жыл бұрын
In theESP_Simple_Clock.ino got an error at line 75 // Serial.println("WiFi connected to address: "+String(WiFi.localIP())); Compiler Error "call of overloaded 'String(IPAddress)' is ambiguous", had to change to: Serial.print("WiFi connected to address: "); Serial.println(WiFi.localIP());
@G6EJD
@G6EJD 5 жыл бұрын
There’s nothing wrong with the code are you at IDE 1.8.9 and ESP cores 1.0 for ESP32 and 2.4.2 for ESP8266? Did you copy the code using your browser? If so most likely hidden characters exist.
@williammiller8078
@williammiller8078 5 жыл бұрын
Dave: How do I convert time elements to integers so I can apply math or logic operators? Thanks in advance.
@G6EJD
@G6EJD 5 жыл бұрын
There is a predefined type with a TM prefix: int my_hour = tm.hour; int my_min = tm.min There are about 20 sub-types day, Dow, secs, etc
@tinexdFPV
@tinexdFPV 5 жыл бұрын
@@G6EJD hi and thank you for your great work :) i have the same problem and int my_hour = tm_hour; does not work for me (WEMOS D1 mini & ESP8266, Error: 'tm_hour' was not declared in this scope). Can you help me, please? I need hour and minute in int. Thank you :) .......my solution is the atoi() function....it works for me, but i think its not the best approach
@G6EJD
@G6EJD 5 жыл бұрын
void get_time(){ time_t now; struct tm * timeinfo; time(&now); timeinfo = localtime(&now); int int_hr = timeinfo->tm_hour; int int_min = timeinfo->tm_min; int int_sec = timeinfo->tm_sec; }
@MPElectronique
@MPElectronique 5 жыл бұрын
Hi Dave. I cannot get the function getLocalTime in ESP8266, is it normal? Thanks. Marc.
@G6EJD
@G6EJD 5 жыл бұрын
Marc, Chaco our the code examples for the ESP8266 that function does not work so it has to be a slightly different approach, but still quite short amount of code.
@MPElectronique
@MPElectronique 5 жыл бұрын
@@G6EJD Hey Dave. Why when i request from OpenWeatherMap i got: 1561367183 as sunrise and when i convert it it gives me: 9:06:23 , when it's 5:06 the real sunrise? thanks. Marc.
@G6EJD
@G6EJD 5 жыл бұрын
@@MPElectronique , that time comes from OWM and converted gives 9:06am (UTC) and your +4 hours? which sounds it could be correct to me. What location are you and I'll check what OWM returns here in the UK, could be a OWM bug.
@MPElectronique
@MPElectronique 5 жыл бұрын
@@G6EJD Montréal Canada.. Sunrise at 05:0 6
@G6EJD
@G6EJD 5 жыл бұрын
Marc, OK I found the issue, when your get sunrise and set times from OWM they are in Unixtime (secs from a basedate), next your need to add the timezone value from the API response which for you is -14400 and this takes 4-hours off your sunrise/sunset times. Or, send your Unixtime through this: String ConvertUnixTime(int unix_time) { // Returns either '21:12 ' or ' 09:12pm' depending on Units mode time_t tm = unix_time; struct tm *now_tm = localtime(&tm); char output[40]; if (Units == "M") { strftime(output, sizeof(output), "%H:%M %d/%m/%y", now_tm); } else { strftime(output, sizeof(output), "%I:%M%P %m/%d/%y", now_tm); } return output; }
@JosefZvolanek
@JosefZvolanek 5 жыл бұрын
Super Dave :-)
@Andrey-Ush
@Andrey-Ush 5 жыл бұрын
👍
@browaruspierogus2182
@browaruspierogus2182 5 жыл бұрын
I don't use Arduino - so it doesn't help at all.
@G6EJD
@G6EJD 5 жыл бұрын
I don’t understand the point your making?
@G6EJD
@G6EJD 5 жыл бұрын
Also if your using another IDE then I can see few if any differences.
@browaruspierogus2182
@browaruspierogus2182 5 жыл бұрын
@@G6EJD So can you explain in details the protocol to use with TCP? What protocol is it? NTP or SNTP or other?
@G6EJD
@G6EJD 5 жыл бұрын
I have not checked the compiler source code, but most likely the community uses SNTP which as you will no doubt know, is a reduced and simplified version of the NTP (Network Time Protocol) protocol, NTP is generally used only to guarantee high accuracy and is quite complex. Do you need NTP services for your code? Bear in mind there are relatively limited resources on an ESP8266 so for code compatibility SNTP is the likely outcome.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
A foolproof way to get ANY project done using ChatGPT
10:46
Tech Note 130 - Solar Power for Projects (Arduino/ESP8266/ESP32)
20:59
Tech Note 123 - ESP32 or ESP8266 NTP synchronised Real Time Clock
4:34
#139 No Real Time Clock (RTC) Required (Wemos ESP8266 Mini)
31:38
Ralph S Bacon
Рет қаралды 22 М.
Build a Stratum 1 Time Server Using a Raspberry Pi Pico
19:53
Gary Explains
Рет қаралды 21 М.
Tech Note 131 - ESP32/8266 Reducing Battery Load Hints & Tips
5:59
G6EJD - David
Рет қаралды 18 М.
Forget WiFi! This Wireless Method is WAY Better?
12:14
GreatScott!
Рет қаралды 704 М.
This tiny computer changes EVERYTHING
15:57
Jeff Geerling
Рет қаралды 858 М.