1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- bool setupTime()
- {
- if (strlen(confTime.ntpServer1) > 4 && strlen(confTime.ntpServer2) > 4)
- {
- //configTime(gmtOffset_sec, daylightOffset_sec, ntpServer [, ntpServer2[, ntpServer3]]);
- configTime(0, 0, confTime.ntpServer1, confTime.ntpServer2);
- }
- else if (strlen(confTime.ntpServer1) > 4)
- {
- configTime(0, 0, confTime.ntpServer1);
- }
- else return false;
- setenv("TZ", confTime.timeZoneStr, 1); // Zeitzone einstellen https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
- return true;
- }
- void updateTimeFromNTP()
- {
- time_t now = time(&now);
- static time_t lastsek{0};
- if (lt.tm_sec != lastsek)
- {
- lastsek = lt.tm_sec;
- if (!(time(&now) % confTime.ntpSyncInterval))
- {
- //Serial.println("updating time from NTP server");
- sendLog(F("NTP: updating time"), LOGLEVEL_INFO);
- setupTime();
- }
- }
- }
- void updateTime() {
- time_t now = time(&now);
- localtime_r(&now, <);
- }
- // char getDateTime() {
- // char* buf[30]; // je nach Format von "strftime" eventuell anpassen
- // time_t now = time(&now);
- // localtime_r(&now, <);
- // strftime(&buf, sizeof(buf), "%Y-%m-%d %T", <); // http://www.cplusplus.com/reference/ctime/strftime/
- // return buf;
- // }
- // char getDate() {
- // char buf[13];
- // updateTime();
- // strftime(buf, sizeof(buf), "%d.%m.%Y", <); // http://www.cplusplus.com/reference/ctime/strftime/
- // //return buf;
- // }
- // char getDate_YMD() {
- // char* buf[13];
- // time_t now = time(&now);
- // localtime_r(&now, <);
-
- // strftime(&buf, sizeof(buf), "%Y-%m-%d", <); // http://www.cplusplus.com/reference/ctime/strftime/
- // return buf;
- // }
- // char getTime() {
- // char* buf[6];
- // time_t now = time(&now);
- // localtime_r(&now, <);
-
- // strftime(&buf, sizeof(buf), "%H:%M", <); // http://www.cplusplus.com/reference/ctime/strftime/
- // return buf;
- // }
- // char getTime_HMS() {
- // char* buf[9];
- // time_t now = time(&now);
- // localtime_r(&now, <);
-
- // strftime(&buf, sizeof(buf), "%H:%M:%S", <); // http://www.cplusplus.com/reference/ctime/strftime/
- // return buf;
- // }
- /*void printTimeToSerial()
- {
- static char buf[30]; // je nach Format von "strftime" eventuell anpassen
- time_t now = time(&now);
- localtime_r(&now, <);
- //gmtime_r(&now, &utc);
- strftime(buf, sizeof(buf), "%Y-%m-%d %T", <); // http://www.cplusplus.com/reference/ctime/strftime/
- //Serial.printf("%s %s", buf, dayShortNames[lt.tm_wday]);
- Serial.printf("%s", buf);
- Serial.println();
- //Serial.printf("UTC: %.2d:%.2d:%.2d\n", utc.tm_hour, utc.tm_min, utc.tm_sec);
- //Serial.printf("%s: %.2d:%.2d:%.2d %s\n\n", *tzname, lt.tm_hour, lt.tm_min, lt.tm_sec, lt.tm_isdst ? "Sommerzeit" : "Normalzeit");
- }*/
|