-
Notifications
You must be signed in to change notification settings - Fork 13.3k
sntp_set_timezone_in_seconds doesn't seem to have any effect #6678
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
Comments
I suspect that your usage is wrong: you're supposed to wait for the time callback to fire, which happens once the time on board has actually been set from the sntp server.
If I modify the sketch to set a callback and not disconnect right after, I can see the cb firing something like 5 seconds later. CC @d-a-v . |
@devyte if i remove WiFi.disconnect(true);
WiFi.mode(WIFI_OFF); in delay(1000);
Serial.println("Now it's:");
time_t now = time(nullptr);
Serial.println(time(&now));
Serial.println(ctime(&now)); to
So the first call in |
That's because two reasons:
I updated your MCVE as follow: #include <ESP8266WiFi.h>
#include <time.h>
#include <coredecls.h>
const int timezone_sec = 0;
const int daylightOffset_sec = 0;
const char* ntpServer = "pool.ntp.org";
void time_is_set ()
{
Serial.println("Now it's:");
time_t now = time(nullptr);
Serial.println(time(&now));
Serial.println(ctime(&now));
//WiFi.disconnect(true);
//WiFi.mode(WIFI_OFF);
}
void setup()
{
Serial.begin(115200);
settimeofday_cb(time_is_set);
Serial.println("Call configTime...");
configTime(timezone_sec, daylightOffset_sec, ntpServer);
// move the two above lines after(*) "connected" below and re-run
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
// here(*)
}
void loop()
{
} But I think you'd get better results with the provided example If the example is too complex, or doesn't match the general use-case, |
@d-a-v my one question here, per my comment anf experiment above, is: assuming
then shouldn't ctime(time(nullptr)) print 00:00 instead lf 08:00? |
#include <time.h> void setup() { |
The second argument is ignored. Have you seen the provided example accessible from the arduino IDE ? edit: BTW this issue should be fixed by #6828 (already merged, available in 2.6.3) |
Is this issue still relevant ? edit will be fixed by #6993 |
* configTime(tzsec,dstsec,): fix UTC/local management This PR also remove dead code since probably newlib updates The NTP-TZ-DST example is also updated * restore sntp_set_timezone_in_seconds() fixes #6678 * +configTzTime()
Basic Infos
Platform
Settings in IDE
Problem Description
No matter what value I assign to the
timezone_sec
arg inArduino/cores/esp8266/time.cpp
Line 101 in 36c369b
the output of
time_t now = time(nullptr); Serial.println(time(&now)); Serial.println(ctime(&now));
will be UTC+8.So if i set
timezone_sec=0
i would expect the output of GMT/UTC but it won't be.If i set
Arduino/cores/esp8266/sntp-lwip2.cpp
Line 103 in 36c369b
to 0 instead, then you will get the time in GMT/UTC.
It seems that the method
Arduino/cores/esp8266/sntp-lwip2.cpp
Line 437 in 36c369b
hasn't any effect to the global variable
time_zone
Also have a look at #6675
MCVE Sketch
Debug Messages
Run at Mon Oct 28 08:03:51 2019 (GMT/UTC)
The text was updated successfully, but these errors were encountered: