pitrix/src/ntp.cpp

27 lines
624 B
C++
Raw Normal View History

#include <sntp.h>
#include <coredecls.h>
#include <time.h>
#include <TZ.h>
#include "my_fastled.h"
/*void updateCallback(NTPClient* c) {
random16_add_entropy(c->getEpochMillis() & 0xFFFF);
LOGln("Received current time. Epoch is %lu.", ntpClient.getEpochTime());
}*/
void time_changed() {
random16_add_entropy(millis() & 0xFFFF);
time_t now;
tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
char time_s[30];
strftime(time_s, 30, "%a %d.%m.%Y %T", &timeinfo);
LOGln("NTP * Received time: %s", time_s);
}
void ntp_setup() {
settimeofday_cb(time_changed);
configTime(TZ_Europe_Berlin, "de.pool.ntp.org");
}