mqttclient.cpp: added base64 encoding

This commit is contained in:
cyberman54 2020-12-29 20:48:32 +01:00
parent 0209915877
commit e882ad625e

View File

@ -1,6 +1,7 @@
#ifdef HAS_MQTT #ifdef HAS_MQTT
#include "mqttclient.h" #include "mqttclient.h"
#include <base64.h>
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
@ -95,14 +96,15 @@ void mqtt_client_task(void *param) {
MQTT_KEEPALIVE * 1000 / portTICK_PERIOD_MS) != pdTRUE) MQTT_KEEPALIVE * 1000 / portTICK_PERIOD_MS) != pdTRUE)
continue; continue;
// prepare data to send // prepare mqtt topic
char buffer[PAYLOAD_BUFFER_SIZE + 3]; char topic[16];
snprintf(buffer, msg.MessageSize + 3, "%u/%s", msg.MessagePort, snprintf(topic, 16, "%s/%u", MQTT_OUTTOPIC, msg.MessagePort);
msg.Message);
// send data to mqtt server and delete sent item from queue // send base64 encoded message to mqtt server and delete it from queue
if (mqttClient.publish(MQTT_OUTTOPIC, buffer)) { if (mqttClient.publish(topic,
ESP_LOGI(TAG, "%d byte(s) sent to MQTT server", msg.MessageSize + 2); 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); xQueueReceive(MQTTSendQueue, &msg, (TickType_t)0);
} else } else
ESP_LOGD(TAG, "Couldn't sent message to MQTT server"); ESP_LOGD(TAG, "Couldn't sent message to MQTT server");