Skip to content

sntp_set_timezone_in_seconds doesn't seem to have any effect #6678

@osmtools

Description

@osmtools

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12E (LoLin NodeMCU V3)
  • Core Version:ba50bd5
  • Development Env: Arduino IDE 1.8.10
  • Operating System: Ubuntu LTS 18.04.2

Settings in IDE

  • Module: NodeMCU 1.0 (ESP-12E Module)
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

No matter what value I assign to the timezone_sec arg in

void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)

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

static sint32 time_zone = 8 * (60 * 60); // espressif HQ's default timezone

to 0 instead, then you will get the time in GMT/UTC.

It seems that the method

bool sntp_set_timezone_in_seconds(sint32 timezone)

hasn't any effect to the global variable time_zone

Also have a look at #6675

MCVE Sketch

#include <ESP8266WiFi.h> #include <time.h> const char* ssid = "..."; const char* password = "..."; const int timezone_sec = 0; const int daylightOffset_sec = 0; const char* ntpServer = "pool.ntp.org"; void setup() { Serial.begin(115200); Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED"); Serial.println("Call configTime..."); configTime(timezone_sec, daylightOffset_sec, ntpServer); 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 loop() { } 

Debug Messages

Run at Mon Oct 28 08:03:51 2019 (GMT/UTC)

Connecting to xxx ....... CONNECTED Call configTime... Now it's: 1572275031 Mon Oct 28 15:03:51 2019 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions