Browse Source

NTP configuration in web interface

fastled
Xose Pérez 7 years ago
parent
commit
c8eba6a979
5 changed files with 136 additions and 62 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +7
    -1
      code/espurna/ntp.ino
  3. +61
    -61
      code/espurna/static/index.html.gz.h
  4. +22
    -0
      code/espurna/web.ino
  5. +46
    -0
      code/html/index.html

BIN
code/espurna/data/index.html.gz View File


+ 7
- 1
code/espurna/ntp.ino View File

@ -15,7 +15,13 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
void ntpConnect() {
NTP.begin(NTP_SERVER, NTP_TIME_OFFSET, NTP_DAY_LIGHT);
NTP.begin(
getSetting("ntpServer1", NTP_SERVER),
getSetting("ntpOffset", NTP_TIME_OFFSET).toInt(),
getSetting("ntpDST", NTP_DAY_LIGHT).toInt() == 1
);
if (getSetting("ntpServer2")) NTP.setNtpServerName(getSetting("ntpServer2"), 1);
if (getSetting("ntpServer3")) NTP.setNtpServerName(getSetting("ntpServer3"), 2);
NTP.setInterval(NTP_UPDATE_INTERVAL);
}


+ 61
- 61
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 22
- 0
code/espurna/web.ino View File

@ -159,7 +159,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
bool save = false;
bool changed = false;
bool changedMQTT = false;
bool changedNTP = false;
bool apiEnabled = false;
bool dstEnabled = false;
#if ENABLE_FAUXMO
bool fauxmoEnabled = false;
#endif
@ -249,6 +251,10 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
apiEnabled = true;
continue;
}
if (key == "ntpDST") {
dstEnabled = true;
continue;
}
#if ENABLE_FAUXMO
if (key == "fauxmoEnabled") {
fauxmoEnabled = true;
@ -281,6 +287,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
setSetting(key, value);
save = changed = true;
if (key.startsWith("mqtt")) changedMQTT = true;
if (key.startsWith("ntp")) changedNTP = true;
}
}
@ -292,6 +299,10 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
setSetting("apiEnabled", apiEnabled);
save = changed = true;
}
if (dstEnabled != (getSetting("ntpDST").toInt() == 1)) {
setSetting("ntpDST", dstEnabled);
save = changed = changedNTP = true;
}
#if ENABLE_FAUXMO
if (fauxmoEnabled != (getSetting("fauxmoEnabled").toInt() == 1)) {
setSetting("fauxmoEnabled", fauxmoEnabled);
@ -351,6 +362,12 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (changedMQTT) {
mqttDisconnect();
}
// Check if we should reconfigure NTP connection
if (changedNTP) {
ntpConnect();
}
}
if (changed) {
@ -399,6 +416,11 @@ void _wsStart(uint32_t client_id) {
root["deviceip"] = getIP();
root["ntpStatus"] = ntpConnected();
root["ntpServer1"] = getSetting("ntpServer1", NTP_SERVER);
root["ntpServer2"] = getSetting("ntpServer2");
root["ntpServer3"] = getSetting("ntpServer3");
root["ntpOffset"] = getSetting("ntpOffset", NTP_TIME_OFFSET).toInt();
root["ntpDST"] = getSetting("ntpDST", NTP_DAY_LIGHT).toInt() == 1;
root["mqttStatus"] = mqttConnected();
root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER);


+ 46
- 0
code/html/index.html View File

@ -98,6 +98,10 @@
<a href="#" class="pure-menu-link" data="panel-mqtt">MQTT</a>
</li>
<li class="pure-menu-item">
<a href="#" class="pure-menu-link" data="panel-ntp">NTP</a>
</li>
<li class="pure-menu-item module module-dcz">
<a href="#" class="pure-menu-link" data="panel-domoticz">DOMOTICZ</a>
</li>
@ -470,6 +474,48 @@
</div>
<div class="panel" id="panel-ntp">
<div class="header">
<h1>NTP</h1>
<h2>Configure your NTP (Network Time Protocol) servers and local configuration to keep your device time up to the second for your location.</h2>
</div>
<div class="page">
<fieldset>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="ntpServer1">NTP Server 1</label>
<input class="pure-u-1 pure-u-md-3-4" name="ntpServer1" type="text" size="20" tabindex="41" />
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="ntpServer2">NTP Server 2</label>
<input class="pure-u-1 pure-u-md-3-4" name="ntpServer2" type="text" size="20" tabindex="42" />
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="ntpServer3">NTP Server 3</label>
<input class="pure-u-1 pure-u-md-3-4" name="ntpServer3" type="text" size="20" tabindex="43" />
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4" for="ntpOffset">Time offset</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="ntpOffset" type="number" min="-11" max="14" tabindex="44" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 for UTC time</div>
</div>
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-4"><label for="ntpDST">Enable Daylight Saving Time</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="ntpDST" /></div>
</div>
</fieldset>
</div>
</div>
<div class="panel" id="panel-domoticz">
<div class="header">


Loading…
Cancel
Save