-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
configTime() not working #4749
Comments
So what makes you think this is a ESP8266/Arduino problem? (a problem with this repository) Nothing you have posted here indicates anything other than that you have a problem.
And how is someone supposed to do anything with that? If you are going to post your code then provide a complete simplified sketch. But keep in mind that this is not an I need help forum. See #3 in https://github.com/esp8266/Arduino/blob/master/POLICY.md And that seems to be what your issue is. The following is a minimal example of a working sketch using configTime()
And its output
|
Most of the time it is a DNS problem. Try directly with the IP of your DNS server. And as RudyFiero says ... it's not a problem with this repository. |
Youre absolutely right guys. My (newbie) mistake. Issue closed. |
I've experienced such "01-01-1970 09:00:00" situations before as well. The workaround was to query Serial.println("Syncing time...");
configTime(0, 0, "pool.ntp.org");
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 0);
while(time(nullptr) <= 100000) {
Serial.print(".");
delay(100);
} |
Time is coming from ntp servers some time after the request. (this example needs rework though, |
In case someone else comes here looking for help on time, here's something I created based on a variety of tips and samples elsewhere.... (in this case, Pacific time) - that first checks if the time is already set, then tries to set network time, then resorts to a hard-coded epoch time (could possibly have a web service providing epoch time, too)
|
For those who may need it: just call configtime in setup(), it can even be called before the wifi begin. Throw and forget. |
A further reference point is the full-monty bells'n whistles example at https://github.com/esp8266/Arduino/blob/master/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino. For most developers the only relevant lines are 254-264. In my experience |
Should an example with this single configuration line be setup in the example repository ? |
Hi,
I have some weird issues with configTime. I have two different sketches, both using the same function to initialise the network and do a sync with NTP. Only on one sketch it works fine, time is updated, other sketch the time defaults to 01-01-1970 09:00:00.
Even a recurrent configTime() (every few minutes) doesn't update.
Network connectivity is normal, i can access the ESP, no issues there.
Is there anyway to debug the configTime function?
Here's the abbreviated code parts;
#define NTP_SERVERS "0.nl.pool.ntp.org", "1.nl.pool.ntp.org", "2.nl.pool.ntp.org"
#define UTC_OFFSET +1
struct dstRule StartRule = {"CEST", Last, Sun, Mar, 2, 3600}; // Central European Summer Time = UTC/GMT +2 hours
struct dstRule EndRule = {"CET", Last, Sun, Oct, 2, 0}; // Central European Time = UTC/GMT +1 hour
simpleDSTadjust dstAdjusted(StartRule, EndRule);
if (WiFi.status() == WL_CONNECTED) {
digitalWrite(LED_BUILTIN, HIGH);
DEBUG_PRINTLN(F(""));
DEBUG_PRINTLN(F("Connected successfully"));
DEBUG_PRINTLN(F(""));
DEBUG_PRINTLN(F("WiFi connected."));
if (!MDNS.begin(V_UNIT_NAME)) {
DEBUG_PRINTLN(F("Error setting up MDNS responder!"));
} else {
DEBUG_PRINT(F("MDNS Service started for http://"));
DEBUG_PRINT(V_UNIT_NAME);
DEBUG_PRINTLN(F(".local"));
}
SetupWebserver();
WebServer.begin();
DEBUG_PRINT(F("IP address: "));
DEBUG_PRINTLN(WiFi.localIP());
DEBUG_PRINT(F("Gateway: "));
DEBUG_PRINTLN(WiFi.gatewayIP());
DEBUG_PRINT(F("Server started on port:"));
DEBUG_PRINTLN(WEB_SERVER_PORT);
configTime(UTC_OFFSET * 3600, 0, NTP_SERVERS);
delay(500);
}
The text was updated successfully, but these errors were encountered: