From f7fc459095a37842b5ac27e6c5c3a13d448a4aac Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 6 Jun 2019 06:43:50 +0200 Subject: [PATCH] MQTT can now be disabled via MQTT_ENABLE --- include/my_mqtt.h | 8 +++++--- src/mqtt.cpp | 5 +++++ src/pitrix.cpp | 16 ++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/my_mqtt.h b/include/my_mqtt.h index 24bd217..3748b6e 100644 --- a/include/my_mqtt.h +++ b/include/my_mqtt.h @@ -1,5 +1,7 @@ -#ifndef my_mqtt_H -#define my_mqtt_H +#pragma once +#include "config.h" + +#ifdef MQTT_ENABLE #include #include @@ -27,4 +29,4 @@ void mqtt_log_send(const char* message); extern String mqtt_log_str; -#endif // mqtt_H +#endif // MQTT_ENABLE diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 61572b6..4a650c7 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -1,5 +1,8 @@ #include "my_mqtt.h" #include "config.h" + +#ifdef MQTT_ENABLE + #include #include #include "EffectEntry.h" @@ -118,3 +121,5 @@ void mqtt_log_send(const char* message) { mqtt_client.publish(MQTT_TOPIC_LOG, message); } } + +#endif // MQTT_ENABLE diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 95a2bfc..12430c8 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -29,7 +29,9 @@ void setup() { ota_setup(); fastled_setup(); ntpClient.begin(); - mqtt_setup(); + #ifdef MQTT_ENABLE + mqtt_setup(); + #endif LOGln("Core * Setup complete"); current_effect->start(); @@ -53,7 +55,9 @@ void loop() { } ntpClient.update(); - mqtt_loop(); + #ifdef MQTT_ENABLE + mqtt_loop(); + #endif EVERY_N_MILLISECONDS(100) { baseHue++; @@ -70,12 +74,12 @@ void loop() { FastLED.show(); } + #if defined(MQTT_ENABLE) && defined(MQTT_REPORT_METRICS) EVERY_N_SECONDS(15) { - if (REPORT_METRICS) { - mqtt_publish("free_heap", ESP.getFreeHeap()); - mqtt_publish("uptime", millis()/1000); - } + mqtt_publish("free_heap", ESP.getFreeHeap()); + mqtt_publish("uptime", millis()/1000); } + #endif // MQTT_REPORT_METRICS if (MONITOR_LOOP_TIMES && millis()-loop_started_at>=MONITOR_LOOP_TIME_THRESHOLD) {