Implemented inverter restart via web ui
This commit is contained in:
parent
da0998c809
commit
88ad6495d1
@ -39,11 +39,9 @@ void WebApiPowerClass::onPowerStatus(AsyncWebServerRequest* request)
|
|||||||
String limitStatus = "Unknown";
|
String limitStatus = "Unknown";
|
||||||
if (status == LastCommandSuccess::CMD_OK) {
|
if (status == LastCommandSuccess::CMD_OK) {
|
||||||
limitStatus = "Ok";
|
limitStatus = "Ok";
|
||||||
}
|
} else if (status == LastCommandSuccess::CMD_NOK) {
|
||||||
else if (status == LastCommandSuccess::CMD_NOK) {
|
|
||||||
limitStatus = "Failure";
|
limitStatus = "Failure";
|
||||||
}
|
} else if (status == LastCommandSuccess::CMD_PENDING) {
|
||||||
else if (status == LastCommandSuccess::CMD_PENDING) {
|
|
||||||
limitStatus = "Pending";
|
limitStatus = "Pending";
|
||||||
}
|
}
|
||||||
root[buffer]["power_set_status"] = limitStatus;
|
root[buffer]["power_set_status"] = limitStatus;
|
||||||
@ -86,7 +84,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(root.containsKey("serial")
|
if (!(root.containsKey("serial")
|
||||||
&& root.containsKey("power"))) {
|
&& (root.containsKey("power") || root.containsKey("restart")))) {
|
||||||
retMsg[F("message")] = F("Values are missing!");
|
retMsg[F("message")] = F("Values are missing!");
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
@ -101,8 +99,6 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t serial = strtoll(root[F("serial")].as<String>().c_str(), NULL, 16);
|
uint64_t serial = strtoll(root[F("serial")].as<String>().c_str(), NULL, 16);
|
||||||
uint16_t power = root[F("power")].as<bool>();
|
|
||||||
|
|
||||||
auto inv = Hoymiles.getInverterBySerial(serial);
|
auto inv = Hoymiles.getInverterBySerial(serial);
|
||||||
if (inv == nullptr) {
|
if (inv == nullptr) {
|
||||||
retMsg[F("message")] = F("Invalid inverter specified!");
|
retMsg[F("message")] = F("Invalid inverter specified!");
|
||||||
@ -111,7 +107,14 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root.containsKey("power")) {
|
||||||
|
uint16_t power = root[F("power")].as<bool>();
|
||||||
inv->sendPowerControlRequest(Hoymiles.getRadio(), power);
|
inv->sendPowerControlRequest(Hoymiles.getRadio(), power);
|
||||||
|
} else {
|
||||||
|
if (root[F("restart")].as<bool>()) {
|
||||||
|
inv->sendRestartControlRequest(Hoymiles.getRadio());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
retMsg[F("type")] = F("success");
|
retMsg[F("type")] = F("success");
|
||||||
retMsg[F("message")] = F("Settings saved!");
|
retMsg[F("message")] = F("Settings saved!");
|
||||||
|
|||||||
@ -280,6 +280,9 @@
|
|||||||
<button type="button" class="btn btn-danger" @click="onSetPowerSettings(false)">
|
<button type="button" class="btn btn-danger" @click="onSetPowerSettings(false)">
|
||||||
<BIconToggleOff class="fs-4" /> Turn Off
|
<BIconToggleOff class="fs-4" /> Turn Off
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn btn-warning" @click="onSetPowerSettings(true, true)">
|
||||||
|
<BIconArrowCounterclockwise class="fs-4" /> Restart
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -568,11 +571,20 @@ export default defineComponent({
|
|||||||
this.showAlertPower = false;
|
this.showAlertPower = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
onSetPowerSettings(turnOn: boolean) {
|
onSetPowerSettings(turnOn: boolean, restart = false) {
|
||||||
const data = {
|
let data = {};
|
||||||
|
if (restart) {
|
||||||
|
data = {
|
||||||
|
serial: this.powerSettingSerial,
|
||||||
|
restart: true,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
data = {
|
||||||
serial: this.powerSettingSerial,
|
serial: this.powerSettingSerial,
|
||||||
power: turnOn,
|
power: turnOn,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("data", JSON.stringify(data));
|
formData.append("data", JSON.stringify(data));
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user