You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

220 lines
9.4 KiB

<!doctype html>
<html>
<head>
<title>Index</title>
{#HTML_HEADER}
</head>
<body>
{#HTML_NAV}
<div id="wrapper">
<div id="content">
<p>
<span class="des">Uptime: </span><span id="uptime"></span><br/>
<span class="des">ESP-Time: </span><span id="date"></span>
</p>
<p>
<span class="des">System Infos:</span>
<div id="iv"></div>
<div class="hr"></div>
<div id="warn_info"></div>
</p>
<div id="note">
<h3>Support this project:</h3>
<ul>
<li><a href="https://github.com/lumapu/ahoy/blob/main/src/CHANGES.md" target="_blank">Changelog</a></li>
<li>Discuss with us on <a href="https://discord.gg/WzhxEY62mB">Discord</a></li>
<li>Report <a href="https://github.com/lumapu/ahoy/issues" target="_blank">issues</a></li>
<li>Contribute to <a href="https://github.com/lumapu/ahoy/blob/main/User_Manual.md" target="_blank">documentation</a></li>
<li><a href="https://nightly.link/lumapu/ahoy/workflows/compile_development/development03/ahoydtu_dev.zip" target="_blank">Download</a> & Test development firmware, <a href="https://github.com/lumapu/ahoy/blob/development03/src/CHANGES.md" target="_blank">Development Changelog</a></li>
<li>make a <a href="https://paypal.me/lupusch" target="_blank">donation</a></li>
</ul>
<p class="lic">
This project was started from <a href="https://www.mikrocontroller.net/topic/525778" target="_blank">this discussion. (Mikrocontroller.net)</a>
</p>
</div>
</div>
</div>
{#HTML_FOOTER}
<script type="text/javascript">
var exeOnce = true;
var tickCnt = 0;
var ts = 0;
var commInfo = "";
var release = null;
function apiCb(obj) {
var e = document.getElementById("apiResult");
if(obj.success) {
e.innerHTML = " command executed";
getAjax("/api/index", parse);
}
else
e.innerHTML = " Error: " + obj.error;
}
function setTime() {
var date = new Date();
var obj = new Object();
obj.cmd = "set_time";
obj.val = parseInt(date.getTime() / 1000);
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
}
function parseGeneric(obj) {
if(exeOnce)
parseESP(obj);
parseRssi(obj);
}
function parseSys(obj) {
ts = obj.ts_now;
var date = new Date(obj.ts_now * 1000);
var up = obj.generic["ts_uptime"];
var days = parseInt(up / 86400) % 365;
var hrs = parseInt(up / 3600) % 24;
var min = parseInt(up / 60) % 60;
var sec = up % 60;
var e = document.getElementById("uptime");
e.innerHTML = days + " Day";
if(1 != days)
e.innerHTML += "s";
e.innerHTML += ", " + ("0"+hrs).substr(-2) + ":"
+ ("0"+min).substr(-2) + ":"
+ ("0"+sec).substr(-2);
var dSpan = document.getElementById("date");
if(0 != obj.ts_now) {
if(obj.ts_now < 1680000000)
setTime();
else
dSpan.innerHTML = toIsoDateStr(date);
}
else {
dSpan.innerHTML = "";
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);
}
if(obj.disNightComm) {
if(((obj.ts_sunrise + obj.ts_offsSr) < obj.ts_now)
&& ((obj.ts_sunset + obj.ts_offsSs) > obj.ts_now)) {
commInfo = "Polling inverter(s), will pause at sunset " + (new Date((obj.ts_sunset + obj.ts_offsSs) * 1000).toLocaleString('de-DE'));
}
else {
commInfo = "Night time, inverter polling disabled, ";
if(obj.ts_now > (obj.ts_sunrise + obj.ts_offsSr)) {
commInfo += "paused at " + (new Date((obj.ts_sunset + obj.ts_offsSs) * 1000).toLocaleString('de-DE'));
}
else {
commInfo += "will start polling at " + (new Date((obj.ts_sunrise + obj.ts_offsSr) * 1000).toLocaleString('de-DE'));
}
}
}
}
function parseIv(obj, ts) {
var p = div(["none"]);
for(var i of obj) {
var icon = iconSuccess;
var cl = "icon-success";
var avail = "";
if(false == i["enabled"]) {
icon = iconWarn;
cl = "icon-warn";
avail = "disabled";
} else if((false == i["is_avail"]) || (0 == ts)) {
icon = iconInfo;
cl = "icon-info";
avail = "not yet available";
} else if(0 == i["ts_last_success"]) {
avail = "available but no data was received until now";
} else {
avail = "available and is ";
if(false == i["is_producing"])
avail += "not producing";
else {
icon = iconSuccessFull;
avail += "producing " + i.cur_pwr + "W";
}
}
p.append(
svg(icon, 30, 30, "icon " + cl),
span("Inverter #" + i["id"] + ": " + i["name"] + " is " + avail),
br()
);
if(false == i["is_avail"]) {
if(i["ts_last_success"] > 0) {
var date = new Date(i["ts_last_success"] * 1000);
p.append(span("-> last successful transmission: " + toIsoDateStr(date)), br());
}
}
}
document.getElementById("iv").replaceChildren(p);
}
function parseWarn(warn) {
var p = div(["none"]);
for(var w of warn) {
p.append(svg(iconWarn, 30, 30, "icon icon-warn"), span(w), br());
}
if(commInfo.length > 0)
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span(commInfo), br());
if(null != release) {
if(getVerInt("{#VERSION}") < getVerInt(release))
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("Update available, current released version: " + release), br());
else if(getVerInt("{#VERSION}") > getVerInt(release))
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("You are using development version {#VERSION}. In case of issues you may want to try the current stable release: " + release), br());
else
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("You are using the current stable release: " + release), br());
}
document.getElementById("warn_info").replaceChildren(p);
}
function tick() {
if(0 != ts)
document.getElementById("date").innerHTML = toIsoDateStr((new Date((++ts) * 1000)));
if(++tickCnt >= 10) {
tickCnt = 0;
getAjax('/api/index', parse);
}
}
function parse(obj) {
if(null != obj) {
if(exeOnce)
parseNav(obj.generic);
parseGeneric(obj.generic);
parseSys(obj);
parseIv(obj.inverter, obj.ts_now);
parseWarn(obj.warnings);
if(exeOnce) {
window.setInterval("tick()", 1000);
exeOnce = false;
getAjax("https://api.github.com/repos/lumapu/ahoy/releases/latest", parseRelease);
}
}
}
function getVerInt(ver) {
var a = ver.split('.');
return (a[0] << 24) | (a[1] << 16) | a[2];
}
function parseRelease(obj) {
release = obj.name.substring(6);
getAjax("/api/index", parse);
}
getAjax("/api/index", parse);
</script>
</body>
</html>