NTP Zeit immer eine Stunde zu hoch

Hallo,

NTP funktioniert soweit ganz gut, aber die Uhrzeit wird immer mit einer Stunde zuviel angezeigt.
Hab´s schon mehrfach gecheckt, fnde aber den Fehler nicht.

Die eigentliche Definition der Zeitzone scheint zu stimmen.
habt ihr eine Idee?
LG

//  im Definitionsteil
// ------------------------ NTP ------------------------------
//#include <WiFi.h>
#include "time.h"
#include "sntp.h"                             // Bsp von der library
const char* ntpServer1 = "fritz.box";         // die eigene Fritz box
const char* ntpServer2 = "pool.ntp.org";      // offizieller NTP Server
const long  gmtOffset_sec = 3600;
const int   daylightOffset_sec = 3600;
const char* time_zone = "CET-1CEST,M3.5.0,M10.5.0/3";  // M3.5.0: 3 = 3rd month, 5 =last 0 = sunday,   M10.5.0 = last sunday in 19th month ;  TimeZone rule for Europe/Rome including daylight adjustment rules (optional)


// im Setup:   ===============================

NTPStart();                      // ist vor dem IPStart          



// im  Loop:   =================================

void NTPStart() {

  // set notification call-back function
  sntp_set_time_sync_notification_cb( timeavailable );

  /*
   * NTP server address could be aquired via DHCP,
   *
   * NOTE: This call should be made BEFORE esp32 aquires IP address via DHCP,
   * otherwise SNTP option 42 would be rejected by default.
   * NOTE: configTime() function call if made AFTER DHCP-client run
   * will OVERRIDE aquired NTP server address
   */
  sntp_servermode_dhcp(1);    // (optional)

  /*
   * This will set configured ntp servers and constant TimeZone/daylightOffset
   * should be OK if your time zone does not need to adjust daylightOffset twice a year,
   * in such a case time adjustment won't be handled automagicaly.
   */
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);

  /*
   * A more convenient approach to handle TimeZones with daylightOffset 
   * would be to specify a environmnet variable with TimeZone definition including daylight adjustmnet rules.
   * A list of rules for your zone could be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
   */
  //configTzTime(time_zone, ntpServer1, ntpServer2);


}   // end void


void getLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println(F("NTP Zeit noch nicht verfügbar"));
    return;
  }
  //Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");  // %A = Tag mit Namen - zB Montag
  //if (imsetup == true) {Serial.print("ZEITABFRAGE: "); Serial.println(&timeinfo, "%B %d %Y %H:%M:%S");}
  // alle fix ------------------------ Zeit/Datum von NTP in Variablen übernehmen --------------------------

  ntpsek = timeinfo.tm_sec;
  ntpmin = timeinfo.tm_min;
  ntpstd = timeinfo.tm_hour;  // ###  -1??  im winter -1 , Achtung uint_16 nach mitternacht
  ntptag = timeinfo.tm_mday;
  ntpmonat = timeinfo.tm_mon + 1;
  ntpjahrkurz = timeinfo.tm_year - 100; 
  ntpjahr = timeinfo.tm_year + 1900;
  ntpdaylightsavingflag = timeinfo.tm_isdst;
        
 /*   
|Member|Type|Meaning|Range|
|tm_sec|`int`|seconds after the minute|`0-60*`|
|tm_min|`int`|minutes after the hour|`0-59`|
|tm_hour|`int`|hours since midnight|`0-23`|
|tm_mday|`int`|day of the month|`1-31`|
|tm_mon|`int`|months since January|`0-11`|
|tm_year|`int`|years since 1900|``|
|tm_wday|`int`|days since Sunday|`0-6`|
|tm_yday|`int`|days since January 1|`0-365`|
|tm_isdst|`int`|Daylight Saving Time flag|   The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
 zB. int meineSec = timeinfo.tm_sec;
*/

  } // end void


// Callback function (get's called when time adjusts via NTP)
void timeavailable(struct timeval *t)
{
  Serial.println(F("Zeitupdate von NTP erhalten!"));
  ntptimevorhanden = true;
  getLocalTime();
}  // end void


"CET-1CEST,M3.5.0/02,M10.5.0/03"
Versuch damit

spiel nicht mit den offsets rum wenn du eh eine Timezone setzt.

das funktioniert sicherlich für den ESP32:

https://werner.rothschopf.net/microcontroller/202103_arduino_esp32_ntp_en.htm

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