Added config parameters to set longitude and latitude

This commit is contained in:
Thomas Basler 2023-02-18 16:40:24 +01:00
parent 7da782c4ef
commit 19a1c0aa54
10 changed files with 36 additions and 1 deletions

View File

@ -60,6 +60,8 @@ struct CONFIG_T {
char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1];
char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
double Ntp_Longitude;
double Ntp_Latitude;
bool Mqtt_Enabled;
uint Mqtt_Port;

View File

@ -23,6 +23,8 @@
#define NTP_SERVER "pool.ntp.org"
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
#define NTP_TIMEZONEDESCR "Europe/Berlin"
#define NTP_LONGITUDE 10.4515f
#define NTP_LATITUDE 51.1657f
#define MQTT_ENABLED false
#define MQTT_HOST ""

View File

@ -44,6 +44,8 @@ bool ConfigurationClass::write()
ntp["server"] = config.Ntp_Server;
ntp["timezone"] = config.Ntp_Timezone;
ntp["timezone_descr"] = config.Ntp_TimezoneDescr;
ntp["latitude"] = config.Ntp_Latitude;
ntp["longitude"] = config.Ntp_Longitude;
JsonObject mqtt = doc.createNestedObject("mqtt");
mqtt["enabled"] = config.Mqtt_Enabled;
@ -175,6 +177,8 @@ bool ConfigurationClass::read()
strlcpy(config.Ntp_Server, ntp["server"] | NTP_SERVER, sizeof(config.Ntp_Server));
strlcpy(config.Ntp_Timezone, ntp["timezone"] | NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
strlcpy(config.Ntp_TimezoneDescr, ntp["timezone_descr"] | NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
config.Ntp_Latitude = ntp["latitude"] | NTP_LATITUDE;
config.Ntp_Longitude = ntp["longitude"] | NTP_LONGITUDE;
JsonObject mqtt = doc["mqtt"];
config.Mqtt_Enabled = mqtt["enabled"] | MQTT_ENABLED;

View File

@ -68,6 +68,8 @@ void WebApiNtpClass::onNtpAdminGet(AsyncWebServerRequest* request)
root[F("ntp_server")] = config.Ntp_Server;
root[F("ntp_timezone")] = config.Ntp_Timezone;
root[F("ntp_timezone_descr")] = config.Ntp_TimezoneDescr;
root[F("longitude")] = config.Ntp_Longitude;
root[F("latitude")] = config.Ntp_Latitude;
response->setLength();
request->send(response);
@ -112,7 +114,7 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
return;
}
if (!(root.containsKey("ntp_server") && root.containsKey("ntp_timezone"))) {
if (!(root.containsKey("ntp_server") && root.containsKey("ntp_timezone") && root.containsKey("longitude") && root.containsKey("latitude"))) {
retMsg[F("message")] = F("Values are missing!");
retMsg[F("code")] = WebApiError::GenericValueMissing;
response->setLength();
@ -151,6 +153,8 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
strlcpy(config.Ntp_Server, root[F("ntp_server")].as<String>().c_str(), sizeof(config.Ntp_Server));
strlcpy(config.Ntp_Timezone, root[F("ntp_timezone")].as<String>().c_str(), sizeof(config.Ntp_Timezone));
strlcpy(config.Ntp_TimezoneDescr, root[F("ntp_timezone_descr")].as<String>().c_str(), sizeof(config.Ntp_TimezoneDescr));
config.Ntp_Latitude = root[F("latitude")].as<double>();
config.Ntp_Longitude = root[F("longitude")].as<double>();
Configuration.write();
retMsg[F("type")] = F("success");

View File

@ -27,6 +27,7 @@
:maxlength="maxlength"
:min="min"
:max="max"
:step="step"
:disabled="disabled"
:aria-describedby="descriptionId"
/>
@ -69,6 +70,7 @@ export default defineComponent({
'maxlength': String,
'min': String,
'max': String,
'step': String,
'rows': String,
'disabled': Boolean,
'postfix': String,

View File

@ -328,6 +328,9 @@
"TimeServerHint": "Der Standardwert ist in Ordnung, solange OpenDTU direkten Zugang zum Internet hat.",
"Timezone": "Zeitzone:",
"TimezoneConfig": "Zeitzonenkonfiguration:",
"LocationConfiguration": "Standortkonfiguration",
"Longitude": "Längengrad:",
"Latitude": "Breitengrad:",
"Save": "@:dtuadmin.Save",
"ManualTimeSynchronization": "Manuelle Zeitsynchronization",
"CurrentOpenDtuTime": "Aktuelle OpenDTU Zeit:",

View File

@ -328,6 +328,9 @@
"TimeServerHint": "The default value is fine as long as OpenDTU has direct access to the internet.",
"Timezone": "Timezone:",
"TimezoneConfig": "Timezone Config:",
"LocationConfiguration": "Location Configuration",
"Longitude": "Longitude",
"Latitude": "Latitude",
"Save": "@:dtuadmin.Save",
"ManualTimeSynchronization": "Manual Time Synchronization",
"CurrentOpenDtuTime": "Current OpenDTU Time:",

View File

@ -328,6 +328,9 @@
"TimeServerHint": "La valeur par défaut convient tant que OpenDTU a un accès direct à Internet.",
"Timezone": "Fuseau horaire",
"TimezoneConfig": "Configuration du fuseau horaire",
"LocationConfiguration": "Location Configuration",
"Longitude": "Longitude",
"Latitude": "Latitude",
"Save": "@:dtuadmin.Save",
"ManualTimeSynchronization": "Synchronisation manuelle de l'heure",
"CurrentOpenDtuTime": "Heure actuelle de l'OpenDTU",

View File

@ -2,4 +2,6 @@ export interface NtpConfig {
ntp_server: string;
ntp_timezone: string;
ntp_timezone_descr: string;
latitude: number;
longitude: number;
}

View File

@ -27,6 +27,16 @@
v-model="ntpConfigList.ntp_timezone"
type="text" maxlength="32" disabled/>
</CardElement>
<CardElement :text="$t('ntpadmin.LocationConfiguration')" textVariant="text-bg-primary" add-space>
<InputElement :label="$t('ntpadmin.Longitude')"
v-model="ntpConfigList.longitude"
type="number" min="-180" max="180" step="any"/>
<InputElement :label="$t('ntpadmin.Latitude')"
v-model="ntpConfigList.latitude"
type="number" min="-90" max="90" step="any"/>
</CardElement>
<button type="submit" class="btn btn-primary mb-3">{{ $t('ntpadmin.Save') }}</button>
</form>