From 03b57179ac2c2f9912c9f9293d716c3c901b787d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 21 Sep 2024 13:23:14 +0200 Subject: [PATCH] Final fix unknown/error --- tasmota/tasmota_support/support.ino | 8 -------- tasmota/tasmota_support/support_command.ino | 15 ++++++++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index 868accc3a958..d385ec0acb8f 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -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,'{'); diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 18b805e4b9ad..eb460e7fbdb1 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -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) ? " " : "", @@ -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()) {