changed LOG_TOPIC to "log/" + HOSTNAME
This commit is contained in:
parent
df5a7b6c4a
commit
b4705d5662
@ -12,12 +12,15 @@ MySerialClass MySerial(mqtt);
|
|||||||
|
|
||||||
unsigned long mqttFailureMillis = 0;
|
unsigned long mqttFailureMillis = 0;
|
||||||
|
|
||||||
|
// ReSharper disable once CppUseAuto
|
||||||
|
const char* LOG_TOPIC = (String("log/") + HOSTNAME).c_str();
|
||||||
|
|
||||||
void mqttLoop() {
|
void mqttLoop() {
|
||||||
if (!mqtt.loop() && isWifiConnected() && (mqttFailureMillis == 0 || millis() - mqttFailureMillis >= 3000)) {
|
if (!mqtt.loop() && isWifiConnected() && (mqttFailureMillis == 0 || millis() - mqttFailureMillis >= 3000)) {
|
||||||
mqtt.setServer("10.0.0.50", 1883);
|
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();
|
yield();
|
||||||
mqttPublish(HOSTNAME, "connected\n");
|
mqttPublish(LOG_TOPIC, "connected\n");
|
||||||
MySerial.printf("MQTT connected as \"%s\"\n", HOSTNAME);
|
MySerial.printf("MQTT connected as \"%s\"\n", HOSTNAME);
|
||||||
mqttFailureMillis = 0;
|
mqttFailureMillis = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#include "PubSubClient.h"
|
#include "PubSubClient.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
|
||||||
|
extern const char* LOG_TOPIC;
|
||||||
|
|
||||||
void mqttLoop();
|
void mqttLoop();
|
||||||
|
|
||||||
void mqttPublish(const char *topic, int32_t value, const char *unit);
|
void mqttPublish(const char *topic, int32_t value, const char *unit);
|
||||||
@ -47,10 +49,10 @@ public:
|
|||||||
due = true;
|
due = true;
|
||||||
if (mqtt.connected()) {
|
if (mqtt.connected()) {
|
||||||
if (overflow > 0) {
|
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;
|
overflow = 0;
|
||||||
}
|
}
|
||||||
mqtt.publish(HOSTNAME, reinterpret_cast<const char *>(buffer));
|
mqtt.publish(LOG_TOPIC, reinterpret_cast<const char *>(buffer));
|
||||||
bufferWrite = buffer;
|
bufferWrite = buffer;
|
||||||
*bufferWrite = 0;
|
*bufferWrite = 0;
|
||||||
due = false;
|
due = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user