LoRa_APRS_iGate/src/ntp_utils.cpp

33 lines
789 B
C++
Raw Normal View History

2024-10-14 16:44:22 +02:00
#include <NTPClient.h>
#include <WiFiUdp.h>
#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() {
if (!Config.digi.ecoMode && Config.callsign != "NOCALL-10") {
int gmt = Config.ntp.gmtCorrection * 3600;
timeClient.setTimeOffset(gmt);
timeClient.begin();
}
}
void update() {
if (!Config.digi.ecoMode && Config.callsign != "NOCALL-10") timeClient.update();
}
String getFormatedTime() {
if (!Config.digi.ecoMode) return timeClient.getFormattedTime();
return "DigiEcoMode Active";
}
}