30 lines
839 B
C++
30 lines
839 B
C++
#pragma once
|
|
|
|
#include <NTPClient.h>
|
|
#include <WiFiUdp.h>
|
|
#include <Timezone.h>
|
|
|
|
namespace Ntp {
|
|
|
|
WiFiUDP ntpUDP;
|
|
NTPClient timeClient(ntpUDP, "192.168.6.1");
|
|
|
|
// Central European Time (Frankfurt, Paris)
|
|
TimeChangeRule CEST = { "CEST", Last, Sun, Mar, 2, 120 }; // Central European Summer Time
|
|
TimeChangeRule CET = { "CET ", Last, Sun, Oct, 3, 60 }; // Central European Standard Time
|
|
Timezone CE(CEST, CET);
|
|
|
|
Task tUpdateTime(TASK_IMMEDIATE, TASK_ONCE,
|
|
[] {
|
|
if (timeClient.forceUpdate()) {
|
|
time_t newTime = CE.toLocal(timeClient.getEpochTime());
|
|
setTime(newTime);
|
|
Serial.println(asctime(localtime(&newTime)));
|
|
}
|
|
}, &ts);
|
|
|
|
void setup() {
|
|
Serial.println("NTP setup");
|
|
timeClient.begin();
|
|
}
|
|
} |