Implemented additional timezone description
This commit is contained in:
parent
62768395aa
commit
000cd8b6dc
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#define NTP_MAX_SERVER_STRLEN 31
|
#define NTP_MAX_SERVER_STRLEN 31
|
||||||
#define NTP_MAX_TIMEZONE_STRLEN 50
|
#define NTP_MAX_TIMEZONE_STRLEN 50
|
||||||
|
#define NTP_MAX_TIMEZONEDESCR_STRLEN 50
|
||||||
|
|
||||||
struct CONFIG_T {
|
struct CONFIG_T {
|
||||||
uint32_t Cfg_Version;
|
uint32_t Cfg_Version;
|
||||||
@ -28,6 +29,7 @@ struct CONFIG_T {
|
|||||||
|
|
||||||
char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1];
|
char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1];
|
||||||
char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
|
char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
|
||||||
|
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigurationClass {
|
class ConfigurationClass {
|
||||||
|
|||||||
@ -19,3 +19,4 @@
|
|||||||
|
|
||||||
#define NTP_SERVER "pool.ntp.org"
|
#define NTP_SERVER "pool.ntp.org"
|
||||||
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
|
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
|
||||||
|
#define NTP_TIMEZONEDESCR "Europe/Berlin"
|
||||||
@ -19,6 +19,7 @@ void ConfigurationClass::init()
|
|||||||
// NTP Settings
|
// NTP Settings
|
||||||
strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server));
|
strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server));
|
||||||
strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
||||||
|
strlcpy(config.Ntp_TimezoneDescr, NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigurationClass::write()
|
bool ConfigurationClass::write()
|
||||||
@ -55,6 +56,7 @@ void ConfigurationClass::migrate()
|
|||||||
if (config.Cfg_Version < 0x00010400) {
|
if (config.Cfg_Version < 0x00010400) {
|
||||||
strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server));
|
strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server));
|
||||||
strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
|
||||||
|
strlcpy(config.Ntp_TimezoneDescr, NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr));
|
||||||
}
|
}
|
||||||
config.Cfg_Version = CONFIG_VERSION;
|
config.Cfg_Version = CONFIG_VERSION;
|
||||||
write();
|
write();
|
||||||
|
|||||||
@ -307,6 +307,7 @@ void WebApiClass::onNtpAdminGet(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
root[F("ntp_server")] = config.Ntp_Server;
|
root[F("ntp_server")] = config.Ntp_Server;
|
||||||
root[F("ntp_timezone")] = config.Ntp_Timezone;
|
root[F("ntp_timezone")] = config.Ntp_Timezone;
|
||||||
|
root[F("ntp_timezone_descr")] = config.Ntp_TimezoneDescr;
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
@ -365,9 +366,17 @@ void WebApiClass::onNtpAdminPost(AsyncWebServerRequest* request)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root[F("ntp_timezone_descr")].as<String>().length() == 0 || root[F("ntp_timezone_descr")].as<String>().length() > NTP_MAX_TIMEZONEDESCR_STRLEN) {
|
||||||
|
retMsg[F("message")] = F("Timezone description must between 1 and " STR(NTP_MAX_TIMEZONEDESCR_STRLEN) " characters long!");
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
strcpy(config.Ntp_Server, root[F("ntp_server")].as<String>().c_str());
|
strcpy(config.Ntp_Server, root[F("ntp_server")].as<String>().c_str());
|
||||||
strcpy(config.Ntp_Timezone, root[F("ntp_timezone")].as<String>().c_str());
|
strcpy(config.Ntp_Timezone, root[F("ntp_timezone")].as<String>().c_str());
|
||||||
|
strcpy(config.Ntp_TimezoneDescr, root[F("ntp_timezone_descr")].as<String>().c_str());
|
||||||
Configuration.write();
|
Configuration.write();
|
||||||
|
|
||||||
retMsg[F("type")] = F("success");
|
retMsg[F("type")] = F("success");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user