Skip to content

Commit

Permalink
[Web commands] Show LogEntry results + speed up parsing web commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Dec 24, 2023
1 parent 94ed93e commit 6e25c01
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/src/Commands/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const __FlashStringHelper * Command_Debug(struct EventStruct *event, const char
return return_see_serial(event);
}

const __FlashStringHelper * Command_logentry(struct EventStruct *event, const char *Line)
String Command_logentry(struct EventStruct *event, const char *Line)
{
uint8_t level = LOG_LEVEL_INFO;
// An extra optional parameter to set log level.
Expand All @@ -164,8 +164,9 @@ const __FlashStringHelper * Command_logentry(struct EventStruct *event, const ch
LOG_LEVEL_INFO
#endif
) { level = event->Par2; }
addLog(level, tolerantParseStringKeepCase(Line, 2));
return return_command_success_flashstr();
String res = tolerantParseStringKeepCase(Line, 2);
addLog(level, res);
return res;
}

#ifndef BUILD_NO_DIAGNOSTIC_COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion src/src/Commands/Diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const __FlashStringHelper * Command_MemInfo_detail(struct EventStruct *event, co
const __FlashStringHelper * Command_Background(struct EventStruct *event, const char* Line);
#endif
const __FlashStringHelper * Command_Debug(struct EventStruct *event, const char* Line);
const __FlashStringHelper * Command_logentry(struct EventStruct *event, const char* Line);
String Command_logentry(struct EventStruct *event, const char* Line);
#ifndef BUILD_NO_DIAGNOSTIC_COMMANDS
const __FlashStringHelper * Command_JSONPortStatus(struct EventStruct *event, const char* Line);
//void createLogPortStatus(std::map< uint32_t, portStatusStruct >::iterator it);
Expand Down
57 changes: 33 additions & 24 deletions src/src/Helpers/WebServer_commandHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../../ESPEasy-Globals.h"
#include "../Commands/ExecuteCommand.h"
#include "../Commands/InternalCommands_decoder.h"
#include "../Globals/EventQueue.h"
#include "../Helpers/StringConverter.h"
#include "../Helpers/StringParser.h"
Expand Down Expand Up @@ -29,42 +30,50 @@ HandledWebCommand_result handle_command_from_web(EventValueSource::Enum source,
// in case of event, store to buffer and return...
const String command = parseString(webrequest, 1);

if ((equals(command, F("event"))) || (equals(command, F("asyncevent"))))
{
eventQueue.addMove(parseStringToEndKeepCase(webrequest, 2));
handledCmd = true;
sendOK = true;
} else if (equals(command, F("taskrun")) ||
equals(command, F("taskrunat")) ||
equals(command, F("scheduletaskrun")) ||
equals(command, F("taskvalueset")) ||
equals(command, F("taskvaluesetandrun")) ||
equals(command, F("taskvaluetoggle")) ||
equals(command, F("let")) ||
equals(command, F("logportstatus")) ||
equals(command, F("jsonportstatus")) ||
equals(command, F("rules"))) {
printToWeb = true;
handledCmd = ExecuteCommand_internal(source, webrequest.c_str());
sendOK = true;
const ESPEasy_cmd_e command_e = match_ESPEasy_internal_command(command);

// handledCmd = true;
} else {
if (command_e == ESPEasy_cmd_e::NotMatched) {
// For sure not an internal command, try plugin or remote config
printToWeb = true;
handledCmd = ExecuteCommand_all_config(source, webrequest.c_str());
handledCmd = ExecuteCommand_plugin_config(source, webrequest.c_str());
sendOK = false;
} else {
if ((command_e == ESPEasy_cmd_e::event) || (command_e == ESPEasy_cmd_e::asyncevent))
{
eventQueue.addMove(parseStringToEndKeepCase(webrequest, 2));
handledCmd = true;
sendOK = true;
} else if (command_e == ESPEasy_cmd_e::taskrun ||
command_e == ESPEasy_cmd_e::taskrunat ||
command_e == ESPEasy_cmd_e::scheduletaskrun ||
command_e == ESPEasy_cmd_e::taskvalueset ||
command_e == ESPEasy_cmd_e::taskvaluesetandrun ||
command_e == ESPEasy_cmd_e::taskvaluetoggle ||
command_e == ESPEasy_cmd_e::let ||
command_e == ESPEasy_cmd_e::logportstatus ||
command_e == ESPEasy_cmd_e::logentry ||
command_e == ESPEasy_cmd_e::jsonportstatus ||
command_e == ESPEasy_cmd_e::rules) {
sendOK = true;

// handledCmd = true;
} else {
sendOK = false;
}
printToWeb = true;
handledCmd = ExecuteCommand_internal(source, webrequest.c_str());
}

if (handledCmd) {
if (sendOK) {
String reply = printWebString.isEmpty() ? F("OK") : printWebString;
removeChar(reply, '\n'); // Don't use newline in JSON.
if (printToWebJSON) {
// Format "OK" to JSON format
// Format return string of command to JSON format
printWebString = strformat(
F("{\"return\": \"%s\",\"command\": \"%s\"}"),
reply.c_str(),
webrequest.c_str());
to_json_value(reply).c_str(),
to_json_value(webrequest).c_str());
} else {
printWebString = reply;
}
Expand Down

0 comments on commit 6e25c01

Please sign in to comment.