mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 02:34:29 +05:00
refactor: added doc.clear() doc.shrinkToFit() in some code areas
This commit is contained in:
@@ -505,6 +505,7 @@ protected:
|
||||
bool publishSettings(const char* topic) {
|
||||
JsonDocument doc;
|
||||
safeSettingsToJson(settings, doc);
|
||||
doc.shrinkToFit();
|
||||
|
||||
return this->writer->publish(topic, doc, true);
|
||||
}
|
||||
@@ -512,6 +513,7 @@ protected:
|
||||
bool publishVariables(const char* topic) {
|
||||
JsonDocument doc;
|
||||
varsToJson(vars, doc);
|
||||
doc.shrinkToFit();
|
||||
|
||||
return this->writer->publish(topic, doc, true);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#define PORTAL_CACHE_TIME "" //"max-age=86400"
|
||||
#define PORTAL_CACHE_TIME "max-age=86400"
|
||||
#define PORTAL_CACHE settings.system.debug ? nullptr : PORTAL_CACHE_TIME
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266WebServer.h>
|
||||
@@ -72,7 +72,6 @@ protected:
|
||||
this->dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
this->webServer->enableETag(true);
|
||||
//this->webServer->getServer().setNoDelay(true);
|
||||
#endif
|
||||
|
||||
// index page
|
||||
@@ -183,11 +182,13 @@ protected:
|
||||
|
||||
JsonDocument networkSettingsDoc;
|
||||
networkSettingsToJson(networkSettings, networkSettingsDoc);
|
||||
networkSettingsDoc.shrinkToFit();
|
||||
|
||||
JsonDocument settingsDoc;
|
||||
settingsToJson(settings, settingsDoc);
|
||||
JsonDocument doc;
|
||||
settingsDoc.shrinkToFit();
|
||||
|
||||
JsonDocument doc;
|
||||
doc["network"] = networkSettingsDoc;
|
||||
doc["settings"] = settingsDoc;
|
||||
doc.shrinkToFit();
|
||||
@@ -261,6 +262,8 @@ protected:
|
||||
|
||||
JsonDocument doc;
|
||||
networkSettingsToJson(networkSettings, doc);
|
||||
doc.shrinkToFit();
|
||||
|
||||
this->bufferedWebServer->send(200, "application/json", doc);
|
||||
});
|
||||
|
||||
@@ -292,7 +295,11 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
if (jsonToNetworkSettings(doc, networkSettings)) {
|
||||
bool changed = jsonToNetworkSettings(doc, networkSettings);
|
||||
doc.clear();
|
||||
doc.shrinkToFit();
|
||||
|
||||
if (changed) {
|
||||
this->webServer->send(201);
|
||||
|
||||
fsNetworkSettings.update();
|
||||
@@ -383,6 +390,8 @@ protected:
|
||||
|
||||
JsonDocument doc;
|
||||
settingsToJson(settings, doc);
|
||||
doc.shrinkToFit();
|
||||
|
||||
this->bufferedWebServer->send(200, "application/json", doc);
|
||||
});
|
||||
|
||||
@@ -414,7 +423,11 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
if (jsonToSettings(doc, settings)) {
|
||||
bool changed = jsonToSettings(doc, settings);
|
||||
doc.clear();
|
||||
doc.shrinkToFit();
|
||||
|
||||
if (changed) {
|
||||
fsSettings.update();
|
||||
this->webServer->send(201);
|
||||
|
||||
@@ -470,7 +483,11 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
if (jsonToVars(doc, vars)) {
|
||||
bool changed = jsonToVars(doc, vars);
|
||||
doc.clear();
|
||||
doc.shrinkToFit();
|
||||
|
||||
if (changed) {
|
||||
this->webServer->send(201);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -111,8 +111,6 @@ void networkSettingsToJson(const NetworkSettings& src, JsonVariant dst) {
|
||||
dst["sta"]["ssid"] = src.sta.ssid;
|
||||
dst["sta"]["password"] = src.sta.password;
|
||||
dst["sta"]["channel"] = src.sta.channel;
|
||||
|
||||
//dst.shrinkToFit();
|
||||
}
|
||||
|
||||
bool jsonToNetworkSettings(const JsonVariantConst src, NetworkSettings& dst) {
|
||||
@@ -309,8 +307,6 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
|
||||
dst["externalPump"]["antiStuckInterval"] = roundd(src.externalPump.antiStuckInterval / 86400, 0);
|
||||
dst["externalPump"]["antiStuckTime"] = roundd(src.externalPump.antiStuckTime / 60, 0);
|
||||
}
|
||||
|
||||
//dst.shrinkToFit();
|
||||
}
|
||||
|
||||
void safeSettingsToJson(const Settings& src, JsonVariant dst) {
|
||||
@@ -893,8 +889,6 @@ void varsToJson(const Variables& src, JsonVariant dst) {
|
||||
dst["parameters"]["heatingSetpoint"] = src.parameters.heatingSetpoint;
|
||||
dst["parameters"]["dhwMinTemp"] = src.parameters.dhwMinTemp;
|
||||
dst["parameters"]["dhwMaxTemp"] = src.parameters.dhwMaxTemp;
|
||||
|
||||
//dst.shrinkToFit();
|
||||
}
|
||||
|
||||
bool jsonToVars(const JsonVariantConst src, Variables& dst) {
|
||||
|
||||
Reference in New Issue
Block a user