From 42461aaaf36952be9d910783ed935d9fb5e6268e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Jan 2020 17:38:32 +0100 Subject: [PATCH] Fix command Publish payload handling --- tasmota/xdrv_02_mqtt.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index 55b63c4de..4d574a9f1 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -389,7 +389,7 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic, bool retain } // update topic is "$aws/things//shadow/update" snprintf_P(romram, sizeof(romram), PSTR("$aws/things/%s/shadow/update"), topic2); - + // copy buffer char *mqtt_save = (char*) malloc(strlen(mqtt_data)+1); if (!mqtt_save) { return; } // abort @@ -852,13 +852,13 @@ void CmndPrefix(void) void CmndPublish(void) { if (XdrvMailbox.data_len > 0) { - char *mqtt_part = strtok(XdrvMailbox.data, " "); + char *payload_part; + char *mqtt_part = strtok_r(XdrvMailbox.data, " ", &payload_part); if (mqtt_part) { char stemp1[TOPSZ]; strlcpy(stemp1, mqtt_part, sizeof(stemp1)); - mqtt_part = strtok(nullptr, " "); - if (mqtt_part) { - strlcpy(mqtt_data, mqtt_part, sizeof(mqtt_data)); + if ((payload_part != nullptr) && strlen(payload_part)) { + strlcpy(mqtt_data, payload_part, sizeof(mqtt_data)); } else { mqtt_data[0] = '\0'; }