From b6c24d252adcc011bee107452ba795840517005a Mon Sep 17 00:00:00 2001 From: Pieter De Mil Date: Mon, 26 Jul 2021 15:41:51 +0200 Subject: [PATCH] bugfix: check if the user wants to send temperature and humidity via MQTT --- operame.ino | 58 +++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/operame.ino b/operame.ino index 1624d83..7d7969d 100644 --- a/operame.ino +++ b/operame.ino @@ -610,35 +610,37 @@ void loop() { serializeJson(doc, message); retain(mqtt_topic, message); - //temperature - if(isnan(t)) { - Serial.println("Failed to read from DHT sensor, so no MQTT publish"); - } - else { - String message; - const size_t capacity = JSON_OBJECT_SIZE(3); - DynamicJsonDocument doc(capacity); - doc["variable"] = "temperature"; - doc["value"] = t; - doc["unit"] = "C"; - serializeJson(doc, message); - retain(mqtt_topic, message); - } + if(mqtt_temp_hum_enabled) { + //temperature + if(isnan(t)) { + Serial.println("Failed to read from DHT sensor, so no MQTT publish"); + } + else { + String message; + const size_t capacity = JSON_OBJECT_SIZE(3); + DynamicJsonDocument doc(capacity); + doc["variable"] = "temperature"; + doc["value"] = t; + doc["unit"] = "C"; + serializeJson(doc, message); + retain(mqtt_topic, message); + } - //humidity - if(isnan(h)) { - Serial.println("Failed to read from DHT sensor, so no MQTT publish"); - } - else { - String message; - const size_t capacity = JSON_OBJECT_SIZE(3); - DynamicJsonDocument doc(capacity); - doc["variable"] = "humidity"; - doc["value"] = h; - doc["unit"] = "%R.H."; - serializeJson(doc, message); - retain(mqtt_topic, message); - } + //humidity + if(isnan(h)) { + Serial.println("Failed to read from DHT sensor, so no MQTT publish"); + } + else { + String message; + const size_t capacity = JSON_OBJECT_SIZE(3); + DynamicJsonDocument doc(capacity); + doc["variable"] = "humidity"; + doc["value"] = h; + doc["unit"] = "%R.H."; + serializeJson(doc, message); + retain(mqtt_topic, message); + } + } } }