Feature: Allow configuration of sunset type
This commit is contained in:
parent
889e191589
commit
e7198073af
@ -66,6 +66,7 @@ struct CONFIG_T {
|
|||||||
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
||||||
double Ntp_Longitude;
|
double Ntp_Longitude;
|
||||||
double Ntp_Latitude;
|
double Ntp_Latitude;
|
||||||
|
uint8_t Ntp_SunsetType;
|
||||||
|
|
||||||
bool Mqtt_Enabled;
|
bool Mqtt_Enabled;
|
||||||
uint Mqtt_Port;
|
uint Mqtt_Port;
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
#define NTP_TIMEZONEDESCR "Europe/Berlin"
|
#define NTP_TIMEZONEDESCR "Europe/Berlin"
|
||||||
#define NTP_LONGITUDE 10.4515f
|
#define NTP_LONGITUDE 10.4515f
|
||||||
#define NTP_LATITUDE 51.1657f
|
#define NTP_LATITUDE 51.1657f
|
||||||
|
#define NTP_SUNSETTYPE 1
|
||||||
|
|
||||||
#define MQTT_ENABLED false
|
#define MQTT_ENABLED false
|
||||||
#define MQTT_HOST ""
|
#define MQTT_HOST ""
|
||||||
|
|||||||
@ -46,6 +46,7 @@ bool ConfigurationClass::write()
|
|||||||
ntp["timezone_descr"] = config.Ntp_TimezoneDescr;
|
ntp["timezone_descr"] = config.Ntp_TimezoneDescr;
|
||||||
ntp["latitude"] = config.Ntp_Latitude;
|
ntp["latitude"] = config.Ntp_Latitude;
|
||||||
ntp["longitude"] = config.Ntp_Longitude;
|
ntp["longitude"] = config.Ntp_Longitude;
|
||||||
|
ntp["sunsettype"] = config.Ntp_SunsetType;
|
||||||
|
|
||||||
JsonObject mqtt = doc.createNestedObject("mqtt");
|
JsonObject mqtt = doc.createNestedObject("mqtt");
|
||||||
mqtt["enabled"] = config.Mqtt_Enabled;
|
mqtt["enabled"] = config.Mqtt_Enabled;
|
||||||
@ -189,6 +190,7 @@ bool ConfigurationClass::read()
|
|||||||
strlcpy(config.Ntp_TimezoneDescr, ntp["timezone_descr"] | NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
strlcpy(config.Ntp_TimezoneDescr, ntp["timezone_descr"] | NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
||||||
config.Ntp_Latitude = ntp["latitude"] | NTP_LATITUDE;
|
config.Ntp_Latitude = ntp["latitude"] | NTP_LATITUDE;
|
||||||
config.Ntp_Longitude = ntp["longitude"] | NTP_LONGITUDE;
|
config.Ntp_Longitude = ntp["longitude"] | NTP_LONGITUDE;
|
||||||
|
config.Ntp_SunsetType = ntp["sunsettype"] | NTP_SUNSETTYPE;
|
||||||
|
|
||||||
JsonObject mqtt = doc["mqtt"];
|
JsonObject mqtt = doc["mqtt"];
|
||||||
config.Mqtt_Enabled = mqtt["enabled"] | MQTT_ENABLED;
|
config.Mqtt_Enabled = mqtt["enabled"] | MQTT_ENABLED;
|
||||||
|
|||||||
@ -45,8 +45,25 @@ void SunPositionClass::updateSunData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_sun.setCurrentDate(1900 + timeinfo.tm_year, timeinfo.tm_mon + 1, timeinfo.tm_mday);
|
_sun.setCurrentDate(1900 + timeinfo.tm_year, timeinfo.tm_mon + 1, timeinfo.tm_mday);
|
||||||
_sunriseMinutes = static_cast<int>(_sun.calcCustomSunrise(SunSet::SUNSET_NAUTICAL));
|
|
||||||
_sunsetMinutes = static_cast<int>(_sun.calcCustomSunset(SunSet::SUNSET_NAUTICAL));
|
double sunset_type;
|
||||||
|
switch (config.Ntp_SunsetType) {
|
||||||
|
case 0:
|
||||||
|
sunset_type = SunSet::SUNSET_OFFICIAL;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
sunset_type = SunSet::SUNSET_CIVIL;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
sunset_type = SunSet::SUNSET_ASTONOMICAL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sunset_type = SunSet::SUNSET_NAUTICAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sunriseMinutes = static_cast<int>(_sun.calcCustomSunrise(sunset_type));
|
||||||
|
_sunsetMinutes = static_cast<int>(_sun.calcCustomSunset(sunset_type));
|
||||||
uint minutesPastMidnight = timeinfo.tm_hour * 60 + timeinfo.tm_min;
|
uint minutesPastMidnight = timeinfo.tm_hour * 60 + timeinfo.tm_min;
|
||||||
|
|
||||||
_isDayPeriod = (minutesPastMidnight >= _sunriseMinutes) && (minutesPastMidnight < _sunsetMinutes);
|
_isDayPeriod = (minutesPastMidnight >= _sunriseMinutes) && (minutesPastMidnight < _sunsetMinutes);
|
||||||
|
|||||||
@ -81,6 +81,7 @@ void WebApiNtpClass::onNtpAdminGet(AsyncWebServerRequest* request)
|
|||||||
root["ntp_timezone_descr"] = config.Ntp_TimezoneDescr;
|
root["ntp_timezone_descr"] = config.Ntp_TimezoneDescr;
|
||||||
root["longitude"] = config.Ntp_Longitude;
|
root["longitude"] = config.Ntp_Longitude;
|
||||||
root["latitude"] = config.Ntp_Latitude;
|
root["latitude"] = config.Ntp_Latitude;
|
||||||
|
root["sunsettype"] = config.Ntp_SunsetType;
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
@ -125,7 +126,7 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(root.containsKey("ntp_server") && root.containsKey("ntp_timezone") && root.containsKey("longitude") && root.containsKey("latitude"))) {
|
if (!(root.containsKey("ntp_server") && root.containsKey("ntp_timezone") && root.containsKey("longitude") && root.containsKey("latitude") && root.containsKey("sunsettype"))) {
|
||||||
retMsg["message"] = "Values are missing!";
|
retMsg["message"] = "Values are missing!";
|
||||||
retMsg["code"] = WebApiError::GenericValueMissing;
|
retMsg["code"] = WebApiError::GenericValueMissing;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
@ -166,6 +167,7 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
|
|||||||
strlcpy(config.Ntp_TimezoneDescr, root["ntp_timezone_descr"].as<String>().c_str(), sizeof(config.Ntp_TimezoneDescr));
|
strlcpy(config.Ntp_TimezoneDescr, root["ntp_timezone_descr"].as<String>().c_str(), sizeof(config.Ntp_TimezoneDescr));
|
||||||
config.Ntp_Latitude = root["latitude"].as<double>();
|
config.Ntp_Latitude = root["latitude"].as<double>();
|
||||||
config.Ntp_Longitude = root["longitude"].as<double>();
|
config.Ntp_Longitude = root["longitude"].as<double>();
|
||||||
|
config.Ntp_SunsetType = root["sunsettype"].as<uint8_t>();
|
||||||
Configuration.write();
|
Configuration.write();
|
||||||
|
|
||||||
retMsg["type"] = "success";
|
retMsg["type"] = "success";
|
||||||
|
|||||||
@ -243,8 +243,8 @@
|
|||||||
"Synced": "synchronisiert",
|
"Synced": "synchronisiert",
|
||||||
"NotSynced": "nicht synchronisiert",
|
"NotSynced": "nicht synchronisiert",
|
||||||
"LocalTime": "Lokale Uhrzeit",
|
"LocalTime": "Lokale Uhrzeit",
|
||||||
"Sunrise": "Nautische Morgendämmerung",
|
"Sunrise": "Morgendämmerung",
|
||||||
"Sunset": "Nautische Abenddämmerung",
|
"Sunset": "Abenddämmerung",
|
||||||
"Mode": "Modus",
|
"Mode": "Modus",
|
||||||
"Day": "Tag",
|
"Day": "Tag",
|
||||||
"Night": "Nacht"
|
"Night": "Nacht"
|
||||||
@ -359,6 +359,12 @@
|
|||||||
"LocationConfiguration": "Standortkonfiguration",
|
"LocationConfiguration": "Standortkonfiguration",
|
||||||
"Longitude": "Längengrad:",
|
"Longitude": "Längengrad:",
|
||||||
"Latitude": "Breitengrad:",
|
"Latitude": "Breitengrad:",
|
||||||
|
"SunSetType": "Dämmerungstyp:",
|
||||||
|
"SunSetTypeHint": "Beeinflusst die Tag/Nacht Berechnung. Es kann bis zu einer Minute dauern bis der neue Typ angewendet wurde.",
|
||||||
|
"OFFICIAL": "Standard Dämmerung (90.8°)",
|
||||||
|
"NAUTICAL": "Nautische Dämmerung (102°)",
|
||||||
|
"CIVIL": "Bürgerliche Dämmerung (96°)",
|
||||||
|
"ASTONOMICAL": "Astronomische Dämmerung (108°)",
|
||||||
"Save": "@:dtuadmin.Save",
|
"Save": "@:dtuadmin.Save",
|
||||||
"ManualTimeSynchronization": "Manuelle Zeitsynchronization",
|
"ManualTimeSynchronization": "Manuelle Zeitsynchronization",
|
||||||
"CurrentOpenDtuTime": "Aktuelle OpenDTU-Zeit:",
|
"CurrentOpenDtuTime": "Aktuelle OpenDTU-Zeit:",
|
||||||
|
|||||||
@ -243,8 +243,8 @@
|
|||||||
"Synced": "synced",
|
"Synced": "synced",
|
||||||
"NotSynced": "not synced",
|
"NotSynced": "not synced",
|
||||||
"LocalTime": "Local Time",
|
"LocalTime": "Local Time",
|
||||||
"Sunrise": "Nautical Sunrise",
|
"Sunrise": "Sunrise",
|
||||||
"Sunset": "Nautical Sunset",
|
"Sunset": "Sunset",
|
||||||
"Mode": "Mode",
|
"Mode": "Mode",
|
||||||
"Day": "Day",
|
"Day": "Day",
|
||||||
"Night": "Night"
|
"Night": "Night"
|
||||||
@ -359,6 +359,12 @@
|
|||||||
"LocationConfiguration": "Location Configuration",
|
"LocationConfiguration": "Location Configuration",
|
||||||
"Longitude": "Longitude",
|
"Longitude": "Longitude",
|
||||||
"Latitude": "Latitude",
|
"Latitude": "Latitude",
|
||||||
|
"SunSetType": "Sunset type",
|
||||||
|
"SunSetTypeHint": "Affects the day/night calculation. It can take up to one minute until the new type will be applied.",
|
||||||
|
"OFFICIAL": "Standard dawn (90.8°)",
|
||||||
|
"NAUTICAL": "Nautical dawn (102°)",
|
||||||
|
"CIVIL": "Civil dawn (96°)",
|
||||||
|
"ASTONOMICAL": "Astronomical dawn (108°)",
|
||||||
"Save": "@:dtuadmin.Save",
|
"Save": "@:dtuadmin.Save",
|
||||||
"ManualTimeSynchronization": "Manual Time Synchronization",
|
"ManualTimeSynchronization": "Manual Time Synchronization",
|
||||||
"CurrentOpenDtuTime": "Current OpenDTU Time:",
|
"CurrentOpenDtuTime": "Current OpenDTU Time:",
|
||||||
|
|||||||
@ -243,8 +243,8 @@
|
|||||||
"Synced": "synchronisée",
|
"Synced": "synchronisée",
|
||||||
"NotSynced": "pas synchronisée",
|
"NotSynced": "pas synchronisée",
|
||||||
"LocalTime": "Heure locale",
|
"LocalTime": "Heure locale",
|
||||||
"Sunrise": "Nautical Sunrise",
|
"Sunrise": "Sunrise",
|
||||||
"Sunset": "Nautical Sunset",
|
"Sunset": "Sunset",
|
||||||
"Mode": "Mode",
|
"Mode": "Mode",
|
||||||
"Day": "Day",
|
"Day": "Day",
|
||||||
"Night": "Night"
|
"Night": "Night"
|
||||||
@ -359,6 +359,12 @@
|
|||||||
"LocationConfiguration": "Géolocalisation",
|
"LocationConfiguration": "Géolocalisation",
|
||||||
"Longitude": "Longitude",
|
"Longitude": "Longitude",
|
||||||
"Latitude": "Latitude",
|
"Latitude": "Latitude",
|
||||||
|
"SunSetType": "Sunset type",
|
||||||
|
"SunSetTypeHint": "Affects the day/night calculation. It can take up to one minute until the new type will be applied.",
|
||||||
|
"OFFICIAL": "Standard dawn (90.8°)",
|
||||||
|
"NAUTICAL": "Nautical dawn (102°)",
|
||||||
|
"CIVIL": "Civil dawn (96°)",
|
||||||
|
"ASTONOMICAL": "Astronomical dawn (108°)",
|
||||||
"Save": "@:dtuadmin.Save",
|
"Save": "@:dtuadmin.Save",
|
||||||
"ManualTimeSynchronization": "Synchronisation manuelle de l'heure",
|
"ManualTimeSynchronization": "Synchronisation manuelle de l'heure",
|
||||||
"CurrentOpenDtuTime": "Heure actuelle de l'OpenDTU",
|
"CurrentOpenDtuTime": "Heure actuelle de l'OpenDTU",
|
||||||
|
|||||||
@ -4,4 +4,5 @@ export interface NtpConfig {
|
|||||||
ntp_timezone_descr: string;
|
ntp_timezone_descr: string;
|
||||||
latitude: number;
|
latitude: number;
|
||||||
longitude: number;
|
longitude: number;
|
||||||
|
sunsettype: number;
|
||||||
}
|
}
|
||||||
@ -36,6 +36,21 @@
|
|||||||
<InputElement :label="$t('ntpadmin.Longitude')"
|
<InputElement :label="$t('ntpadmin.Longitude')"
|
||||||
v-model="ntpConfigList.longitude"
|
v-model="ntpConfigList.longitude"
|
||||||
type="number" min="-180" max="180" step="any"/>
|
type="number" min="-180" max="180" step="any"/>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<label class="col-sm-2 col-form-label">
|
||||||
|
{{ $t('ntpadmin.SunSetType') }}
|
||||||
|
<BIconInfoCircle v-tooltip :title="$t('ntpadmin.SunSetTypeHint')" />
|
||||||
|
</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<select class="form-select" v-model="ntpConfigList.sunsettype">
|
||||||
|
<option v-for="sunsettype in sunsetTypeList" :key="sunsettype.key" :value="sunsettype.key">
|
||||||
|
{{ $t(`ntpadmin.` + sunsettype.value) }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</CardElement>
|
</CardElement>
|
||||||
<button type="submit" class="btn btn-primary mb-3">{{ $t('ntpadmin.Save') }}</button>
|
<button type="submit" class="btn btn-primary mb-3">{{ $t('ntpadmin.Save') }}</button>
|
||||||
</form>
|
</form>
|
||||||
@ -67,6 +82,7 @@ import InputElement from '@/components/InputElement.vue';
|
|||||||
import type { NtpConfig } from "@/types/NtpConfig";
|
import type { NtpConfig } from "@/types/NtpConfig";
|
||||||
import { authHeader, handleResponse } from '@/utils/authentication';
|
import { authHeader, handleResponse } from '@/utils/authentication';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
|
import { BIconInfoCircle } from 'bootstrap-icons-vue';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@ -74,6 +90,7 @@ export default defineComponent({
|
|||||||
BootstrapAlert,
|
BootstrapAlert,
|
||||||
CardElement,
|
CardElement,
|
||||||
InputElement,
|
InputElement,
|
||||||
|
BIconInfoCircle,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -88,6 +105,12 @@ export default defineComponent({
|
|||||||
alertMessage: "",
|
alertMessage: "",
|
||||||
alertType: "info",
|
alertType: "info",
|
||||||
showAlert: false,
|
showAlert: false,
|
||||||
|
sunsetTypeList: [
|
||||||
|
{ key: 0, value: 'OFFICIAL' },
|
||||||
|
{ key: 1, value: 'NAUTICAL' },
|
||||||
|
{ key: 2, value: 'CIVIL' },
|
||||||
|
{ key: 3, value: 'ASTONOMICAL' },
|
||||||
|
],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user