Arduino v7

This commit is contained in:
Proddy
2024-01-04 23:43:30 +01:00
parent 13a915e1f4
commit af237c4fc0
213 changed files with 3900 additions and 4479 deletions

View File

@@ -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";

View File

@@ -30,7 +30,7 @@ WebCustomEntityService::WebCustomEntityService(AsyncWebServer * server, FS * fs,
EMSESP_CUSTOMENTITY_SERVICE_PATH,
securityManager,
AuthenticationPredicates::IS_AUTHENTICATED)
, _fsPersistence(WebCustomEntity::read, WebCustomEntity::update, this, fs, EMSESP_CUSTOMENTITY_FILE, FS_BUFFER_SIZE) {
, _fsPersistence(WebCustomEntity::read, WebCustomEntity::update, this, fs, EMSESP_CUSTOMENTITY_FILE) {
}
// load the settings when the service starts
@@ -43,10 +43,10 @@ void WebCustomEntityService::begin() {
// this creates the entity file, saving it to the FS
// and also calls when the Entity web page is refreshed
void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject & root) {
JsonArray entity = root.createNestedArray("entities");
JsonArray entity = root["entities"].to<JsonArray>();
uint8_t counter = 0;
for (const CustomEntityItem & entityItem : webEntity.customEntityItems) {
JsonObject ei = entity.createNestedObject();
JsonObject ei = entity.add<JsonObject>();
ei["id"] = counter++; // id is only used to render the table and must be unique
ei["device_id"] = entityItem.device_id;
ei["type_id"] = entityItem.type_id;
@@ -70,7 +70,7 @@ StateUpdateResult WebCustomEntity::update(JsonObject & root, WebCustomEntity & w
const char * json =
"{\"entities\": [{\"id\":0,\"device_id\":8,\"type_id\":24,\"offset\":0,\"factor\":1,\"name\":\"boiler_flowtemp\",\"uom\":1,\"value_type\":1,\"writeable\":true}]}";
// clang-format on
StaticJsonDocument<500> doc;
JsonDocument doc;
deserializeJson(doc, json);
root = doc.as<JsonObject>();
Serial.println(COLOR_BRIGHT_MAGENTA);
@@ -342,8 +342,8 @@ void WebCustomEntityService::publish_single(const CustomEntityItem & entity) {
} else {
snprintf(topic, sizeof(topic), "%s/%s", "custom_data", entity.name.c_str());
}
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc;
JsonObject output = doc.to<JsonObject>();
JsonDocument doc;
JsonObject output = doc.to<JsonObject>();
render_value(output, entity, true);
Mqtt::queue_publish(topic, output["value"].as<std::string>());
}
@@ -366,15 +366,15 @@ void WebCustomEntityService::publish(const bool force) {
}
}
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE);
JsonObject output = doc.to<JsonObject>();
bool ha_created = ha_registered_;
JsonDocument doc;
JsonObject output = doc.to<JsonObject>();
bool ha_created = ha_registered_;
for (const CustomEntityItem & entityItem : *customEntityItems) {
render_value(output, entityItem);
// create HA config
if (Mqtt::ha_enabled() && !ha_registered_) {
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
char stat_t[50];
JsonDocument config;
char stat_t[50];
snprintf(stat_t, sizeof(stat_t), "%s/custom_data", Mqtt::base().c_str());
config["stat_t"] = stat_t;
@@ -426,7 +426,7 @@ void WebCustomEntityService::publish(const bool force) {
config["pl_off"] = Helpers::render_boolean(result, false);
}
}
Mqtt::add_ha_sections_to_doc("custom", stat_t, config.as<JsonObject>(), true, val_cond);
Mqtt::add_ha_sections_to_doc("custom", stat_t, config, true, val_cond);
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
}
@@ -445,9 +445,9 @@ uint8_t WebCustomEntityService::count_entities() {
return 0;
}
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE);
JsonObject output = doc.to<JsonObject>();
uint8_t count = 0;
JsonDocument doc;
JsonObject output = doc.to<JsonObject>();
uint8_t count = 0;
for (const CustomEntityItem & entity : *customEntityItems) {
render_value(output, entity);
count += (output.containsKey(entity.name) || entity.writeable) ? 1 : 0;
@@ -469,10 +469,10 @@ void WebCustomEntityService::generate_value_web(JsonObject & output) {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
output["label"] = (std::string) "Custom Entities";
JsonArray data = output.createNestedArray("data");
JsonArray data = output["data"].to<JsonArray>();
uint8_t index = 0;
for (const CustomEntityItem & entity : *customEntityItems) {
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
JsonObject obj = data.add<JsonObject>(); // create the object, we know there is a value
obj["id"] = "00" + entity.name;
obj["u"] = entity.uom;
if (entity.writeable) {
@@ -487,7 +487,7 @@ void WebCustomEntityService::generate_value_web(JsonObject & output) {
case DeviceValueType::BOOL: {
char s[12];
obj["v"] = Helpers::render_boolean(s, (uint8_t)entity.value, true);
JsonArray l = obj.createNestedArray("l");
JsonArray l = obj["l"].to<JsonArray>();
l.add(Helpers::render_boolean(s, false, true));
l.add(Helpers::render_boolean(s, true, true));
break;

View File

@@ -51,25 +51,24 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f
_masked_entities_handler.setMethod(HTTP_POST);
_masked_entities_handler.setMaxContentLength(2048);
_masked_entities_handler.setMaxJsonBufferSize(2048);
server->addHandler(&_masked_entities_handler);
}
// this creates the customization file, saving it to the FS
void WebCustomization::read(WebCustomization & customizations, JsonObject & root) {
// Temperature Sensor customization
JsonArray sensorsJson = root.createNestedArray("ts");
JsonArray sensorsJson = root["ts"].to<JsonArray>();
for (const SensorCustomization & sensor : customizations.sensorCustomizations) {
JsonObject sensorJson = sensorsJson.createNestedObject();
JsonObject sensorJson = sensorsJson.add<JsonObject>();
sensorJson["id"] = sensor.id; // ID of chip
sensorJson["name"] = sensor.name; // n
sensorJson["offset"] = sensor.offset; // o
}
// Analog Sensor customization
JsonArray analogJson = root.createNestedArray("as");
JsonArray analogJson = root["as"].to<JsonArray>();
for (const AnalogCustomization & sensor : customizations.analogCustomizations) {
JsonObject sensorJson = analogJson.createNestedObject();
JsonObject sensorJson = analogJson.add<JsonObject>();
sensorJson["gpio"] = sensor.gpio; // g
sensorJson["name"] = sensor.name; // n
sensorJson["offset"] = sensor.offset; // o
@@ -79,14 +78,14 @@ void WebCustomization::read(WebCustomization & customizations, JsonObject & root
}
// Masked entities customization
JsonArray masked_entitiesJson = root.createNestedArray("masked_entities");
JsonArray masked_entitiesJson = root["masked_entities"].to<JsonArray>();
for (const EntityCustomization & entityCustomization : customizations.entityCustomizations) {
JsonObject entityJson = masked_entitiesJson.createNestedObject();
JsonObject entityJson = masked_entitiesJson.add<JsonObject>();
entityJson["product_id"] = entityCustomization.product_id;
entityJson["device_id"] = entityCustomization.device_id;
// entries are in the form <XX><shortname>[|optional customname] e.g "08heatingactive|heating is on"
JsonArray masked_entityJson = entityJson.createNestedArray("entity_ids");
JsonArray masked_entityJson = entityJson["entity_ids"].to<JsonArray>();
for (std::string entity_id : entityCustomization.entity_ids) {
masked_entityJson.add(entity_id);
}
@@ -98,9 +97,9 @@ void WebCustomization::read(WebCustomization & customizations, JsonObject & root
StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization & customizations) {
#ifdef EMSESP_STANDALONE
// invoke some fake data for testing
const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom "
"name for heating active (HS1)\",\"08tapwateractive\"]}]}";
StaticJsonDocument<500> doc;
const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom "
"name for heating active (HS1)\",\"08tapwateractive\"]}]}";
JsonDocument doc;
deserializeJson(doc, json);
root = doc.as<JsonObject>();
Serial.println(COLOR_BRIGHT_MAGENTA);
@@ -179,15 +178,15 @@ void WebCustomizationService::reset_customization(AsyncWebServerRequest * reques
// send back a list of devices used in the customization web page
void WebCustomizationService::devices(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_XLARGE);
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
// list is already sorted by device type
// controller is ignored since it doesn't have any associated entities
JsonArray devices = root.createNestedArray("devices");
JsonArray devices = root["devices"].to<JsonArray>();
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->has_entities()) {
JsonObject obj = devices.createNestedObject();
JsonObject obj = devices.add<JsonObject>();
obj["i"] = emsdevice->unique_id(); // its unique id
obj["s"] = std::string(emsdevice->device_type_2_device_name_translated()) + " (" + emsdevice->name() + ")"; // shortname, is device type translated
obj["tn"] = emsdevice->device_type_name(); // non-translated, lower-case
@@ -205,14 +204,14 @@ void WebCustomizationService::device_entities(AsyncWebServerRequest * request) {
if (request->hasParam(F_(id))) {
id = Helpers::atoint(request->getParam(F_(id))->value().c_str()); // get id from url
size_t buffer = EMSESP_JSON_SIZE_XXXXLARGE;
auto * response = new MsgpackAsyncJsonResponse(true, buffer);
auto * response = new MsgpackAsyncJsonResponse(true);
// while (!response) {
// delete response;
// buffer -= 1024;
// response = new MsgpackAsyncJsonResponse(true, buffer);
// }
while (!response) {
delete response;
buffer -= 1024;
response = new MsgpackAsyncJsonResponse(true, buffer);
}
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->unique_id() == id) {
#ifndef EMSESP_STANDALONE

View File

@@ -71,15 +71,15 @@ void WebDataService::scan_devices(AsyncWebServerRequest * request) {
// this is used in the dashboard and contains all ems device information
// /coreData endpoint
void WebDataService::core_data(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE);
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
// list is already sorted by device type
JsonArray devices = root.createNestedArray("devices");
JsonArray devices = root["devices"].to<JsonArray>();
for (const auto & emsdevice : EMSESP::emsdevices) {
// ignore controller
if (emsdevice && (emsdevice->device_type() != EMSdevice::DeviceType::CONTROLLER || emsdevice->count_entities() > 0)) {
JsonObject obj = devices.createNestedObject();
JsonObject obj = devices.add<JsonObject>();
obj["id"] = emsdevice->unique_id(); // a unique id
obj["tn"] = emsdevice->device_type_2_device_name_translated(); // translated device type name
obj["t"] = emsdevice->device_type(); // device type number
@@ -95,7 +95,7 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
// add any custom entities
uint8_t customEntities = EMSESP::webCustomEntityService.count_entities();
if (customEntities) {
JsonObject obj = devices.createNestedObject();
JsonObject obj = devices.add<JsonObject>();
obj["id"] = 99; // the last unique id
obj["tn"] = Helpers::translated_word(FL_(custom_device)); // translated device type name
obj["t"] = EMSdevice::DeviceType::CUSTOM; // device type number
@@ -116,14 +116,14 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
// sensor data - sends back to web
// /sensorData endpoint
void WebDataService::sensor_data(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_XXLARGE);
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
// temperature sensors
JsonArray sensors = root.createNestedArray("ts");
JsonArray sensors = root["ts"].to<JsonArray>();
if (EMSESP::temperaturesensor_.have_sensors()) {
for (const auto & sensor : EMSESP::temperaturesensor_.sensors()) {
JsonObject obj = sensors.createNestedObject();
JsonObject obj = sensors.add<JsonObject>();
obj["id"] = sensor.id(); // id as string
obj["n"] = sensor.name(); // name
if (EMSESP::system_.fahrenheit()) {
@@ -143,11 +143,11 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
}
// analog sensors
JsonArray analogs = root.createNestedArray("as");
JsonArray analogs = root["as"].to<JsonArray>();
if (EMSESP::analog_enabled() && EMSESP::analogsensor_.have_sensors()) {
uint8_t count = 0;
for (const auto & sensor : EMSESP::analogsensor_.sensors()) {
JsonObject obj = analogs.createNestedObject();
JsonObject obj = analogs.add<JsonObject>();
obj["id"] = ++count; // needed for sorting table
obj["g"] = sensor.gpio();
obj["n"] = sensor.name();
@@ -178,15 +178,14 @@ void WebDataService::device_data(AsyncWebServerRequest * request) {
if (request->hasParam(F_(id))) {
id = Helpers::atoint(request->getParam(F_(id))->value().c_str()); // get id from url
size_t buffer = EMSESP_JSON_SIZE_XXXXLARGE;
auto * response = new MsgpackAsyncJsonResponse(false, buffer);
auto * response = new MsgpackAsyncJsonResponse(false);
// check size
while (!response) {
delete response;
buffer -= 1024;
response = new MsgpackAsyncJsonResponse(false, buffer);
}
// while (!response) {
// delete response;
// buffer -= 1024;
// response = new MsgpackAsyncJsonResponse(false, buffer);
// }
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->unique_id() == id) {
@@ -249,7 +248,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
cmd = Command::parse_command_string(cmd, id); // extract hc or wwc
// create JSON for output
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_SMALL);
auto * response = new AsyncJsonResponse(false);
JsonObject output = response->getRoot();
// the data could be in any format, but we need string
@@ -289,7 +288,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
// parse the command as it could have a hc or wwc prefixed, e.g. hc2/seltemp
int8_t id = -1;
cmd = Command::parse_command_string(cmd, id);
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_SMALL);
auto * response = new AsyncJsonResponse(false);
JsonObject output = response->getRoot();
uint8_t return_code = CommandRet::NOT_FOUND;
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;

View File

@@ -24,7 +24,7 @@ namespace emsesp {
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
: events_(EVENT_SOURCE_LOG_PATH)
, setValues_(LOG_SETTINGS_PATH, std::bind(&WebLogService::setValues, this, _1, _2), 256) {
, setValues_(LOG_SETTINGS_PATH, std::bind(&WebLogService::setValues, this, _1, _2)) {
events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_ADMIN));
server->on(LOG_SETTINGS_PATH, HTTP_GET, std::bind(&WebLogService::getValues, this, _1)); // get settings
@@ -183,10 +183,8 @@ char * WebLogService::messagetime(char * out, const uint64_t t, const size_t buf
// send to web eventsource
void WebLogService::transmit(const QueuedLogMessage & message) {
DynamicJsonDocument jsonDocument(EMSESP_JSON_SIZE_LARGE);
if (jsonDocument.capacity() == 0) {
return;
}
JsonDocument jsonDocument;
JsonObject logEvent = jsonDocument.to<JsonObject>();
char time_string[25];
@@ -234,7 +232,7 @@ void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant & jso
// return the current value settings after a GET
void WebLogService::getValues(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_SMALL);
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
root["level"] = log_level();
root["max_messages"] = maximum_log_messages();

View File

@@ -37,10 +37,10 @@ void WebSchedulerService::begin() {
// this creates the scheduler file, saving it to the FS
// and also calls when the Scheduler web page is refreshed
void WebScheduler::read(WebScheduler & webScheduler, JsonObject & root) {
JsonArray schedule = root.createNestedArray("schedule");
JsonArray schedule = root["schedule"].to<JsonArray>();
uint8_t counter = 0;
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
JsonObject si = schedule.createNestedObject();
JsonObject si = schedule.add<JsonObject>();
si["id"] = counter++; // id is only used to render the table and must be unique
si["active"] = scheduleItem.active;
si["flags"] = scheduleItem.flags;
@@ -59,7 +59,7 @@ StateUpdateResult WebScheduler::update(JsonObject & root, WebScheduler & webSche
const char * json =
"{\"schedule\": [{\"id\":1,\"active\":true,\"flags\":31,\"time\": \"07:30\",\"cmd\": \"hc1mode\",\"value\": \"day\",\"name\": \"turn on "
"central heating\"}]}";
StaticJsonDocument<500> doc;
JsonDocument doc;
deserializeJson(doc, json);
root = doc.as<JsonObject>();
Serial.println(COLOR_BRIGHT_MAGENTA);
@@ -237,8 +237,8 @@ void WebSchedulerService::publish(const bool force) {
}
}
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE);
bool ha_created = ha_registered_;
JsonDocument doc;
bool ha_created = ha_registered_;
for (const ScheduleItem & scheduleItem : *scheduleItems) {
if (!scheduleItem.name.empty() && !doc.containsKey(scheduleItem.name)) {
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
@@ -252,8 +252,8 @@ void WebSchedulerService::publish(const bool force) {
// create HA config
if (Mqtt::ha_enabled() && !ha_registered_) {
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
char stat_t[50];
JsonDocument config;
char stat_t[50];
snprintf(stat_t, sizeof(stat_t), "%s/scheduler_data", Mqtt::base().c_str());
config["stat_t"] = stat_t;
@@ -287,7 +287,7 @@ void WebSchedulerService::publish(const bool force) {
config["pl_off"] = Helpers::render_boolean(result, false);
}
Mqtt::add_ha_sections_to_doc("scheduler", stat_t, config.as<JsonObject>(), true, val_cond);
Mqtt::add_ha_sections_to_doc("scheduler", stat_t, config, true, val_cond);
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
}
@@ -314,14 +314,14 @@ bool WebSchedulerService::has_commands() {
// execute scheduled command
bool WebSchedulerService::command(const char * cmd, const char * data) {
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc_input;
JsonObject input = doc_input.to<JsonObject>();
JsonDocument doc_input;
JsonObject input = doc_input.to<JsonObject>();
if (strlen(data)) { // empty data queries a value
input["data"] = data;
}
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> doc_output; // only for commands without output
JsonObject output = doc_output.to<JsonObject>();
JsonDocument doc_output; // only for commands without output
JsonObject output = doc_output.to<JsonObject>();
// prefix "api/" to command string
char command_str[100];

View File

@@ -364,7 +364,7 @@ void WebSettingsService::board_profile(AsyncWebServerRequest * request) {
if (request->hasParam("boardProfile")) {
std::string board_profile = request->getParam("boardProfile")->value().c_str();
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_MEDIUM);
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
std::vector<int8_t> data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode

View File

@@ -115,7 +115,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
}
void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_LARGE);
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
root["status"] = EMSESP::bus_status(); // 0, 1 or 2
@@ -125,29 +125,29 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
root["num_sensors"] = EMSESP::temperaturesensor_.no_sensors();
root["num_analogs"] = EMSESP::analogsensor_.no_sensors();
JsonArray statsJson = root.createNestedArray("stats");
JsonArray statsJson = root["stats"].to<JsonArray>();
JsonObject statJson;
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 0;
statJson["s"] = EMSESP::rxservice_.telegram_count();
statJson["f"] = EMSESP::rxservice_.telegram_error_count();
statJson["q"] = EMSESP::rxservice_.quality();
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 1;
statJson["s"] = EMSESP::txservice_.telegram_read_count();
statJson["f"] = EMSESP::txservice_.telegram_read_fail_count();
statJson["q"] = EMSESP::txservice_.read_quality();
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 2;
statJson["s"] = EMSESP::txservice_.telegram_write_count();
statJson["f"] = EMSESP::txservice_.telegram_write_fail_count();
statJson["q"] = EMSESP::txservice_.write_quality();
if (EMSESP::sensor_enabled()) {
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 3;
statJson["s"] = EMSESP::temperaturesensor_.reads() - EMSESP::temperaturesensor_.fails();
statJson["f"] = EMSESP::temperaturesensor_.fails();
@@ -155,21 +155,21 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
EMSESP::temperaturesensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::temperaturesensor_.fails()) / EMSESP::temperaturesensor_.reads());
}
if (EMSESP::analog_enabled()) {
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 4;
statJson["s"] = EMSESP::analogsensor_.reads() - EMSESP::analogsensor_.fails();
statJson["f"] = EMSESP::analogsensor_.fails();
statJson["q"] = EMSESP::analogsensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::analogsensor_.fails()) / EMSESP::analogsensor_.reads());
}
if (Mqtt::enabled()) {
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 5;
statJson["s"] = Mqtt::publish_count() - Mqtt::publish_fails();
statJson["f"] = Mqtt::publish_fails();
statJson["q"] = Mqtt::publish_count() == 0 ? 100 : 100 - (uint8_t)((100 * Mqtt::publish_fails()) / Mqtt::publish_count());
}
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 6;
statJson["s"] = WebAPIService::api_count(); // + WebAPIService::api_fails();
statJson["f"] = WebAPIService::api_fails();
@@ -179,7 +179,7 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
#ifndef EMSESP_STANDALONE
if (EMSESP::system_.syslog_enabled()) {
statJson = statsJson.createNestedObject();
statJson = statsJson.add<JsonObject>();
statJson["id"] = 7;
statJson["s"] = EMSESP::system_.syslog_count();
statJson["f"] = EMSESP::system_.syslog_fails();