Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sntp: use one time source and fix unsynchronized sntp time stamp #7595

Merged
merged 7 commits into from
Sep 12, 2020

Conversation

d-a-v
Copy link
Collaborator

@d-a-v d-a-v commented Sep 12, 2020

  • move useful functions from sntp-lwip2.cpp files to time.cpp, remove the first
  • "sntp real time stamp" management is removed:
    • one less os_timer
    • it didn't allow synchronization of the full time API
      (time() was not synchronized with gettimeofday()'s tv_sec & tv_usec)

also minor fix for CI compiler flags.

edit: example

Before this PR, with updated NTP-TZ-DST example,
on last line with "<-- second changed", system function time() and gettimeofday() are not synchronized.

16:16:00.752971213 localtime: isdst=1 yday=255 wday=6 year=120 mon=8 mday=12 hour=15 min=16 sec=0
16:16:00.760816407 gmtime:    isdst=0 yday=255 wday=6 year=120 mon=8 mday=12 hour=14 min=16 sec=0
16:16:00.769484560 clock:     7s / 139481000ns
16:16:00.777284078 millis:    7139
16:16:00.784749753 micros:    7139501
16:16:00.791351114 gtod:      1599920160s / 663763us
16:16:00.798425014 time:      1599920160
16:16:00.805655379 timezone:  GMT0BST,M3.5.0/1,M10.5.0
16:16:00.813127963 ctime:     Sat Sep 12 15:16:00 2020
16:16:00.821596885 sntp0:     10.0.1.254 IPv6: No Reachability: 1
16:16:00.827925501 
16:16:00.836309002 time(): 1599920160   gettimeofday(): 1599920160.699017  second unchanged
16:16:00.843256885 time(): 1599920160   gettimeofday(): 1599920160.755456  second unchanged
16:16:00.852054825 time(): 1599920160   gettimeofday(): 1599920160.806042  second unchanged
16:16:00.870771509 time(): 1599920160   gettimeofday(): 1599920160.856501  second unchanged
16:16:00.920584101 time(): 1599920160   gettimeofday(): 1599920160.907156  second unchanged
16:16:00.971140838 time(): 1599920160   gettimeofday(): 1599920160.957609  second unchanged
16:16:01.021199767 time(): 1599920160   gettimeofday(): 1599920161.008199  <-- second changed 
16:16:01.064865923 

With this PR, time(), gettimeofday() and other libc functions have the same time source.

16:34:27.130753975 localtime: isdst=1 yday=255 wday=6 year=120 mon=8 mday=12 hour=15 min=34 sec=27
16:34:27.137778554 gmtime:    isdst=0 yday=255 wday=6 year=120 mon=8 mday=12 hour=14 min=34 sec=27
16:34:27.145699538 clock:     7s / 119659000ns
16:34:27.152986545 millis:    7119
16:34:27.160393772 micros:    7119684
16:34:27.168077945 gtod:      1599921267s / 75418us
16:34:27.175523564 time:      1599921267
16:34:27.181491234 timezone:  GMT0BST,M3.5.0/1,M10.5.0
16:34:27.188683292 ctime:     Sat Sep 12 15:34:27 2020
16:34:27.195727888 sntp0:     10.0.1.254 IPv6: No Reachability: 1
16:34:27.203593279 
16:34:27.211198888 time(): 1599921267   gettimeofday(): 1599921267.110768  second unchanged
16:34:27.218413329 time(): 1599921267   gettimeofday(): 1599921267.167200  second unchanged
16:34:27.225694226 time(): 1599921267   gettimeofday(): 1599921267.217642  second unchanged
16:34:27.251604647 time(): 1599921267   gettimeofday(): 1599921267.268252  second unchanged
16:34:27.301489041 time(): 1599921267   gettimeofday(): 1599921267.318696  second unchanged
16:34:27.351750685 time(): 1599921267   gettimeofday(): 1599921267.369280  second unchanged
16:34:27.402388179 time(): 1599921267   gettimeofday(): 1599921267.419833  second unchanged
16:34:27.452420738 time(): 1599921267   gettimeofday(): 1599921267.470428  second unchanged
16:34:27.503847309 time(): 1599921267   gettimeofday(): 1599921267.520876  second unchanged
16:34:27.554389393 time(): 1599921267   gettimeofday(): 1599921267.571441  second unchanged
16:34:27.604114326 time(): 1599921267   gettimeofday(): 1599921267.621890  second unchanged
16:34:27.654529599 time(): 1599921267   gettimeofday(): 1599921267.672472  second unchanged
16:34:27.705583152 time(): 1599921267   gettimeofday(): 1599921267.722921  second unchanged
16:34:27.756291619 time(): 1599921267   gettimeofday(): 1599921267.773486  second unchanged
16:34:27.806815447 time(): 1599921267   gettimeofday(): 1599921267.823935  second unchanged
16:34:27.857165349 time(): 1599921267   gettimeofday(): 1599921267.874520  second unchanged
16:34:27.907289482 time(): 1599921267   gettimeofday(): 1599921267.924969  second unchanged
16:34:27.957837938 time(): 1599921267   gettimeofday(): 1599921267.975537  second unchanged
16:34:28.010159178 time(): 1599921268   gettimeofday(): 1599921268.025986  <-- second changed
16:34:28.052279993 

@d-a-v d-a-v merged commit 40eb574 into esp8266:master Sep 12, 2020
@d-a-v d-a-v deleted the simpletime branch September 12, 2020 16:22
Jason2866 added a commit to Jason2866/Arduino that referenced this pull request Sep 17, 2020
Jason2866 added a commit to Jason2866/Arduino that referenced this pull request Sep 17, 2020
Jason2866 added a commit to Jason2866/Arduino that referenced this pull request Sep 17, 2020
Jason2866 added a commit to Jason2866/Arduino that referenced this pull request Sep 17, 2020
Jason2866 added a commit to Jason2866/Arduino that referenced this pull request Sep 17, 2020
Jason2866 added a commit to Jason2866/Tasmota that referenced this pull request Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant