Time library not changing from DST on ESP32

Its a lot of code so I've pasted what I believe to be the relevant bits here. The sketch has been working fine but this morning I discovered it has not changed from BST to GMT (yes I'm in the UK)
as it should have done. Grateful for any suggestions.

#include "time.h"
//  *** for ntp  ***
const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 0;
const int   daylightOffset_sec = 3600;
struct tm timeinfo;

  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);   // Init and get the time
  delay(100); //allow to get NTP time
  while (!getLocalTime(&timeinfo)) {

I wonder if changing

const char* ntpServer = "pool.ntp.org";


const char* ntpServer = "uk.pool.ntp.org";

to ensure that you get connected to a local time server would help.

You didn't set the local time environment string, like

  configTime(0, 0, "pool.ntp.org");
  setenv("TZ", "EST5EDT,M3.2.0/2,M11.1.0", 1);

...this one for New York, USA

1 Like

Thanks to both of you. I've implemented those changes;

const char* ntpServer = "uk.pool.ntp.org";
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); // Init and get the time
setenv("TZ","GMTGMT-1,M3.4.0/01,M10.4.0/02",1); //added V2.19 as staying on BST

However its STILL showing 1 hour ahead of GMT ???

Try this:

configTime(0, 0, "pool.ntp.org");  
setenv("TZ","GMTGMT-1,M3.4.0/01,M10.4.0/02",1); //added V2.19 as staying on BST

All NTP servers return time in UTC (~GMT)


or, better just the following without the setenv() expression :

configTime( "GMT0BST,M3.5.0/1,M10.5.0" , "pool.ntp.org" ); // new format

See: Arduino/NTP-TZ-DST.ino at master · esp8266/Arduino · GitHub

and ensure your timezone exactly matches that in: Arduino/TZ.h at master · esp8266/Arduino · GitHub

My bad forgot to say I'm running the code on an ESP32. Anyway
@6v6gt thanks:

no different. and

invalid conversion from 'const char*' to 'long int' [-fpermissive]

I've tried the rui santos example and it shows the same issue. Presumably because without the setenv it does not know when to change between BST &GMT

As this code is for a data logger to track the output from my solar panels, I'm thinking it might make sense just to record time as GMT all year round. They dont produce much power between midnight & 1am anyway :wink:

But - of course - I'd still like to know why its not working as is.

On ESP32 use

configTzTime("GMT0BST,M3.5.0/1,M10.5.0", "pool.ntp.org"); 

Works also on ESP8266 since core version 2.7.0.

That seems to be working. However I'm not sure there will always be 5 sundays in march or october?
I couldnt find any documentation re configTzTime.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.