Browse Source

Show NTP status on web interface (#126)

fastled
Xose Pérez 7 years ago
parent
commit
3a872979fe
6 changed files with 67 additions and 51 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +6
    -0
      code/espurna/ntp.ino
  3. +51
    -51
      code/espurna/static/index.html.gz.h
  4. +2
    -0
      code/espurna/web.ino
  5. +3
    -0
      code/html/custom.js
  6. +5
    -0
      code/html/index.html

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


+ 6
- 0
code/espurna/ntp.ino View File

@ -19,6 +19,10 @@ void ntpConnect() {
NTP.setInterval(NTP_UPDATE_INTERVAL); NTP.setInterval(NTP_UPDATE_INTERVAL);
} }
bool ntpConnected() {
return (timeStatus() == timeSet);
}
void ntpSetup() { void ntpSetup() {
NTP.onNTPSyncEvent([](NTPSyncEvent_t error) { NTP.onNTPSyncEvent([](NTPSyncEvent_t error) {
@ -28,8 +32,10 @@ void ntpSetup() {
} else if (error == invalidAddress) { } else if (error == invalidAddress) {
DEBUG_MSG_P(PSTR("[NTP] Error: Invalid NTP server address\n")); DEBUG_MSG_P(PSTR("[NTP] Error: Invalid NTP server address\n"));
} }
wsSend("{\"ntpStatus\": false}");
} else { } else {
DEBUG_MSG_P(PSTR("[NTP] Time: %s\n"), (char *) NTP.getTimeDateString(NTP.getLastNTPSync()).c_str()); DEBUG_MSG_P(PSTR("[NTP] Time: %s\n"), (char *) NTP.getTimeDateString(NTP.getLastNTPSync()).c_str());
wsSend("{\"ntpStatus\": true}");
} }
}); });


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


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

@ -398,6 +398,8 @@ void _wsStart(uint32_t client_id) {
root["network"] = getNetwork(); root["network"] = getNetwork();
root["deviceip"] = getIP(); root["deviceip"] = getIP();
root["ntpStatus"] = ntpConnected();
root["mqttStatus"] = mqttConnected(); root["mqttStatus"] = mqttConnected();
root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER); root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER);
root["mqttPort"] = getSetting("mqttPort", MQTT_PORT); root["mqttPort"] = getSetting("mqttPort", MQTT_PORT);


+ 3
- 0
code/html/custom.js View File

@ -427,6 +427,9 @@ function processData(data) {
if (key == "mqttStatus") { if (key == "mqttStatus") {
data.mqttStatus = data.mqttStatus ? "CONNECTED" : "NOT CONNECTED"; data.mqttStatus = data.mqttStatus ? "CONNECTED" : "NOT CONNECTED";
} }
if (key == "ntpStatus") {
data.ntpStatus = data.ntpStatus ? "SYNC'D" : "NOT SYNC'D";
}
if (key == "tmpUnits") { if (key == "tmpUnits") {
$("span#tmpUnit").html(data[key] == 1 ? "ºF" : "ºC"); $("span#tmpUnit").html(data[key] == 1 ? "ºF" : "ºC");
} }


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

@ -178,6 +178,11 @@
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="mqttStatus" readonly /> <input class="pure-u-1 pure-u-sm-3-4" type="text" name="mqttStatus" readonly />
</div> </div>
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4" for="ntp">NTP Status</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="ntpStatus" readonly />
</div>
<div class="pure-g module module-analog"> <div class="pure-g module module-analog">
<label class="pure-u-1 pure-u-sm-1-4" for="analogValue">Analog</label> <label class="pure-u-1 pure-u-sm-1-4" for="analogValue">Analog</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="analogValue" readonly /> <input class="pure-u-1 pure-u-sm-3-4" type="text" name="analogValue" readonly />


Loading…
Cancel
Save