Browse Source

Make change in serial.htm and webApi.cpp

pull/341/head
DanielR92 2 years ago
parent
commit
c3d81d36c6
  1. 2
      tools/esp8266/html/index.html
  2. 59
      tools/esp8266/html/serial.html
  3. 5
      tools/esp8266/webApi.cpp

2
tools/esp8266/html/index.html

@ -13,7 +13,7 @@
<a href="/live">Visualization</a><br/>
<br/>
<a href="/setup">Setup</a><br/>
<a href="/serial">Serial Console</a><br/>
<a href="/serial">Webserial & Commands</a><br/>
</p>
<p><span class="des">Uptime: </span><span id="uptime"></span></p>
<p><span class="des">ESP-Time: </span><span id="date"></span></p>

59
tools/esp8266/html/serial.html

@ -27,17 +27,17 @@
<select name="iv" id="InvID">
</select>
<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="Restart" class="btn" id="restart"/>
<input type="button" value="Turn Off" class="btn" id="turnoff"/>
<input type="button" value="Turn On" class="btn" id="turnon"/>
<div id='power'>
<input type="button" value="Restart" class="btn" id="restart"/>
<input type="button" value="Turn Off" class="btn" id="power_off"/>
<input type="button" value="Turn On" class="btn" id="power_on"/>
</div>
<br/>
<label>Send Power Limit:</label>
<input type="text" class="text" name="pwrlimval" maxlength="4" size="20%"/>
<input type="number" class="text" name="pwrlimval" maxlength="4" size="20%"/>
<label></label>
<select name="pwrlimcntrl" id="pwrlimcntrl">
<option value="65535">select the unit and persistence</option>
<option value="65535" selected disabled hidden>select the unit and persistence</option>
<option value="0">absolute in Watt non persistent</option>
<option value="1">relativ in percent non persistent</option>
<option value="256">absolute in Watt persistent</option>
@ -132,48 +132,39 @@
function get_selected_iv()
{
var e = document.getElementById("InvID");
return e.value;
return parseInt(e.value);
}
document.getElementById("turnon").addEventListener("click", function() {
var obj = new Object();
obj.inverter = get_selected_iv();
obj.cmd = 0;
obj.tx_request = 81;
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
});
const wrapper = document.getElementById('power');
document.getElementById("turnoff").addEventListener("click", function() {
wrapper.addEventListener('click', (event) => {
var power = event.target.value;
var obj = new Object();
obj.inverter = get_selected_iv();
obj.cmd = 1;
obj.tx_request = 81;
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
});
document.getElementById("restart").addEventListener("click", function() {
var obj = new Object();
obj.inverter = get_selected_iv();
obj.cmd = 2;
obj.tx_request = 81;
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
});
if(power === "Restart") {
obj.cmd = 0;
} else if(power === "Turn Off") {
obj.cmd = 1;
} else {
obj.cmd = 2;
}
document.getElementById("pwrlim").addEventListener("click", function() {
var obj = new Object();
obj.inverter = get_selected_iv();
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() {
document.getElementById("sendpwrlim").addEventListener("click", function() {
var power = parseInt(document.getElementsByName('pwrlimval')[0].value);
var type = parseInt(document.getElementsByName('pwrlimcntrl')[0].value);
if((type == 1 || type == 257) && power < 2) power = 2;
var obj = new Object();
obj.inverter = get_selected_iv();
obj.cmd = 11;
obj.tx_request = 81;
obj.payload = [100, 1];
obj.payload = [power, type];
getAjax("/api/ctrl", ctrlCb, "POST", JSON.stringify(obj));
});

5
tools/esp8266/webApi.cpp

@ -336,8 +336,9 @@ bool webApi::setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
// Todo: num is the inverter number 0-3. For better display in DPRINTLN
uint8_t num = jsonIn[F("inverter")];
uint8_t tx_request = jsonIn[F("tx_request")];
if(TX_REQ_DEVCONTROL == jsonIn[F("tx_request")])
if(TX_REQ_DEVCONTROL == tx_request)
{
DPRINTLN(DBG_INFO, F("devcontrol [") + String(num) + F("], cmd: 0x") + String(cmd, HEX));
@ -365,6 +366,8 @@ bool webApi::setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
iv->devControlRequest = true;
break;
case ActivePowerContr:
iv->devControlCmd = ActivePowerContr;
iv->devControlRequest = true;
iv->powerLimit[0] = payload[0];
iv->powerLimit[1] = payload[1];
break;

Loading…
Cancel
Save