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();