diff --git a/src/WebApi_inverter.cpp b/src/WebApi_inverter.cpp index f467fd5d..2fb254f9 100644 --- a/src/WebApi_inverter.cpp +++ b/src/WebApi_inverter.cpp @@ -53,13 +53,16 @@ void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request) obj[F("serial")] = buffer; auto inv = Hoymiles.getInverterBySerial(config.Inverter[i].Serial); + uint8_t max_channels; if (inv == nullptr) { obj[F("type")] = F("Unknown"); + max_channels = INV_MAX_CHAN_COUNT; } else { obj[F("type")] = inv->typeName(); + max_channels = inv->Statistics()->getChannelCount(); } - for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) { + for (uint8_t c = 0; c < max_channels; c++) { obj[F("max_power")][c] = config.Inverter[i].MaxChannelPower[c]; } } @@ -223,7 +226,7 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request) } JsonArray maxPowerArray = root[F("max_power")].as(); - if (maxPowerArray.size() != INV_MAX_CHAN_COUNT) { + if (maxPowerArray.size() == 0 || maxPowerArray.size() > INV_MAX_CHAN_COUNT) { retMsg[F("message")] = F("Invalid amount of max channel setting given!"); response->setLength(); request->send(response);