diff --git a/include/WebApi.h b/include/WebApi.h index d8895f94f..39e7fd101 100644 --- a/include/WebApi.h +++ b/include/WebApi.h @@ -35,7 +35,7 @@ class WebApiClass { static void sendTooManyRequests(AsyncWebServerRequest* request); - static void writeConfig(JsonObject& retMsg, const WebApiError code = WebApiError::GenericSuccess, const String& message = "Settings saved!"); + static void writeConfig(JsonVariant& retMsg, const WebApiError code = WebApiError::GenericSuccess, const String& message = "Settings saved!"); private: void loop(); diff --git a/src/WebApi.cpp b/src/WebApi.cpp index b7c85c503..b50d32002 100644 --- a/src/WebApi.cpp +++ b/src/WebApi.cpp @@ -101,7 +101,7 @@ void WebApiClass::sendTooManyRequests(AsyncWebServerRequest* request) request->send(response); } -void WebApiClass::writeConfig(JsonObject& retMsg, const WebApiError code, const String& message) +void WebApiClass::writeConfig(JsonVariant& retMsg, const WebApiError code, const String& message) { if (!Configuration.write()) { retMsg["message"] = "Write failed!"; diff --git a/src/WebApi_config.cpp b/src/WebApi_config.cpp index e466c79c9..73df1e3d0 100644 --- a/src/WebApi_config.cpp +++ b/src/WebApi_config.cpp @@ -59,7 +59,7 @@ void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { @@ -125,8 +125,8 @@ void WebApiConfigClass::onConfigListGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); - JsonArray data = root.createNestedArray("configs"); + auto& root = response->getRoot(); + auto data = root.createNestedArray("configs"); File rootfs = LittleFS.open("/"); File file = rootfs.openNextFile(); diff --git a/src/WebApi_device.cpp b/src/WebApi_device.cpp index 9d241dfab..c8c216e86 100644 --- a/src/WebApi_device.cpp +++ b/src/WebApi_device.cpp @@ -33,14 +33,14 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); const PinMapping_t& pin = PinMapping.get(); - JsonObject curPin = root.createNestedObject("curPin"); + auto curPin = root.createNestedObject("curPin"); curPin["name"] = config.Dev_PinMapping; - JsonObject nrfPinObj = curPin.createNestedObject("nrf24"); + auto nrfPinObj = curPin.createNestedObject("nrf24"); nrfPinObj["clk"] = pin.nrf24_clk; nrfPinObj["cs"] = pin.nrf24_cs; nrfPinObj["en"] = pin.nrf24_en; @@ -48,7 +48,7 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) nrfPinObj["miso"] = pin.nrf24_miso; nrfPinObj["mosi"] = pin.nrf24_mosi; - JsonObject cmtPinObj = curPin.createNestedObject("cmt"); + auto cmtPinObj = curPin.createNestedObject("cmt"); cmtPinObj["clk"] = pin.cmt_clk; cmtPinObj["cs"] = pin.cmt_cs; cmtPinObj["fcs"] = pin.cmt_fcs; @@ -56,7 +56,7 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) cmtPinObj["gpio2"] = pin.cmt_gpio2; cmtPinObj["gpio3"] = pin.cmt_gpio3; - JsonObject ethPinObj = curPin.createNestedObject("eth"); + auto ethPinObj = curPin.createNestedObject("eth"); ethPinObj["enabled"] = pin.eth_enabled; ethPinObj["phy_addr"] = pin.eth_phy_addr; ethPinObj["power"] = pin.eth_power; @@ -65,19 +65,19 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) ethPinObj["type"] = pin.eth_type; ethPinObj["clk_mode"] = pin.eth_clk_mode; - JsonObject displayPinObj = curPin.createNestedObject("display"); + auto displayPinObj = curPin.createNestedObject("display"); displayPinObj["type"] = pin.display_type; displayPinObj["data"] = pin.display_data; displayPinObj["clk"] = pin.display_clk; displayPinObj["cs"] = pin.display_cs; displayPinObj["reset"] = pin.display_reset; - JsonObject ledPinObj = curPin.createNestedObject("led"); + auto ledPinObj = curPin.createNestedObject("led"); for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) { ledPinObj["led" + String(i)] = pin.led[i]; } - JsonObject display = root.createNestedObject("display"); + auto display = root.createNestedObject("display"); display["rotation"] = config.Display.Rotation; display["power_safe"] = config.Display.PowerSafe; display["screensaver"] = config.Display.ScreenSaver; @@ -85,9 +85,9 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) display["language"] = config.Display.Language; display["diagramduration"] = config.Display.DiagramDuration; - JsonArray leds = root.createNestedArray("led"); + auto leds = root.createNestedArray("led"); for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) { - JsonObject led = leds.createNestedObject(); + auto led = leds.createNestedObject(); led["brightness"] = config.Led_Single[i].Brightness; } @@ -102,7 +102,7 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_devinfo.cpp b/src/WebApi_devinfo.cpp index 04b8a581d..b5f3e3707 100644 --- a/src/WebApi_devinfo.cpp +++ b/src/WebApi_devinfo.cpp @@ -28,7 +28,7 @@ void WebApiDevInfoClass::onDevInfoStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); uint64_t serial = 0; if (request->hasParam("inv")) { diff --git a/src/WebApi_dtu.cpp b/src/WebApi_dtu.cpp index 6e22a6318..c8a87678f 100644 --- a/src/WebApi_dtu.cpp +++ b/src/WebApi_dtu.cpp @@ -30,7 +30,7 @@ void WebApiDtuClass::onDtuAdminGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); // DTU Serial is read as HEX @@ -57,7 +57,7 @@ void WebApiDtuClass::onDtuAdminPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_eventlog.cpp b/src/WebApi_eventlog.cpp index e0c8b3164..0551978af 100644 --- a/src/WebApi_eventlog.cpp +++ b/src/WebApi_eventlog.cpp @@ -27,7 +27,7 @@ void WebApiEventlogClass::onEventlogStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, 2048); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); uint64_t serial = 0; if (request->hasParam("inv")) { diff --git a/src/WebApi_gridprofile.cpp b/src/WebApi_gridprofile.cpp index ee945bc44..a5793e772 100644 --- a/src/WebApi_gridprofile.cpp +++ b/src/WebApi_gridprofile.cpp @@ -28,7 +28,7 @@ void WebApiGridProfileClass::onGridProfileStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, 8192); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); uint64_t serial = 0; if (request->hasParam("inv")) { @@ -72,7 +72,7 @@ void WebApiGridProfileClass::onGridProfileRawdata(AsyncWebServerRequest* request } AsyncJsonResponse* response = new AsyncJsonResponse(false, 4096); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); uint64_t serial = 0; if (request->hasParam("inv")) { diff --git a/src/WebApi_inverter.cpp b/src/WebApi_inverter.cpp index dcec28c85..7538b2c03 100644 --- a/src/WebApi_inverter.cpp +++ b/src/WebApi_inverter.cpp @@ -36,7 +36,7 @@ void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, 768 * INV_MAX_COUNT); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); JsonArray data = root.createNestedArray("inverter"); const CONFIG_T& config = Configuration.get(); @@ -94,7 +94,7 @@ void WebApiInverterClass::onInverterAdd(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { @@ -191,7 +191,7 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { @@ -333,7 +333,7 @@ void WebApiInverterClass::onInverterDelete(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { @@ -404,7 +404,7 @@ void WebApiInverterClass::onInverterOrder(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_limit.cpp b/src/WebApi_limit.cpp index 1e5b3f212..8bf0c9426 100644 --- a/src/WebApi_limit.cpp +++ b/src/WebApi_limit.cpp @@ -31,7 +31,7 @@ void WebApiLimitClass::onLimitStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) { auto inv = Hoymiles.getInverterByPos(i); @@ -64,7 +64,7 @@ void WebApiLimitClass::onLimitPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_maintenance.cpp b/src/WebApi_maintenance.cpp index 8b65c9352..0c62394cf 100644 --- a/src/WebApi_maintenance.cpp +++ b/src/WebApi_maintenance.cpp @@ -29,7 +29,7 @@ void WebApiMaintenanceClass::onRebootPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_mqtt.cpp b/src/WebApi_mqtt.cpp index 368f770f2..32c7568ca 100644 --- a/src/WebApi_mqtt.cpp +++ b/src/WebApi_mqtt.cpp @@ -33,7 +33,7 @@ void WebApiMqttClass::onMqttStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); root["mqtt_enabled"] = config.Mqtt.Enabled; @@ -67,7 +67,7 @@ void WebApiMqttClass::onMqttAdminGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); root["mqtt_enabled"] = config.Mqtt.Enabled; @@ -105,7 +105,7 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_network.cpp b/src/WebApi_network.cpp index bb6271b69..b95beb34f 100644 --- a/src/WebApi_network.cpp +++ b/src/WebApi_network.cpp @@ -32,7 +32,7 @@ void WebApiNetworkClass::onNetworkStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); root["sta_status"] = ((WiFi.getMode() & WIFI_STA) != 0); root["sta_ssid"] = WiFi.SSID(); @@ -63,7 +63,7 @@ void WebApiNetworkClass::onNetworkAdminGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); root["hostname"] = config.WiFi.Hostname; @@ -89,7 +89,7 @@ void WebApiNetworkClass::onNetworkAdminPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_ntp.cpp b/src/WebApi_ntp.cpp index ff397628e..2eb4c087d 100644 --- a/src/WebApi_ntp.cpp +++ b/src/WebApi_ntp.cpp @@ -35,7 +35,7 @@ void WebApiNtpClass::onNtpStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); root["ntp_server"] = config.Ntp.Server; @@ -80,7 +80,7 @@ void WebApiNtpClass::onNtpAdminGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); root["ntp_server"] = config.Ntp.Server; @@ -101,7 +101,7 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { @@ -198,7 +198,7 @@ void WebApiNtpClass::onNtpTimeGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); struct tm timeinfo; if (!getLocalTime(&timeinfo, 5)) { @@ -225,7 +225,7 @@ void WebApiNtpClass::onNtpTimePost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_power.cpp b/src/WebApi_power.cpp index 3fa47984c..697c1e87a 100644 --- a/src/WebApi_power.cpp +++ b/src/WebApi_power.cpp @@ -29,7 +29,7 @@ void WebApiPowerClass::onPowerStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) { auto inv = Hoymiles.getInverterByPos(i); @@ -57,7 +57,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { diff --git a/src/WebApi_security.cpp b/src/WebApi_security.cpp index 2b5fa4894..8e6815d8e 100644 --- a/src/WebApi_security.cpp +++ b/src/WebApi_security.cpp @@ -31,7 +31,7 @@ void WebApiSecurityClass::onSecurityGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); const CONFIG_T& config = Configuration.get(); root["password"] = config.Security.Password; @@ -48,7 +48,7 @@ void WebApiSecurityClass::onSecurityPost(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "warning"; if (!request->hasParam("data", true)) { @@ -115,7 +115,7 @@ void WebApiSecurityClass::onAuthenticateGet(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject retMsg = response->getRoot(); + auto& retMsg = response->getRoot(); retMsg["type"] = "success"; retMsg["message"] = "Authentication successful!"; retMsg["code"] = WebApiError::SecurityAuthSuccess; diff --git a/src/WebApi_sysstatus.cpp b/src/WebApi_sysstatus.cpp index 35904bf85..8cda1bd1a 100644 --- a/src/WebApi_sysstatus.cpp +++ b/src/WebApi_sysstatus.cpp @@ -36,7 +36,7 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request) } AsyncJsonResponse* response = new AsyncJsonResponse(); - JsonObject root = response->getRoot(); + auto& root = response->getRoot(); root["hostname"] = NetworkSettings.getHostname(); diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index 5ffdc7de1..a64db3a5c 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -222,7 +222,7 @@ void WebApiWsLiveClass::onLivedataStatus(AsyncWebServerRequest* request) try { std::lock_guard lock(_mutex); AsyncJsonResponse* response = new AsyncJsonResponse(false, 4096 * INV_MAX_COUNT); - JsonVariant root = response->getRoot(); + auto& root = response->getRoot(); generateJsonResponse(root);