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

configTime ignores timezone in rc2 #3774

Closed
dragondaud opened this issue Oct 30, 2017 · 6 comments
Closed

configTime ignores timezone in rc2 #3774

dragondaud opened this issue Oct 30, 2017 · 6 comments

Comments

@dragondaud
Copy link
Contributor

Hardware

Hardware: ESP-12
Core Version: 2.4.0-rc2

Description

After upgrading from 2.4.0-rc1 to 2.4.0-rc2, I noticed the timezone parameter seems to be ignored by configTime, and ctime() returns only GMT. The included sketch demonstrates this problem, and when compiled with rc1 or earlier it shows the correct time output, based on TZ setting. In rc2, the same sketch shows only GMT. If there is an expected change in behavior, I could find no documentation.

Settings in IDE

Module: NodeMCU 1.0
Flash Size: 4MB/1MB
CPU Frequency: 80Mhz
Upload Using: SERIAL

Sketch

#include <ESP8266WiFi.h>
#include <time.h>

#define WIFI_SSID "SSID"
#define WIFI_PASS "PASS"
#define TZ -6

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println();
  Serial.print("Last reset: ");
  Serial.println(ESP.getResetReason());
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  Serial.print("...");
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("Synchronize with NTP...");
  configTime((TZ * 3600), 0, "pool.ntp.org", "time.nist.gov");
  while (!time(nullptr)) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {
  time_t now = time(nullptr);
  String t = ctime(&now);
  t.trim();                       // ctime() output ends with \n, bug?
  long heap = ESP.getFreeHeap();
  Serial.print(heap);
  Serial.print(" free heap @ ");
  Serial.print(t);
  Serial.println();
  delay(5000);
}
@5chufti
Copy link
Contributor

5chufti commented Oct 31, 2017

since there are more than one time lib and the only one distributed via library manager does not have configTime()
we don't know what dependencies could be the culprit, maybe it is just a time.h conflict.
As a/the time lib is not part of the arduino esp8266 core, there most probably are other places to get this fixed as a cleanly implemented time lib should not be affected by change of esp8266 sdk.

@dragondaud
Copy link
Contributor Author

Looks like its part of the core to me:

./cores/esp8266/time.c:void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)

@dragondaud
Copy link
Contributor Author

dragondaud commented Oct 31, 2017

@d-a-v just noticed this bug only occurs when I'm using lwip2v2 from #3362 but not if I switch back to lwipv1.4.

@d-a-v
Copy link
Collaborator

d-a-v commented Oct 31, 2017

@dragondaud thanks for reporting. This is now fixed and verified with your sketch.

@5chufti
Copy link
Contributor

5chufti commented Oct 31, 2017

@dragondaud: sorry, never thought on looking there.
For a 3rd party lib to arduino standards I think it is in the wrong place and should be found somewhere like /esp8266/libraries/time

@devyte
Copy link
Collaborator

devyte commented Nov 1, 2017

Closing, as the issue is in an unmerged PR, and also seems to be already fixed. If there are further comments about the time issue in lwop2, please comment in the PR itself.

@devyte devyte closed this as completed Nov 1, 2017
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

4 participants