From ff13c563d88e264d91252467ebbd76c6340e0ae0 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 21 Apr 2021 09:52:05 +0200 Subject: [PATCH] Move MqttPublish log to heap --- tasmota/tasmota_template.h | 2 -- tasmota/xdrv_02_mqtt.ino | 48 +++++++------------------------------- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 4e2dddaad..5b600eee4 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -159,9 +159,7 @@ enum UserSelectablePins { GPIO_TFMINIPLUS_TX, GPIO_TFMINIPLUS_RX, // TFmini Plus ToF sensor GPIO_ZEROCROSS, #ifdef ESP32 -#if CONFIG_IDF_TARGET_ESP32 GPIO_HALLEFFECT, -#endif // CONFIG_IDF_TARGET_ESP32 GPIO_EPD_DATA, // Base connection EPD driver #endif GPIO_SENSOR_END }; diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index 6b0d55dfa..8e20b8de2 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -338,51 +338,19 @@ void MqttPublish(const char* topic, bool retained) { retained = false; // Some brokers don't support retained, they will disconnect if received } - char sretained[CMDSZ]; - sretained[0] = '\0'; - char slog_type[20]; - snprintf_P(slog_type, sizeof(slog_type), PSTR(D_LOG_RESULT)); - - if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT - if (MqttPublishLib(topic, retained)) { - snprintf_P(slog_type, sizeof(slog_type), PSTR(D_LOG_MQTT)); - if (retained) { - snprintf_P(sretained, sizeof(sretained), PSTR(" (" D_RETAINED ")")); - } - } + String log_data = F(D_LOG_RESULT); + if (Settings.flag.mqtt_enabled && MqttPublishLib(topic, retained)) { // SetOption3 - Enable MQTT + log_data = F(D_LOG_MQTT); + log_data += topic; + } else { + log_data += strrchr(topic,'/')+1; + retained = false; } - -/* - // Runs out of stack space with long messages - char log_data[MAX_LOGSZ]; - snprintf_P(log_data, sizeof(log_data), PSTR("%s%s = %s"), slog_type, (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1, TasmotaGlobal.mqtt_data); // SetOption3 - Enable MQTT - if (strlen(log_data) >= (sizeof(log_data) - strlen(sretained) -1)) { - log_data[sizeof(log_data) - strlen(sretained) -5] = '\0'; - snprintf_P(log_data, sizeof(log_data), PSTR("%s ..."), log_data); - } - snprintf_P(log_data, sizeof(log_data), PSTR("%s%s"), log_data, sretained); - AddLogData(LOG_LEVEL_INFO, log_data); -*/ - -/* - // Works - uint32_t sizeof_log_data = strlen(slog_type) + strlen(topic) + strlen(TasmotaGlobal.mqtt_data) + strlen(sretained) +4; - char *log_data = (char*)malloc(sizeof_log_data); - if (log_data) { - snprintf_P(log_data, sizeof_log_data, PSTR("%s%s = %s%s"), - slog_type, (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1, TasmotaGlobal.mqtt_data, sretained); // SetOption3 - Enable MQTT - AddLogData(LOG_LEVEL_INFO, log_data); - free(log_data); - } -*/ - String log_data = slog_type; - log_data += (Settings.flag.mqtt_enabled) ? topic : strrchr(topic,'/')+1; log_data += F(" = "); log_data += TasmotaGlobal.mqtt_data; - log_data += sretained; + if (retained) { log_data += F(" (" D_RETAINED ")"); } AddLogData(LOG_LEVEL_INFO, log_data.c_str()); - if (Settings.ledstate &0x04) { TasmotaGlobal.blinks++; }