exclude light sensor calls on unsupported devices
add mqtt default host define
This commit is contained in:
parent
adf6b38bfb
commit
ee81edbcd2
2 changed files with 6 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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<int>(std::round(getLightLevel())));
|
||||
publish("sensors/lux", lux_s.c_str());
|
||||
}
|
||||
#endif
|
||||
if (WiFi.isConnected())
|
||||
{
|
||||
int8_t rssi = WiFi.RSSI();
|
||||
|
|
Loading…
Reference in a new issue