diff --git a/tasmota/support.ino b/tasmota/support.ino index 70d3f58d0..7eb6f5ea1 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -375,6 +375,22 @@ char* RemoveSpace(char* p) return p; } +char* RemoveControlCharacter(char* p) +{ + char* write = p; + char* read = p; + char ch = '.'; + + while (ch != '\0') { + ch = *read++; + if (!iscntrl(ch)) { + *write++ = ch; + } + } + if (write != p) { *write-- = '\0'; } + return p; +} + char* ReplaceCommaWithDot(char* p) { char* write = (char*)p; diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index cc0ed8e62..c5bd6a404 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -242,12 +242,15 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len char topic[TOPSZ]; strlcpy(topic, mqtt_topic, sizeof(topic)); mqtt_data[data_len] = 0; - char data[data_len +1]; - memcpy(data, mqtt_data, sizeof(data)); - AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_RECEIVED_TOPIC " \"%s\", " D_DATA_SIZE " %d, " D_DATA " \"%s\""), topic, data_len, data); + char data[data_len +1]; + + memcpy(data, mqtt_data, sizeof(data)); + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, RemoveControlCharacter(data)); // if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(data); } + memcpy(data, mqtt_data, sizeof(data)); + // MQTT pre-processing XdrvMailbox.index = strlen(topic); XdrvMailbox.data_len = data_len;