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.
 
 
 
 
 
 

300 lines
13 KiB

<!doctype html>
<html>
<head>
<title>Setup - {#DEVICE}</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
function toggle(name, hide) {
var elm = document.getElementsByName(name)[0];
if(hide) {
if(!elm.classList.contains("hide"))
elm.classList.add("hide");
}
else
elm.classList.remove('hide');
}
function load() {
document.querySelectorAll('input[name^="inv"][name$="Addr"]').forEach(elm => {
elm.addEventListener("keyup", (e) => {
serial = elm.value.substring(0,4);
iv = elm.name.substring(3,4);
max = 0;
for(i=0;i<4;i++) {
toggle("inv"+iv+"ModPwr"+i, true);
toggle("inv"+iv+"ModName"+i, true);
}
toggle("lbl"+iv+"ModPwr", true);
toggle("lbl"+iv+"ModName", true);
if(serial == "1161") max = 4;
else if(serial == "1141") max = 2;
else if(serial == "1121") max = 1;
for(i=0;i<max;i++) {
toggle("inv"+iv+"ModPwr"+i, false);
toggle("inv"+iv+"ModName"+i, false);
}
if(max != 0) {
toggle("lbl"+iv+"ModPwr", false);
toggle("lbl"+iv+"ModName", false);
}
});
evt = document.createEvent("HTMLEvents");
evt.initEvent("keyup", false, true);
elm.dispatchEvent(evt);
});
}
</script>
</head>
<body onload="load()">
<h1>Setup</h1>
<div id="setup" class="content">
<div id="content">
<a class="erase" href="/erase">ERASE SETTINGS (not WiFi)</a>
<form method="post" action="/save">
<fieldset>
<legend class="des">Device Host Name</legend>
<label for="device">Device Name</label>
<input type="text" name="device" class="text"/>
</fieldset>
<button type="button" class="s_collapsible">WiFi</button>
<div class="s_content">
<fieldset>
<legend class="des">WiFi</legend>
<p>Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.</p>
<label for="ssid">SSID</label>
<input type="text" name="ssid" class="text"/>
<label for="pwd">Password</label>
<input type="password" class="text" name="pwd" value="{#PWD}"/>
</fieldset>
</div>
<button type="button" class="s_collapsible">Inverter</button>
<div class="s_content">
<fieldset>
<legend class="des">Inverter</legend>
<div id="inverter"></div><br/>
<p class="subdes">General</p>
<label for="invInterval">Interval [s]</label>
<input type="text" class="text" name="invInterval"/>
<label for="invRetry">Max retries per Payload</label>
<input type="text" class="text" name="invRetry"/>
</fieldset>
</div>
<button type="button" class="s_collapsible">NTP Server</button>
<div class="s_content">
<fieldset>
<legend class="des">NTP Server</legend>
<label for="ntpAddr">NTP Server / IP</label>
<input type="text" class="text" name="ntpAddr" value="{#NTP_ADDR}"/>
<label for="ntpPort">NTP Port</label>
<input type="text" class="text" name="ntpPort" value="{#NTP_PORT}"/>
</fieldset>
</div>
<button type="button" class="s_collapsible">MQTT</button>
<div class="s_content">
<fieldset>
<legend class="des">MQTT</legend>
<label for="mqttAddr">Broker / Server IP</label>
<input type="text" class="text" name="mqttAddr"/>
<label for="mqttPort">Port</label>
<input type="text" class="text" name="mqttPort"/>
<label for="mqttUser">Username (optional)</label>
<input type="text" class="text" name="mqttUser"/>
<label for="mqttPwd">Password (optional)</label>
<input type="text" class="text" name="mqttPwd"/>
<label for="mqttTopic">Topic</label>
<input type="text" class="text" name="mqttTopic"/>
</fieldset>
</div>
<button type="button" class="s_collapsible">System Config</button>
<div class="s_content">
<fieldset>
<legend class="des">System Config</legend>
<p class="des">Pinout (Wemos)</p>
{#PINOUT}
<p class="des">Radio (NRF24L01+)</p>
<label for="rf24Power">Amplifier Power Level</label>
<select name="rf24Power">{#RF24}</select>
<p class="des">Serial Console</p>
<label for="serEn">print inverter data</label>
<input type="checkbox" class="cb" name="serEn" {#SER_VAL_CB}/><br/>
<label for="serDbg">Serial Debug</label>
<input type="checkbox" class="cb" name="serDbg" {#SER_DBG_CB}/><br/>
<label for="serIntvl">Interval [s]</label>
<input type="text" class="text" name="serIntvl" value="{#SER_INTVL}"/>
</fieldset>
</div>
<label for="reboot">Reboot device after successful save</label>
<input type="checkbox" class="cb" name="reboot"/>
<input type="submit" value="save" class="btn" />
</form>
</div>
</div>
<div id="footer">
<p class="left"><a href="/">Home</a></p>
<p class="left"><a href="/update">Update Firmware</a></p>
<p class="right">AHOY - {#VERSION}</p>
<p class="right"><a href="/factory">Factory Reset</a></p>
<p class="right"><a href="/reboot">Reboot</a></p>
</div>
<script type="text/javascript">
var coll = document.getElementsByClassName("s_collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
content.style.display = (content.style.display === "block") ? "none" : "block";
});
}
function getAjax(url, ptr) {
var http = null;
http = new XMLHttpRequest();
if(http != null) {
http.open("GET", url, true);
http.onreadystatechange = p;
http.send(null);
}
function p() {
if(http.readyState == 4)
ptr(http.responseText);
}
}
function des(val) {
e = document.createElement('p');
e.classList.add("subdes");
e.innerHTML = val;
return e;
}
function lbl(id, val) {
e = document.createElement('label');
e.htmlFor = id;
e.innerHTML = val;
return e;
}
function inp(name, val, max=32, cl=["text"]) {
e = document.createElement('input');
e.classList.add(...cl);
e.name = name;
e.value = val;
e.maxLength = max;
return e;
}
function sel(name, opt, selId) {
e = document.createElement('select');
e.name = name;
for(i = 0; i < opt.length; i++) {
o = document.createElement('option');
o.value = opt[i][0];
o.innerHTML = opt[i][1];
if(opt[i][0] == selId)
o.selected = true;
e.appendChild(o);
}
return e;
}
function div(cl) {
e = document.createElement('div');
e.classList.add(cl);
return e;
}
function ivHtml(obj, id) {
iv = document.getElementById("inverter");
id = "inv" + id;
iv.appendChild(des("Inverter " + id));
iv.appendChild(lbl(id + "Addr", "Adress*"));
iv.appendChild(inp(id + "Addr", obj.serial, 12));
iv.appendChild(lbl(id + "Name", "Name*"));
iv.appendChild(inp(id + "Name", obj.name));
iv.appendChild(lbl(id + "ActivePowerLimit", "Active Power Limit"));
iv.appendChild(inp(id + "ActivePowerLimit", obj.power_limit.limit, 5));
iv.appendChild(lbl(id + "ActivePowerLimitConType", "Active Power Limit Control Type"));
iv.appendChild(sel(id + "ActivePowerLimitConType", [
[65535, "no power limit"],
[0, "absolute in Watt non persistent"],
[1, "absolute in Watt persistent"],
[256, "relativ in percent non persistent"],
[257, "relativ in percent persistent"]
], obj.power_limit.limit_option));
iv.appendChild(lbl(id + "ModPwr", "Max Module Power (Wp)"));
d = div("modpwr");
for(i = 0; i < obj.channels; i++) {
d.appendChild(inp(id + "ModPwr" + i, obj.ch_max_power[i], 4, ["text", "sh"]))
}
iv.appendChild(d);
iv.appendChild(lbl(id + "ModName", "Module Name"));
d = div("modname");
for(i = 0; i < obj.channels; i++) {
d.appendChild(inp(id + "ModName" + i, obj.ch_name[i], 4, ["text", "sh"]))
}
iv.appendChild(d);
}
function ivGlob(obj) {
e = document.getElementsByName("invInterval");
e[0].value = obj["interval"];
e = document.getElementsByName("invRetry");
e[0].value = obj["retries"];
}
function parseSys(json) {
obj = JSON.parse(json);
e = document.getElementsByName("device");
e[0].value = obj.device_name;
e = document.getElementsByName("ssid");
e[0].value = obj.ssid;
}
function parseIv(json) {
obj = JSON.parse(json);
ivHtml(obj.inverter[0], 0);
ivGlob(obj);
}
function parseMqtt(json) {
obj = JSON.parse(json);
e = document.getElementsByName("mqttAddr");
e[0].value = obj["broker"];
e = document.getElementsByName("mqttPort");
e[0].value = obj["port"];
e = document.getElementsByName("mqttUser");
e[0].value = obj["user"];
e = document.getElementsByName("mqttPwd");
e[0].value = obj["pwd"];
e = document.getElementsByName("mqttTopic");
e[0].value = obj["topic"];
}
getAjax("/api/system", parseSys);
getAjax("/api/inverter/list", parseIv);
getAjax("/api/mqtt", parseMqtt);
</script>
</body>
</html>