mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
Arduino v7
This commit is contained in:
@@ -27,8 +27,8 @@ uint16_t WebAPIService::api_fails_ = 0;
|
||||
|
||||
WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: _securityManager(securityManager)
|
||||
, _apiHandler("/api", std::bind(&WebAPIService::webAPIService_post, this, _1, _2), 256) { // for POSTS, must use 'Content-Type: application/json' in header
|
||||
server->on("/api", HTTP_GET, std::bind(&WebAPIService::webAPIService_get, this, _1)); // for GETS
|
||||
, _apiHandler("/api", std::bind(&WebAPIService::webAPIService_post, this, _1, _2)) { // for POSTS, must use 'Content-Type: application/json' in header
|
||||
server->on("/api", HTTP_GET, std::bind(&WebAPIService::webAPIService_get, this, _1)); // for GETS
|
||||
server->addHandler(&_apiHandler);
|
||||
|
||||
// for settings
|
||||
@@ -45,8 +45,8 @@ WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * security
|
||||
// GET /{device}/{entity}
|
||||
void WebAPIService::webAPIService_get(AsyncWebServerRequest * request) {
|
||||
// has no body JSON so create dummy as empty input object
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> input_doc;
|
||||
JsonObject input = input_doc.to<JsonObject>();
|
||||
JsonDocument input_doc;
|
||||
JsonObject input = input_doc.to<JsonObject>();
|
||||
parse(request, input);
|
||||
}
|
||||
|
||||
@@ -106,15 +106,14 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
||||
emsesp::EMSESP::system_.refreshHeapMem();
|
||||
|
||||
// output json buffer
|
||||
size_t buffer = EMSESP_JSON_SIZE_XXXLARGE;
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse(false, buffer);
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse(false);
|
||||
|
||||
// add more mem if needed - won't be needed in ArduinoJson 7
|
||||
while (!response->getSize()) {
|
||||
delete response;
|
||||
buffer -= 1024;
|
||||
response = new AsyncJsonResponse(false, buffer);
|
||||
}
|
||||
// while (!response->getSize()) {
|
||||
// delete response;
|
||||
// buffer -= 1024;
|
||||
// response = new AsyncJsonResponse(false, buffer);
|
||||
// }
|
||||
|
||||
JsonObject output = response->getRoot();
|
||||
|
||||
@@ -164,12 +163,12 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
||||
}
|
||||
|
||||
void WebAPIService::getSettings(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false, FS_BUFFER_SIZE);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
root["type"] = "settings";
|
||||
|
||||
JsonObject node = root.createNestedObject("System");
|
||||
JsonObject node = root["System"].add<JsonObject>();
|
||||
node["version"] = EMSESP_APP_VERSION;
|
||||
|
||||
System::extractSettings(NETWORK_SETTINGS_FILE, "Network", root);
|
||||
@@ -185,7 +184,7 @@ void WebAPIService::getSettings(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
void WebAPIService::getCustomizations(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false, FS_BUFFER_SIZE);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
root["type"] = "customizations";
|
||||
@@ -197,7 +196,7 @@ void WebAPIService::getCustomizations(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
void WebAPIService::getSchedule(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false, FS_BUFFER_SIZE);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
root["type"] = "schedule";
|
||||
@@ -209,7 +208,7 @@ void WebAPIService::getSchedule(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
void WebAPIService::getEntities(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false, FS_BUFFER_SIZE);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
root["type"] = "entities";
|
||||
|
||||
Reference in New Issue
Block a user