Skip to content

Commit

Permalink
Show NTP status on web interface (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Apr 24, 2017
1 parent ac179da commit 3a87297
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 51 deletions.
Binary file modified code/espurna/data/index.html.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions code/espurna/ntp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ void ntpConnect() {
NTP.setInterval(NTP_UPDATE_INTERVAL);
}

bool ntpConnected() {
return (timeStatus() == timeSet);
}

void ntpSetup() {

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

Expand Down
102 changes: 51 additions & 51 deletions code/espurna/static/index.html.gz.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions code/espurna/web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ void _wsStart(uint32_t client_id) {
root["network"] = getNetwork();
root["deviceip"] = getIP();

root["ntpStatus"] = ntpConnected();

root["mqttStatus"] = mqttConnected();
root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER);
root["mqttPort"] = getSetting("mqttPort", MQTT_PORT);
Expand Down
3 changes: 3 additions & 0 deletions code/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ function processData(data) {
if (key == "mqttStatus") {
data.mqttStatus = data.mqttStatus ? "CONNECTED" : "NOT CONNECTED";
}
if (key == "ntpStatus") {
data.ntpStatus = data.ntpStatus ? "SYNC'D" : "NOT SYNC'D";
}
if (key == "tmpUnits") {
$("span#tmpUnit").html(data[key] == 1 ? "ºF" : "ºC");
}
Expand Down
5 changes: 5 additions & 0 deletions code/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ <h2>Current configuration</h2>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="mqttStatus" readonly />
</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">
<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 />
Expand Down

0 comments on commit 3a87297

Please sign in to comment.