Skip to content

Commit

Permalink
NTP time added
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Oct 14, 2024
1 parent 03ccd2b commit 79cf50a
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 15 deletions.
3 changes: 3 additions & 0 deletions data/igate_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"username": "admin",
"password": ""
},
"ntp": {
"gmtCorrection": 0
},
"other": {
"rememberStationTime": 30,
"lowPowerMode": false,
Expand Down
49 changes: 49 additions & 0 deletions data_embed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,55 @@ <h5>
</div>
<hr />

<div class="row my-5 d-flex align-items-top">
<div class="col-lg-3 col-sm-12">
<h5>
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
fill="currentColor"
class="bi bi-cloud-upload-fill"
viewBox="0 0 16 16"
>
<path
fill-rule="evenodd"
d="M8 0a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 4.095 0 5.555 0 7.318 0 9.366 1.708 11 3.781 11H7.5V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V11h4.188C14.502 11 16 9.57 16 7.773c0-1.636-1.242-2.969-2.834-3.194C12.923 1.999 10.69 0 8 0m-.5 14.5V11h1v3.5a.5.5 0 0 1-1 0"
/>
</svg>
NTP
</h5>
<small
>Set your GMT Time Zone.
</small>
</div>
<div class="col-lg-9 col-sm-12">
<div class="col-12">
<label
for="ntp.gmtCorrection"
class="form-label"
>GMT Time Correction for accurate Local Time</label
>
<div class="input-group">
<input
type="number"
name="ntp.gmtCorrection"
id="ntp.gmtCorrection"
placeholder="0"
class="form-control"
step="1"
min="-23"
max="23"
/>
<span class="input-group-text"
>hours</span
>
</div>
</div>
</div>
</div>
<hr />

<div class="row my-5 d-flex align-items-top">
<div class="col-lg-3 col-sm-12">
<h5>
Expand Down
9 changes: 4 additions & 5 deletions data_embed/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ function loadSettings(settings) {
document.getElementById("webadmin.username").value = settings.webadmin.username;
document.getElementById("webadmin.password").value = settings.webadmin.password;

// NTP
document.getElementById("ntp.gmtCorrection").value = settings.ntp.gmtCorrection;

// Experimental
document.getElementById("other.backupDigiMode").checked = settings.other.backupDigiMode;

Expand Down Expand Up @@ -507,13 +510,9 @@ function loadReceivedPackets(packets) {

packets.forEach((packet) => {
const element = document.createElement("tr");

date.setTime(packet.millis);

const p = date.toUTCString().split(' ')

element.innerHTML = `
<td>${p[p.length-2]}</td>
<td>${packet.rxTime}</td>
<td>${packet.packet}</td>
<td>${packet.RSSI}</td>
<td>${packet.SNR}</td>
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ lib_deps =
ayushsharma82/ElegantOTA @ 3.1.5
mathieucarbou/ESPAsyncWebServer @ 3.2.3
mathieucarbou/AsyncTCP @ 3.2.5
arduino-libraries/NTPClient @ 3.2.1

[env:ttgo-lora32-v21]
board = ttgo-lora32-v21
Expand Down
9 changes: 6 additions & 3 deletions src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ ________________________________________________________________________________
#include "gps_utils.h"
#include "web_utils.h"
#include "tnc_utils.h"
#include "ntp_utils.h"
#include "wx_utils.h"
#include "display.h"
#include "utils.h"
#ifdef HAS_A7670
#include "A7670_utils.h"
#endif

String versionDate = "2024.10.08";
String versionDate = "2024.10.14";
Configuration Config;
WiFiClient espClient;

Expand Down Expand Up @@ -67,8 +68,8 @@ void setup() {
GPS_Utils::generateBeacons();

#ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers
displayShow("", " STARTUP DELAY ...", "", "", 0);
delay(STARTUP_DELAY * 60 * 1000);
displayShow("", " STARTUP DELAY ...", "", "", 0);
delay(STARTUP_DELAY * 60 * 1000);
#endif

#ifdef HELTEC_HTCT62
Expand Down Expand Up @@ -113,6 +114,7 @@ void setup() {
#endif
DIGI_Utils::checkEcoMode();
WIFI_Utils::setup();
NTP_Utils::setup();
SYSLOG_Utils::setup();
WX_Utils::setup();
WEB_Utils::setup();
Expand Down Expand Up @@ -145,6 +147,7 @@ void loop() {
if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect();
#endif

NTP_Utils::update();
TNC_Utils::loop();

Utils::checkDisplayInterval();
Expand Down
6 changes: 6 additions & 0 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ void Configuration::writeFile() {
data["webadmin"]["username"] = webadmin.username;
data["webadmin"]["password"] = webadmin.password;

data["ntp"]["gmtCorrection"] = ntp.gmtCorrection;

serializeJson(data, configFile);

configFile.close();
Expand Down Expand Up @@ -201,6 +203,8 @@ bool Configuration::readFile() {
webadmin.username = data["webadmin"]["username"] | "admin";
webadmin.password = data["webadmin"]["password"] | "";

ntp.gmtCorrection = data["ntp"]["gmtCorrection"] | 0;

lowPowerMode = data["other"]["lowPowerMode"] | false;
lowVoltageCutOff = data["other"]["lowVoltageCutOff"] | 0;

Expand Down Expand Up @@ -318,6 +322,8 @@ void Configuration::init() {
webadmin.username = "admin";
webadmin.password = "";

ntp.gmtCorrection = 0;

Serial.println("All is Written!");
}

Expand Down
8 changes: 8 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ class WEBADMIN {
String password;
};

class NTP {
public:
int gmtCorrection;
};



class Configuration {
public:
String callsign;
Expand All @@ -138,6 +145,7 @@ class Configuration {
TNC tnc;
OTA ota;
WEBADMIN webadmin;
NTP ntp;

void init();
void writeFile();
Expand Down
5 changes: 3 additions & 2 deletions src/lora_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "aprs_is_utils.h"
#include "boards_pinout.h"
#include "syslog_utils.h"
#include "ntp_utils.h"
#include "display.h"
#include "utils.h"

Expand Down Expand Up @@ -175,9 +176,9 @@ namespace LoRa_Utils {
Utils::println("<--- LoRa Packet Rx : " + packet.substring(3));
Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")");

if (!Config.lowPowerMode) {
if (!Config.lowPowerMode && !Config.digi.ecoMode) {
ReceivedPacket receivedPacket;
receivedPacket.millis = millis();
receivedPacket.rxTime = NTP_Utils::getFormatedTime();
receivedPacket.packet = packet.substring(3);
receivedPacket.RSSI = rssi;
receivedPacket.SNR = snr;
Expand Down
33 changes: 33 additions & 0 deletions src/ntp_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#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";
}

}
14 changes: 14 additions & 0 deletions src/ntp_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef NTP_UTILS_H_
#define NTP_UTILS_H_

#include <Arduino.h>

namespace NTP_Utils {

void setup();
void update();
String getFormatedTime();

}

#endif
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ReceivedPacket {
public:
long millis;
String rxTime;
String packet;
int RSSI;
float SNR;
Expand Down
10 changes: 6 additions & 4 deletions src/web_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ namespace WEB_Utils {
StaticJsonDocument<1536> data;

for (int i = 0; i < receivedPackets.size(); i++) {
data[i]["millis"] = receivedPackets[i].millis;
data[i]["packet"] = receivedPackets[i].packet;
data[i]["RSSI"] = receivedPackets[i].RSSI;
data[i]["SNR"] = receivedPackets[i].SNR;
data[i]["rxTime"] = receivedPackets[i].rxTime;
data[i]["packet"] = receivedPackets[i].packet;
data[i]["RSSI"] = receivedPackets[i].RSSI;
data[i]["SNR"] = receivedPackets[i].SNR;
}

String buffer;
Expand Down Expand Up @@ -208,6 +208,8 @@ namespace WEB_Utils {
Config.webadmin.password = request->getParam("webadmin.password", true)->value();
}

Config.ntp.gmtCorrection = request->getParam("ntp.gmtCorrection", true)->value().toInt();

Config.writeFile();

AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
Expand Down

0 comments on commit 79cf50a

Please sign in to comment.