Tap to unmute

Atomic Clock Sync: ESP32 NTP Magic in Just 2 Lines of Code!

  Рет қаралды 8,723

atomic14

atomic14

Күн бұрын

Пікірлер: 42
@svids998
@svids998 Жыл бұрын
Really well done video! The animations and all are top notch.
@hermannpaschulke1583
@hermannpaschulke1583 2 жыл бұрын
The esp32 does have an RTC, but no backup battery
@kryptonic010
@kryptonic010 2 жыл бұрын
The code is cool and all but where can I get a hold of the transparent displays & code?
@atomic14
@atomic14 2 жыл бұрын
Updated the description with some links - the display is here - www.dfrobot.com/product-2521.html You can drive it using the U8G2 library github.com/DFRobot/U8g2_Arduino
@kryptonic010
@kryptonic010 2 жыл бұрын
@@atomic14 Thx 4 sharing.
@Bob_Burton
@Bob_Burton 2 жыл бұрын
5:09 The use of timestamps to compensate for transmission delays is all well and good but they need to be accurate, which the local times may not be so how does that work ?
@atomic14
@atomic14 2 жыл бұрын
It's really very clever. Imagine ntp time is 0:30 and our local clock is 10seconds behind at 0:20 We send a request at 0:20 it takes 1second to reach the server and the server records the request received as 0:31. The server takes 1 second to process the request so sends its reply at 0:32 It takes 1 second for the reply to reach us so we recorded the receive time as 0:23 If we now apply the delta formula we have. 0.5 x ((0:31 - 0:21) + (0:32 - 0:23)) = 0.5 x (10+10) = 10 So we have 10s as our offset from the server time.
@PatrickFelstead
@PatrickFelstead 2 жыл бұрын
Excellent video - very informative and fun presentation!
@atomic14
@atomic14 2 жыл бұрын
Thanks - I had a lot of fun making it :)
@connormccarter9581
@connormccarter9581 2 жыл бұрын
This is really cool! Thanks for sharing! And I am guessing this is related to your super sized seven segment display?
@atomic14
@atomic14 2 жыл бұрын
Yep, until I did that project I had no idea it was so simple.
@hungcarl
@hungcarl 2 жыл бұрын
I want a bigger one. Is it possible to buy?
@atomic14
@atomic14 2 жыл бұрын
How big do you want it? www.lg-informationdisplay.com/oled-signage/brand And how much money do you have to spend :)
@t1d100
@t1d100 2 жыл бұрын
So, the network is directly polling GPS satellites... You can, too, and make a portable GPS Atomic Clock. You just need a cheap Ublox GPS Receiver clone and have the MCU tap into it. I used the model NEO-M8N and a PIC18F4550 to make my clock. The NEO-M8N can also be used to make a 10MHz frequency reference, because its on-board chip can be configured to output different frequencies. So, I added this additional output to my clock. For that matter, once you have a GPS receiver, you can have the MCU handle all of the information the GPS satellites provide and build your own GPS positioning device. And, the accuracy is perfect, because there is no line transmission delay.
@atomic14
@atomic14 2 жыл бұрын
It's surprising how much GPS is used just for time - almost all mobile network base station have a built in GPS receiver just so they have accurate time. And you can pick up a GPS module for
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 2 жыл бұрын
You have to remember not to read the time too oftern as the server may time you out, they get 1000's of requests per second so don't want you poking you head in to much. Of couse you could reduce this to one line of code, but it would be harder to read 🙂 Not sure if you have noticed the string of videos on my channel which are leading to something 🙂 P.s still waiting for a delivery date on your doll i ordred. 🙂🙂
@atomic14
@atomic14 2 жыл бұрын
I've been watching the videos... looking forward to seeing what's coming!
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 2 жыл бұрын
@@atomic14 Sad to say i don't think there will a doll in the next one ;-)
@PeterScargill
@PeterScargill 2 жыл бұрын
I'd be more impressed if it were using an ESP8266which is half the price of the ESP32 and the free Tasmota which allows time and date readouts without a single line of code :-) Pop the code in using the online installer, set the mode to show the time and it's done - rstarts automatically after poaer failure.
@Magic-Smoke
@Magic-Smoke 2 жыл бұрын
I just know that this is the prelude to running the display from the ULP coprocessor when you're in deep sleep to save power 😬
@atomic14
@atomic14 2 жыл бұрын
That's not a bad idea!
@nigeljohnson9820
@nigeljohnson9820 2 жыл бұрын
Would have been helpful if delta and theta had been defined and the connection between the two made clear. Certainly the origin and destination of the message must be indicated. It is not sufficient to say the two numbers maybe used to make the time correction, without showing how.
@atomic14
@atomic14 2 жыл бұрын
I should have included a slide for this. It's pretty clever how it works. Imagine NTP time is 0:30 and our local clock is 10seconds behind at 0:20 We send a request at 0:20 it takes 1second to reach the server and the server records the request received as 0:31. The server takes 1 second to process the request so sends its reply at 0:32 It takes 1 second for the reply to reach us so we recorded the receive time as 0:23 If we now apply the formula we have. 0.5 x ((0:31 - 0:21) + (0:32 - 0:23)) = 0.5 x (10+10) = 10 So we have 10s as our offset from the server time.
@atomic14
@atomic14 2 жыл бұрын
Delta is the total network delay - if you plug the same numbers into the formula you should get 2seconds - the total delay due to the network. Theta is the time offset. I really should have put all this in the video!
@nigeljohnson9820
@nigeljohnson9820 2 жыл бұрын
@@atomic14 I derived the equations from first principles, Am I correct in assuming that the result depends on the forward and reverse network path having equal delays. My equations suggest that it's possible to calculate the error in the computer clock, and the total loop delay, but not the difference between the delay between the forward and reverse paths. This delay appears in the LHS of the equation 2*theta + path delay difference= (Tr-ts)+(Ts-tr) Where Tr = request received by time server. ts=request sent by computer. Ts=reply sent from time server tr=computer receives time server reply The above is derived by equating absolute times for the messages at the computer and the server. If e is the time error in the computer, and Ta is the network delay in the path from computer to server, and Tb is the network delay in the path from server to computer, then (e+ts)+Ta=Tr And (e+tr)=Tb+Ts Total network delay being given by (Tr-ts)-(Ts-tr) (2×e)+(Ta-Tb)=(Tr-ts)+(Ts-tr) Thus the time error can only be calculated if Ta=Tb. Which is the bit that bothers me. Where the above Tr, ts, Ts, tr are the only known time values at the computer end of the link. The time error e, is a common value that may be positive, or negative.
@atomic14
@atomic14 2 жыл бұрын
@@nigeljohnson9820 That's correct - there is an assumption that the network delay is symmetrical. That's why it can be important that you connect to an NTP server that is close to you in terms of network hops - fewer hops mean less chance that the routes from and to your computer will differ. A lot of systems will use multiple time servers and will sample them continuously to find the most "stable" source of time.
@nigeljohnson9820
@nigeljohnson9820 2 жыл бұрын
@@atomic14 I looked at the full protocol for NTP. It is remarkable involved. I assume that the difference error between go and return can be eliminated by statistically looking for a minimum error in the clock signal, as this corresponds to Ta=Tb, that is symmetry in the delay of the go and return signal. I find it amazing that NTP can achieve such high levels of accuracy, given that such digital networks memory buffer the data. I worked on the design of digital telecom systems, but we were forced to resort to using clock signals derived from GPS, with a time sync calculated from the UTC clock signal. This proved a problem when the GPS epoch changed.
@jumadhaheri
@jumadhaheri 2 жыл бұрын
I’ve made a 34cm wall clock with ws2812, this is my largest pcb I’ve ever made similar concept
@atomic14
@atomic14 2 жыл бұрын
Nice! That is a big PCB.
@andymouse
@andymouse 2 жыл бұрын
Useful...cheers.
@atomic14
@atomic14 2 жыл бұрын
Thanks!
@kissingfrogs
@kissingfrogs 2 жыл бұрын
and to remember the port number its like a time beat 123 123 123 123 ... I often wonder if that was intentional
@atomic14
@atomic14 2 жыл бұрын
That would not surprise me. The ancients of the internet did do all sorts of fun things.
@markrandall8487
@markrandall8487 2 жыл бұрын
123 was always the phone number for the speaking clock as well...
@kissingfrogs
@kissingfrogs 2 жыл бұрын
@@atomic14 No doubt one of those being RFC 1149 which is always fun. Not sure how it would go carrying NTP. Send enough with averaging perhaps.
@atomic14
@atomic14 2 жыл бұрын
That is amazing - I had no idea they had done that :)
@atomic14
@atomic14 2 жыл бұрын
@@markrandall8487 That really does take me back. To the days when listening to the speaking clock passed as entertainment for a child - simpler times :)
@AdityaMehendale
@AdityaMehendale 2 жыл бұрын
Cool expo. Although you likely put a lot of thought and effort into it, imho the "stock footage" clips shall get kitsch pretty soon. It's a different when they are in "today I found out" or such, but out of place in a topical channel for EEs, such as yours.
@atomic14
@atomic14 2 жыл бұрын
Thanks - it’s always difficult to tread the line between information and entertainment. I felt this topic was a bit dry so needed a bit of spicing up. There’ll be some more EE focussed videos soon which hopefully will be entertaining in themselves.
ESP-Now Range Test: Real-World Results for ESP32 Devices!
8:01
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН
I'VE MADE A CUTE FLYING LOLLIPOP FOR MY KID #SHORTS
0:48
A Plus School
Рет қаралды 20 МЛН
ESP32 Audio Input Using I2S and Internal ADC
10:43
atomic14
Рет қаралды 134 М.
How Good Are My USB Cables?
8:11
atomic14
Рет қаралды 88 М.
Revolutionize Your ESP32 Projects with Live GPIO Pin Monitoring!
8:08
The Last Outpost Workshop
Рет қаралды 193 М.
ESP32-TV Version 3 - Is it done?
13:51
atomic14
Рет қаралды 63 М.
#328 ESP32 Secrets: Interrupts, and Deep-Sleep under the Hood
18:57
Andreas Spiess
Рет қаралды 180 М.
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.