diff --git a/CHANGELOG.md b/CHANGELOG.md index c8fe4b61f..6c7b651d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. - Correct Energy period display shortly after midnight by gominoa (#9536) - Rule handling of Var or Mem using text regression from v8.5.0.1 (#9540) - TuyaMcu energy display regression from v8.5.0.1 (#9547) +- MQTT data corruption on ``MQTTLog 4`` (#9571) ## [9.0.0.1] - 20201010 ### Added diff --git a/tasmota/support.ino b/tasmota/support.ino index 9e85168e1..462aec9e2 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -386,7 +386,7 @@ char* RemoveControlCharacter(char* p) { *write++ = ch; } } - if (write != p) { *write-- = '\0'; } + *write++ = '\0'; return p; } diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index bee6eb941..ee39145c0 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -220,6 +220,12 @@ bool MqttPublishLib(const char* topic, bool retained) return result; } +void MqttDumpData(char* topic, char* data, uint32_t data_len) { + char dump_data[data_len +1]; + memcpy(dump_data, mqtt_data, sizeof(dump_data)); // Make another copy for removing optional control characters + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, RemoveControlCharacter(dump_data)); +} + void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len) { #ifdef USE_DEBUG_DRIVER @@ -242,14 +248,12 @@ 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_DATA_SIZE " %d, \"%s %s\""), data_len, topic, RemoveControlCharacter(data)); + +// AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_DATA_SIZE " %d, \"%s %s\""), data_len, topic, data); // if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(data); } - - memcpy(data, mqtt_data, sizeof(data)); + MqttDumpData(topic, data, data_len); // Use a function to save stack space used by dump_data // MQTT pre-processing XdrvMailbox.index = strlen(topic);