Browse Source

fix #334 added button to index if ntp timeserver was not reachable

pull/357/head
lumapu 2 years ago
parent
commit
38bb3fd7e2
  1. 2
      tools/esp8266/defines.h
  2. 10
      tools/esp8266/html/api.js
  3. 33
      tools/esp8266/html/index.html

2
tools/esp8266/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 19 #define VERSION_PATCH 20
//------------------------------------- //-------------------------------------

10
tools/esp8266/html/api.js

@ -41,13 +41,14 @@ function lbl(htmlfor, val, cl=null, id=null) {
return e; return e;
} }
function inp(name, val, max=32, cl=["text"], id=null) { function inp(name, val, max=32, cl=["text"], id=null, type=null) {
e = document.createElement('input'); e = document.createElement('input');
e.classList.add(...cl); e.classList.add(...cl);
e.name = name; e.name = name;
e.value = val; e.value = val;
e.maxLength = max; if(null != type) e.maxLength = max;
if(null != id) e.id = id; if(null != id) e.id = id;
if(null != type) e.type = type;
return e; return e;
} }
@ -71,9 +72,10 @@ function div(cl) {
return e; return e;
} }
function span(val, cl) { function span(val, cl=null, id=null) {
e = document.createElement('span'); e = document.createElement('span');
e.innerHTML = val; e.innerHTML = val;
e.classList.add(...cl); if(null != cl) e.classList.add(...cl);
if(null != id) e.id = id;
return e; return e;
} }

33
tools/esp8266/html/index.html

@ -47,9 +47,29 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var mIntervalSet = false; var mIntervalSet = false;
function apiCb(obj) {
var e = document.getElementById("apiResult");
if(obj["success"]) {
e.innerHTML = " command excuted";
getAjax("/api/index", parse);
}
else
e.innerHTML = " Error: " + obj["error"];
}
function setTime() {
var date = new Date();
var offset = date.getTimezoneOffset() * -60;
var obj = new Object();
obj.cmd = "set_time";
obj.ts = parseInt(offset + (date.getTime() / 1000));
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
}
function parseSys(obj) { function parseSys(obj) {
document.getElementById("version").innerHTML = "Git SHA: " + obj["build"] + " :: " + obj["version"]; document.getElementById("version").innerHTML = "Git SHA: " + obj["build"] + " :: " + obj["version"];
document.getElementById("wifi_rssi").innerHTML = obj["wifi_rssi"];; document.getElementById("wifi_rssi").innerHTML = obj["wifi_rssi"];
var date = new Date(obj["ts_now"] * 1000); var date = new Date(obj["ts_now"] * 1000);
var up = obj["ts_uptime"]; var up = obj["ts_uptime"];
@ -61,7 +81,16 @@
+ ("0"+hrs).substr(-2) + ":" + ("0"+hrs).substr(-2) + ":"
+ ("0"+min).substr(-2) + ":" + ("0"+min).substr(-2) + ":"
+ ("0"+sec).substr(-2); + ("0"+sec).substr(-2);
document.getElementById("date").innerHTML = date.toLocaleString('de-DE', {timeZone: 'UTC'}); var dSpan = document.getElementById("date")
if(0 != obj["ts_now"])
dSpan.innerHTML = date.toLocaleString('de-DE', {timeZone: 'UTC'});
else {
var e = inp("set", "sync from browser", 0, ["btn"], "set", "button");
dSpan.appendChild(span("NTP timeserver unreachable. "));
dSpan.appendChild(e);
dSpan.appendChild(span("", ["span"], "apiResult"));
e.addEventListener("click", setTime);
}
} }
function parseStat(obj) { function parseStat(obj) {

Loading…
Cancel
Save