Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
shrink api-json before send, force log level for watch
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Jan 31, 2021
1 parent 1269c5a commit de5d691
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/WebAPIService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void WebAPIService::webAPIService(AsyncWebServerRequest * request) {
ok ? PSTR("OK") : PSTR("Invalid"));
EMSESP::logger().debug(debug.c_str());
if (json.size()) {
doc.shrinkToFit();
std::string buffer2;
serializeJson(doc, buffer2);
EMSESP::logger().debug("json (max 255 chars): %s", buffer2.c_str());
Expand All @@ -109,6 +110,7 @@ void WebAPIService::webAPIService(AsyncWebServerRequest * request) {

// if we have returned data in JSON format, send this to the WEB
if (json.size()) {
doc.shrinkToFit();
std::string buffer;
serializeJsonPretty(doc, buffer);
request->send(200, "text/plain", buffer.c_str());
Expand Down
10 changes: 6 additions & 4 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ void EMSESPShell::add_console_commands() {
watch_id = WATCH_ID_NONE;
} else {
watch_id = Helpers::hextoint(arguments[0].c_str());
if ((emsesp::EMSESP::watch() == EMSESP::WATCH_OFF) && watch_id) {
emsesp::EMSESP::watch(EMSESP::WATCH_ON); // on
} else if ((emsesp::EMSESP::watch() == EMSESP::WATCH_UNKNOWN) || !watch_id) {
if (watch_id && ((emsesp::EMSESP::watch() == EMSESP::WATCH_OFF) || (emsesp::EMSESP::watch() == EMSESP::WATCH_UNKNOWN))) {
emsesp::EMSESP::watch(EMSESP::WATCH_ON); // on
} else if (!watch_id) {
return;
}
}
Expand All @@ -334,8 +334,9 @@ void EMSESPShell::add_console_commands() {
}

// if logging is off, the watch won't show anything, show force it back to NOTICE
if (!shell.logger().enabled(Level::NOTICE)) {
if (shell.log_level() < Level::NOTICE) {
shell.log_level(Level::NOTICE);
shell.printfln(F("Force log level to notice"));
}

if (watch == EMSESP::WATCH_ON) {
Expand Down Expand Up @@ -403,6 +404,7 @@ void EMSESPShell::add_console_commands() {
}

if (ok && json.size()) {
doc.shrinkToFit();
serializeJsonPretty(doc, shell);
shell.println();
}
Expand Down

0 comments on commit de5d691

Please sign in to comment.