-
Notifications
You must be signed in to change notification settings - Fork 10
First NTP sync is wrong #5
Comments
Hard to tell from what you describe. Can you run your code with Cheers! Sacha |
Hej thanks |
aha I need to enable Debug during compile will test that now |
Nope still nothing from ntp I have |
Hej [NTP] NTP Server #0 set to: 192.168.1.1. Looks like the first timestamp always is 28802 after some minutes it got real timestamp back. Not sure how to proceed. |
I can see that you are using a local NTP server. Have you tried using another NTP server (public) to see if you have the same behavior? I don't recall that I had this issue with my NTP server. Since I haven't used it in a while, I need to create a setup again to verify this. :) |
Hej What I read it should set the sync interval to 5 but here it prints out 60? [NTP] NTP Server #0 set to: ntp.bahnhof.se. |
Not sure I follow what your are doing. However, let me try to replicate on my own setup. |
Hej I did this changed two lines.
|
I used my own setup (ESP8266 chip) and get the following output after initial start:
Using the standard example with this library. I tried also with my own private NTP server and a public one, however same results. It looks indeed that on your side the NTP synchronization doesn't take place immediately, although the connection has been established. That would explain the date of '1970-01-01....', as the internal time variable has not been changed yet. Not sure what I can do to further help you. Could you maybe try another ESP8266 device? Just to rule that out... |
Hej What HW are you using?
|
I have various ESP8266 boards (Wemos D1, Adafruit Huzzah ESP8266, NodeMCU, etc.). All work fine for me. |
I am running the latest ESP 2.4.0 release and Arduino 1.8.5. |
It is correct that the SNTP protocol has less accuracy and reliability. The ESP library encompasses an NTP implementation, which may explain the faster sync. (See also: https://www.meinbergglobal.com/english/faq/faq_37.htm) In most cases SNTP is sufficient. If you really need higher accuracy and reliability, then NTP is recommended over SNTP. |
For completeness, I tried another board (NodeMCU v3) with the same code. I get the same output:
Not sure how I can further be of assistance, as I am not able to replicate the issue you are experiencing. |
What version of ESP8266 lib/tools are you using? |
I was actually using 2.3.0 of the ESP8266 framework (hadn't noticed it already moved to 2.4.0). After upgrading, I can also confirm the same behaviour. Something must have been changed in 2.4.0 that causes this. Need to do some investigation... |
Thanks! So actually this lib is no longer needed or needs to be rewritten. You can follow the discussion here esp8266/Arduino#4122 I did not manage to debug lwip since I was using lwip2 :) |
After doing some investigation, it indeed seems the implementation in 2.4.0 makes this library to be redundant :( Not sure if I will rewrite it or discontinue... |
Yes I would like to use TimeAlarms that is dependent on TimeLib but if we do not actually need the Timelib I wonder how I easily can create TimeAlarms. I updated my sketch using this in the setup
Adding this function
It updates the time direct... |
Sorry, I'm not familiar with these Timelib and TimeAlarms libraries. |
Its the same as you are using. :) Line 17 in 8bd5ebb
TimeAlarms need the TimeLib to work. |
Sorry yes, you used small caps so I thought it was a different library. TimeAlarms I'm not familiar with. Your example looks indeed nice and simple, making my library totally redundant, haha. |
Yes and DST works directly without any extra lib or so. |
You too for pointing this out. Maybe it's time to retire this library :( (Which is good thing, because there were already many NTP libraries and now the missing features I was looking for, are incorporated in ESP8266). |
Interestingly I get a similar output when using the NTP-TZ-DST.ino example of ESP 2.4.0:
Also displays initially the time of 01/01/1970 (ctime) :) |
Hej Yes I have also noticed that but for me it gets sync almost direct and I have added a wait for wifi before printing that helps get the initial sync. |
True. Well the ESP2.4.0 library contains the perfect features for time synchronization, so I've decided to retire this library. No need to keep it maintained now anylonger :) |
I can confirm that the problems described in the first post of this issue:
|
Hej
I am testing your code on a SonOff Th10 but I have a slight problem the first sync gives me the wrong time.
Serial print follows
`MDNS responder started
HTTP server started
....Got IP: 192.168.1.21
Got NTP time: 1970-01-01T00:00:08 last sync 1970-01-01T09:00:02
Got NTP time: 1970-01-01T09:01:02 last sync 2018-01-08T14:57:02
Got NTP time: 2018-01-08T14:58:03 last sync 2018-01-08T14:58:04
Got NTP time: 2018-01-08T14:59:05 last sync 2018-01-08T14:59:05
`
I have changed to print out the current time also.
`
case NTP_EVENT_SYNCHRONIZED:
Serial.printf("Got NTP time: %s last sync %s\n", NTP.getTimeDate(now()), NTP.getTimeDate(NTP.getLastSync()));
break;`
Any ideas whats going on. The NTP server works when using regular ntpdate so thats not the issue.
I was thinking maybe I could force the update in setup but gettime is private so that is not an option at this stage.
cheers
The text was updated successfully, but these errors were encountered: