2024-10-14 16:44:22 +02:00
|
|
|
#include <NTPClient.h>
|
|
|
|
|
#include <WiFiUdp.h>
|
2024-10-14 22:04:28 +02:00
|
|
|
#include <WiFi.h>
|
2024-10-14 16:44:22 +02:00
|
|
|
#include "configuration.h"
|
|
|
|
|
#include "ntp_utils.h"
|
|
|
|
|
#include "time.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern Configuration Config;
|
|
|
|
|
|
|
|
|
|
WiFiUDP ntpUDP;
|
|
|
|
|
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 15 * 60 * 1000); // Update interval 15 min
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace NTP_Utils {
|
|
|
|
|
|
|
|
|
|
void setup() {
|
2024-10-14 22:04:28 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED && !Config.digi.ecoMode && Config.callsign != "NOCALL-10") {
|
2024-10-14 16:44:22 +02:00
|
|
|
int gmt = Config.ntp.gmtCorrection * 3600;
|
|
|
|
|
timeClient.setTimeOffset(gmt);
|
|
|
|
|
timeClient.begin();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update() {
|
2024-10-14 22:04:28 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED && !Config.digi.ecoMode && Config.callsign != "NOCALL-10") timeClient.update();
|
2024-10-14 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getFormatedTime() {
|
|
|
|
|
if (!Config.digi.ecoMode) return timeClient.getFormattedTime();
|
|
|
|
|
return "DigiEcoMode Active";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|