mirror of https://github.com/arendst/Tasmota.git
Final fix unknown/error
This commit is contained in:
parent
8d7a27df76
commit
03b57179ac
|
@ -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)
|
// 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) {
|
void ResponseJsonStart(void) {
|
||||||
// Insert a JSON start bracket {
|
// Insert a JSON start bracket {
|
||||||
TasmotaGlobal.mqtt_data.setCharAt(0,'{');
|
TasmotaGlobal.mqtt_data.setCharAt(0,'{');
|
||||||
|
|
|
@ -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];
|
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,
|
type,
|
||||||
(index != 1) ? itoa(index, number, 10) : "",
|
(index != 1) ? itoa(index, number, 10) : "",
|
||||||
(data_len) ? " " : "",
|
(data_len) ? " " : "",
|
||||||
|
@ -468,15 +469,19 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) {
|
||||||
#endif // USE_SCRIPT_SUB_COMMAND
|
#endif // USE_SCRIPT_SUB_COMMAND
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ResponseStartsWith("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"")) {
|
if (!strcmp(ResponseData(), "_1")) {
|
||||||
// No calls to Response_P performed if got here so it's either Command Error or Unknown
|
// 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
|
TasmotaGlobal.no_mqtt_response = false; // Make sure to report commands starting with underline
|
||||||
|
Response_P(PSTR("{\"" D_JSON_COMMAND "\":"));
|
||||||
if (!strlen(type)) {
|
if (!strlen(type)) {
|
||||||
TasmotaGlobal.blinks = 201;
|
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));
|
snprintf_P(stemp1, sizeof(stemp1), PSTR(D_JSON_COMMAND));
|
||||||
type = (char*)stemp1;
|
type = (char*)stemp1;
|
||||||
|
} else {
|
||||||
|
ResponseAppend_P(PSTR("\"" D_JSON_ERROR "\""));
|
||||||
}
|
}
|
||||||
|
ResponseAppend_P(PSTR(",\"Input\":\"%s\"}"), command_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ResponseLength()) {
|
if (ResponseLength()) {
|
||||||
|
|
Loading…
Reference in New Issue