From e882ad625e021f18ffa94cd861a03a22e0c3a27a Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 29 Dec 2020 20:48:32 +0100 Subject: [PATCH] mqttclient.cpp: added base64 encoding --- src/mqttclient.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index 6821a629..4e43244b 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -1,6 +1,7 @@ #ifdef HAS_MQTT #include "mqttclient.h" +#include static const char TAG[] = __FILE__; @@ -95,14 +96,15 @@ void mqtt_client_task(void *param) { MQTT_KEEPALIVE * 1000 / portTICK_PERIOD_MS) != pdTRUE) continue; - // prepare data to send - char buffer[PAYLOAD_BUFFER_SIZE + 3]; - snprintf(buffer, msg.MessageSize + 3, "%u/%s", msg.MessagePort, - msg.Message); + // prepare mqtt topic + char topic[16]; + snprintf(topic, 16, "%s/%u", MQTT_OUTTOPIC, msg.MessagePort); - // send data to mqtt server and delete sent item from queue - if (mqttClient.publish(MQTT_OUTTOPIC, buffer)) { - ESP_LOGI(TAG, "%d byte(s) sent to MQTT server", msg.MessageSize + 2); + // send base64 encoded message to mqtt server and delete it from queue + if (mqttClient.publish(topic, + base64::encode(msg.Message, msg.MessageSize))) { + ESP_LOGD(TAG, "%s/%s sent to MQTT server", topic, + base64::encode(msg.Message, msg.MessageSize)); xQueueReceive(MQTTSendQueue, &msg, (TickType_t)0); } else ESP_LOGD(TAG, "Couldn't sent message to MQTT server");