Skip to content

Commit

Permalink
Final fix unknown/error
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Sep 21, 2024
1 parent 8d7a27d commit 03b5717
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
8 changes: 0 additions & 8 deletions tasmota/tasmota_support/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1321,14 +1321,6 @@ void ResponseClear(void) {
// TasmotaGlobal.mqtt_data = (const char*) nullptr; // Doesn't work on ESP32 as strlen() (in MqttPublishPayload) will fail (for obvious reasons)
}

void ResponseReplace(const char* rold, const char* rnew) {
TasmotaGlobal.mqtt_data.replace(rold, rnew);
}

bool ResponseStartsWith(const char* start_with) {
return TasmotaGlobal.mqtt_data.startsWith(start_with);
}

void ResponseJsonStart(void) {
// Insert a JSON start bracket {
TasmotaGlobal.mqtt_data.setCharAt(0,'{');
Expand Down
15 changes: 10 additions & 5 deletions tasmota/tasmota_support/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,10 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) {
}
}

Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"")); // Prep error message for either Command Error or Command Unknown
Response_P(PSTR("_1")); // Signal error message for either Command Error or Command Unknown
char number[12];
ResponseAppend_P(PSTR(",\"Input\":\"%s%s%s%s\"}"),
char command_line[64];
snprintf_P(command_line, sizeof(command_line), PSTR("%s%s%s%s"),
type,
(index != 1) ? itoa(index, number, 10) : "",
(data_len) ? " " : "",
Expand Down Expand Up @@ -468,15 +469,19 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) {
#endif // USE_SCRIPT_SUB_COMMAND
}

if (ResponseStartsWith("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"")) {
// No calls to Response_P performed if got here so it's either Command Error or Unknown
if (!strcmp(ResponseData(), "_1")) {
// No calls to Response_P performed so it's either Command Error or Unknown
TasmotaGlobal.no_mqtt_response = false; // Make sure to report commands starting with underline
Response_P(PSTR("{\"" D_JSON_COMMAND "\":"));
if (!strlen(type)) {
TasmotaGlobal.blinks = 201;
ResponseReplace("\"" D_JSON_ERROR "\"", "\"" D_JSON_UNKNOWN "\""); // Need quotes to make sure only the first Error is replaceds by Unknown
ResponseAppend_P(PSTR("\"" D_JSON_UNKNOWN "\""));
snprintf_P(stemp1, sizeof(stemp1), PSTR(D_JSON_COMMAND));
type = (char*)stemp1;
} else {
ResponseAppend_P(PSTR("\"" D_JSON_ERROR "\""));
}
ResponseAppend_P(PSTR(",\"Input\":\"%s\"}"), command_line);
}

if (ResponseLength()) {
Expand Down

0 comments on commit 03b5717

Please sign in to comment.