changed LOG_TOPIC to "log/" + HOSTNAME

This commit is contained in:
Patrick Haßel 2025-02-14 09:05:35 +01:00
parent df5a7b6c4a
commit b4705d5662
2 changed files with 9 additions and 4 deletions

View File

@ -12,12 +12,15 @@ MySerialClass MySerial(mqtt);
unsigned long mqttFailureMillis = 0;
// ReSharper disable once CppUseAuto
const char* LOG_TOPIC = (String("log/") + HOSTNAME).c_str();
void mqttLoop() {
if (!mqtt.loop() && isWifiConnected() && (mqttFailureMillis == 0 || millis() - mqttFailureMillis >= 3000)) {
mqtt.setServer("10.0.0.50", 1883);
if (mqtt.connect(HOSTNAME, HOSTNAME, 0, false, "disconnected\n")) {
if (mqtt.connect(HOSTNAME, LOG_TOPIC, 0, false, "disconnected\n")) {
yield();
mqttPublish(HOSTNAME, "connected\n");
mqttPublish(LOG_TOPIC, "connected\n");
MySerial.printf("MQTT connected as \"%s\"\n", HOSTNAME);
mqttFailureMillis = 0;
} else {

View File

@ -5,6 +5,8 @@
#include "PubSubClient.h"
#include "wifi.h"
extern const char* LOG_TOPIC;
void mqttLoop();
void mqttPublish(const char *topic, int32_t value, const char *unit);
@ -47,10 +49,10 @@ public:
due = true;
if (mqtt.connected()) {
if (overflow > 0) {
mqtt.publish(HOSTNAME, "\n### LOG BUFFER OVERFLOW BY %d BYTES ###\n");
mqtt.publish(LOG_TOPIC, "\n### LOG BUFFER OVERFLOW BY %d BYTES ###\n");
overflow = 0;
}
mqtt.publish(HOSTNAME, reinterpret_cast<const char *>(buffer));
mqtt.publish(LOG_TOPIC, reinterpret_cast<const char *>(buffer));
bufferWrite = buffer;
*bufferWrite = 0;
due = false;