From 33a8ad61989a887a59f9c46b0f06feb9c5509bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 10 Apr 2024 12:47:59 +0200 Subject: [PATCH] log to MQTT newline FIX --- lib/patrix/log.cpp | 12 ++++++++---- lib/patrix/mqtt.cpp | 4 ++-- lib/patrix/mqtt.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/patrix/log.cpp b/lib/patrix/log.cpp index 00e3804..dbaf43e 100644 --- a/lib/patrix/log.cpp +++ b/lib/patrix/log.cpp @@ -16,14 +16,18 @@ void log(const char *level, const char *module, const char *format, va_list vl) char datetime[26]; getDateTime(datetime, sizeof datetime); - char header[50]; - snprintf(header, sizeof header, " | %-5s | %-15s | ", level, module); + char header[45]; + snprintf(header, sizeof header, " | %-5s | %-10s | ", level, module); char message[500]; vsnprintf(message, sizeof message, format, vl); - const size_t len = Serial.print(datetime) + Serial.print(header) + Serial.print(message) + Serial.println(); - mqttPublishLog(len, datetime, header, message); + Serial.print(datetime); + Serial.print(header); + Serial.print(message); + Serial.println(); + + mqttPublishLog(datetime, header, message); } void debug(const char *module, const char *format, ...) { diff --git a/lib/patrix/mqtt.cpp b/lib/patrix/mqtt.cpp index 3ddf2f4..3909006 100644 --- a/lib/patrix/mqtt.cpp +++ b/lib/patrix/mqtt.cpp @@ -60,8 +60,8 @@ void mqttLoop() { mqtt.loop(); } -void mqttPublishLog(const size_t len, const char *datetime, const char *header, const char *message) { - if (mqtt.beginPublish(logTopic, len, false)) { +void mqttPublishLog(const char *datetime, const char *header, const char *message) { + if (mqtt.beginPublish(logTopic, strlen(datetime) + strlen(header) + strlen(message), false)) { mqtt.print(datetime); mqtt.print(header); mqtt.print(message); diff --git a/lib/patrix/mqtt.h b/lib/patrix/mqtt.h index 7ec6454..13972d9 100644 --- a/lib/patrix/mqtt.h +++ b/lib/patrix/mqtt.h @@ -9,7 +9,7 @@ void mqttLoop(); void mqttDisconnect(); -void mqttPublishLog(const size_t len, const char *datetime, const char *header, const char *message); +void mqttPublishLog(const char *datetime, const char *header, const char *message); bool mqttPublishData(const char *name, const JsonDocument &doc);