From ee81edbcd2f2ef9638fec6d6224405be4dc7fdb8 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 6 Dec 2024 11:08:55 +0100 Subject: [PATCH] exclude light sensor calls on unsupported devices add mqtt default host define --- src/lib/defaults.hpp | 1 + src/lib/mqtt.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index 3a06218..fa6603f 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -57,6 +57,7 @@ #define DEFAULT_BITAXE_HOSTNAME "bitaxe1" #define DEFAULT_MQTT_ENABLED false +#define DEFAULT_MQTT_HOST "" #define DEFAULT_MQTT_ROOTTOPIC "home/" #define DEFAULT_ZAP_NOTIFY_ENABLED false diff --git a/src/lib/mqtt.cpp b/src/lib/mqtt.cpp index 1fc9d1e..b522bd9 100644 --- a/src/lib/mqtt.cpp +++ b/src/lib/mqtt.cpp @@ -6,8 +6,10 @@ WiFiClient wifiClient; PubSubClient client(wifiClient); // avoid circular deps, just forward declare externs used here. +#ifdef HAS_FRONTLIGHT bool hasLightLevel(); float getLightLevel(); +#endif String getMyHostname(); void onMqttCallback(char* topic, byte* payload, unsigned int length) @@ -43,7 +45,7 @@ boolean connectMqtt() void setupMqtt() { - const String host = preferences.getString("mqttHost", ""); + const String host = preferences.getString("mqttHost", DEFAULT_MQTT_HOST); if (host == "") { Serial.println("[MQTT] host not set"); @@ -80,11 +82,13 @@ void mqttTask(void *pvParameters) continue; } +#ifdef HAS_FRONTLIGHT if (hasLightLevel()) { std::string lux_s = std::to_string(static_cast(std::round(getLightLevel()))); publish("sensors/lux", lux_s.c_str()); } +#endif if (WiFi.isConnected()) { int8_t rssi = WiFi.RSSI();