2025-07-15 22:28:23 +02:00
|
|
|
/* Copyright (C) 2025 Ricardo Guzman - CA2RXU
|
|
|
|
|
*
|
|
|
|
|
* This file is part of LoRa APRS iGate.
|
|
|
|
|
*
|
|
|
|
|
* LoRa APRS iGate is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* LoRa APRS iGate is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
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;
|
2025-10-15 19:31:02 +02:00
|
|
|
NTPClient* timeClient;
|
2024-10-14 16:44:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace NTP_Utils {
|
|
|
|
|
|
|
|
|
|
void setup() {
|
2025-04-24 14:07:29 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED && Config.digi.ecoMode == 0 && Config.callsign != "NOCALL-10") {
|
2024-10-14 16:44:22 +02:00
|
|
|
int gmt = Config.ntp.gmtCorrection * 3600;
|
2025-10-15 19:31:02 +02:00
|
|
|
timeClient = new NTPClient(ntpUDP, Config.ntp.server.c_str(), gmt, 15 * 60 * 1000); // Update interval 15 min
|
|
|
|
|
timeClient->begin();
|
2024-10-14 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update() {
|
2025-10-15 19:31:02 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED && Config.digi.ecoMode == 0 && Config.callsign != "NOCALL-10") timeClient->update();
|
2024-10-14 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getFormatedTime() {
|
2025-12-03 16:31:36 +01:00
|
|
|
if (WiFi.status() == WL_CONNECTED && Config.digi.ecoMode == 0) return timeClient->getFormattedTime();
|
2024-10-14 16:44:22 +02:00
|
|
|
return "DigiEcoMode Active";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|