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

.update() liefert niemals true #21

Open
gitzila opened this issue Jan 2, 2023 · 9 comments
Open

.update() liefert niemals true #21

gitzila opened this issue Jan 2, 2023 · 9 comments

Comments

@gitzila
Copy link

gitzila commented Jan 2, 2023

Hallo Stefan,

habe Deine NTP-Bibliothek in mein Projekt eingebunden. Danke für Deine Arbeit und die Veröffentlichung. Leider bekomme ich von der Methode .update() niemals true zurück.

Definitionen im Kopf des Sketch:

#include "NTP.h"
#include "WiFiUdp.h"
WiFiUDP wifiUdp;
NTP timeClient(wifiUdp);
String letztesNTPUpdate;
boolean erfolgLetztesNTPUpdate;

Im setup() habe ich diesen Code:

timeClient.ruleDST("CEST", Last, Sun, Mar, 2, 120); // last sunday in march 2:00, timetone +120min (+1 GMT + 1h summertime offset)
timeClient.ruleSTD("CET", Last, Sun, Oct, 3, 60); // last sunday in october 3:00, timezone +60min (+1 GMT)
timeClient.updateInterval(1000 * 60 * 30); // Update alle 30 Minuten
timeClient.begin("10.0.0.1"); // Router im LAN stellt NTP bereit
erfolgLetztesNTPUpdate = timeClient.update(); 
letztesNTPUpdate = tc.formattedTime("%H:%M:%S");

Im loop() dieses:

erfolgLetztesNTPUpdate = timeClient.update();
if (erfolgLetztesNTPUpdate) {
  letztesNTPUpdate = tc.formattedTime("%H:%M:%S");
}

Den Inhalt der Variable letztesNTPUpdate lasse ich mir dann auf einer generierten HTML-Seite vom Webserver, der auf dem ESP läuft anzeigen. Doch auch nach nun einigen Stunden bleibt der Inhalt der Variable letztesNTPUpdate auf dem Stand beim Start des ESP. Anscheinend erhalte ich nie true von .update() zurück. Die gesetzte Uhrzeit im timeClient ist aber korrekt und stimmt +-1 Sekunde mit der "richtigen" Zeit überein.

Wo mache ich einen Fehler?

Grüße

Frank

@sstaub
Copy link
Owner

sstaub commented Jan 2, 2023

Dies liegt unter Umständen daran, dass die Verbindung zum Server abgerissen ist, bzw. die Netzwerkverbindung unterbrochen worden ist.

@hedva92
Copy link

hedva92 commented Feb 8, 2023

I have a similar problem. It keeps time, but after a few hours it updates to a meaningless value (a few days into the future and the time will change as well). Wifi is OK because it runs on my ESP server and responds regularly every second. Tried other timeservers but same problem. Otherwise, the library is great. The question why does it update to a meaningless value after a while?

@sstaub
Copy link
Owner

sstaub commented Feb 8, 2023

Sorry but I didn't know why it happens.

@hedva92
Copy link

hedva92 commented Feb 8, 2023

Sorry but I didn't know why it happens.

To add, I modified your logic in ntp.update. If the time until the update has not passed, the function returns -1, if it is kosher it returns true (default), if it is a problem the function returns false. It is precisely because of error catching that if it does not load the correct data, the ESP will get the time from the RTC. However, the problem will be somewhere else, because even with this modification, the wrong time was set, so the update function returned true. I perform a time update once every 10 minutes to local esp time variable

@sstaub
Copy link
Owner

sstaub commented Feb 8, 2023

If you find a final solution can you make a PR? Maybe you log the NTP packets to see if the wrong data comes from the time server.

@hedva92
Copy link

hedva92 commented Feb 8, 2023

If you find a final solution can you make a PR? Maybe you log the NTP packets to see if the wrong data comes from the time server.

I will try to upload a piece of code to the second esp32 connected to a different network (at work) and see if there will be a difference, or the ntp packet log.

@redoxcode
Copy link
Contributor

Hi Frank,
I had the same problem and I think it's my wi-fi router disconnecting my hardware after a few hours. Maybe it expects to be pinged more often or my hardware doesn't respond to pings the way my router would like?
Anyway, my solution was to just quit the connection and reconnect when there was no successful update for some time.
I think I am doing the update once per hour, btw. But doing it at startup and once a day should be more than enough...

@g6094199
Copy link

g6094199 commented Nov 7, 2023

+1
same problem on arduino mkr1010

@g6094199
Copy link

g6094199 commented Jul 1, 2024

i always get ntp status = 0 . even on reboots where mqtt and other stuff connects fine.

Starting NTP ... Try to get time from: 2.europe.pool.ntp.org NTP update status: 0 (bool: 0 = false; 1 = true) No NTP reply. Lets try again: 1 No NTP reply. Lets try again: 2 No NTP reply. Break and go on for now. Current NTP time and date: 01/01/1970 01:00:48

on recurring ntp poll a view minutes later i get the time, but status stays 0

`
Update NTP:
0
NTP update failed. Reinit NTP/RTC.

Starting NTP ...
Try to get time from: 2.europe.pool.ntp.org
NTP update status: 0 (bool: 0 = false; 1 = true)
No NTP reply. Lets try again: 1
No NTP reply. Lets try again: 2
No NTP reply. Break and go on for now.
Current NTP time and date: 01/07/2024 16:51:57
`

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

No branches or pull requests

5 participants