mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-11 07:56:39 +02:00
* started to implement POST api
* improved web serial console * added multi inverter total values (published through MQTT) * fixed: after boot there were transferred wrong data because of incorrect assignment (mqtt, visualization) -> not tested with sun
This commit is contained in:
parent
9e1b6be70e
commit
6bd7e01f1a
13 changed files with 404 additions and 379 deletions
|
@ -8,17 +8,19 @@ function toggle(name, hide) {
|
|||
elm.classList.remove('hide');
|
||||
}
|
||||
|
||||
function getAjax(url, ptr) {
|
||||
var http = new XMLHttpRequest();
|
||||
if(http != null) {
|
||||
http.open("GET", url, true);
|
||||
http.onreadystatechange = p;
|
||||
http.send(null);
|
||||
function getAjax(url, ptr, method="GET", json=null) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
if(xhr != null) {
|
||||
xhr.open(method, url, true);
|
||||
xhr.onreadystatechange = p;
|
||||
if("POST" == method)
|
||||
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
xhr.send(json);
|
||||
}
|
||||
function p() {
|
||||
if(http.readyState == 4) {
|
||||
if(null != http.responseText)
|
||||
ptr(JSON.parse(http.responseText));
|
||||
if(xhr.readyState == 4) {
|
||||
if(null != xhr.responseText)
|
||||
ptr(JSON.parse(xhr.responseText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,19 @@
|
|||
<div class="serial">
|
||||
<textarea id="serial" cols="80" rows="20" readonly></textarea><br/>
|
||||
conntected: <span class="dot" id="connected"></span> Uptime: <span id="uptime"></span><input type="button" value="clear" class="btn" id="clear"/> <input type="button" value="autoscroll" class="btn" id="scroll"/>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<hr>
|
||||
<h3>handle next buttons with care - test / debug only!!</h3>
|
||||
<br/>
|
||||
<input type="button" value="power limit 100%" class="btn" id="pwrlim2"/>
|
||||
<input type="button" value="power limit 10%" class="btn" id="pwrlim"/>
|
||||
<input type="button" value="Turn Off" class="btn" id="turnoff"/>
|
||||
<input type="button" value="Turn On" class="btn" id="turnon"/><br/>
|
||||
Ctrl result: <span id="result">n/a</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer">
|
||||
|
@ -70,6 +83,45 @@
|
|||
}
|
||||
|
||||
getAjax("/api/system", parseSys);
|
||||
|
||||
// only for test
|
||||
function ctrlCb(obj) {
|
||||
var e = document.getElementById("result");
|
||||
if(obj["success"])
|
||||
e.innerHTML = "ok";
|
||||
else
|
||||
e.innerHTML = "Error: " + obj["error"];
|
||||
}
|
||||
|
||||
document.getElementById("turnon").addEventListener("click", function() {
|
||||
var obj = new Object();
|
||||
obj.cmd = 0;
|
||||
obj.tx_request = 81;
|
||||
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
|
||||
});
|
||||
|
||||
document.getElementById("turnoff").addEventListener("click", function() {
|
||||
var obj = new Object();
|
||||
obj.cmd = 1;
|
||||
obj.tx_request = 81;
|
||||
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
|
||||
});
|
||||
|
||||
document.getElementById("pwrlim").addEventListener("click", function() {
|
||||
var obj = new Object();
|
||||
obj.cmd = 11;
|
||||
obj.tx_request = 81;
|
||||
obj.payload = [10, 1];
|
||||
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
|
||||
});
|
||||
|
||||
document.getElementById("pwrlim2").addEventListener("click", function() {
|
||||
var obj = new Object();
|
||||
obj.cmd = 11;
|
||||
obj.tx_request = 81;
|
||||
obj.payload = [2000, 1];
|
||||
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -48,10 +48,10 @@
|
|||
ch0.appendChild(sub);
|
||||
|
||||
switch(j) {
|
||||
case 2: total[j] += val; break; // P_AC
|
||||
case 6: total[j] += val; break; // YieldTotal
|
||||
case 7: total[j] += val; break; // YieldDay
|
||||
case 8: total[j] += val; break; // P_DC
|
||||
case 2: total[j] += val; break; // P_AC
|
||||
case 6: total[j] += val; break; // YieldTotal
|
||||
case 7: total[j] += val; break; // YieldDay
|
||||
case 8: total[j] += val; break; // P_DC
|
||||
case 10: total[j] += val; break; // P_ACr
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue