1
0
mirror of https://github.com/revspace/operame synced 2024-10-31 21:47:30 +00:00

bugfix: check if the user wants to send temperature and humidity via MQTT

This commit is contained in:
Pieter De Mil 2021-07-26 15:41:51 +02:00
parent 9ce786bc62
commit b6c24d252a

View File

@ -610,35 +610,37 @@ void loop() {
serializeJson(doc, message); serializeJson(doc, message);
retain(mqtt_topic, message); retain(mqtt_topic, message);
//temperature if(mqtt_temp_hum_enabled) {
if(isnan(t)) { //temperature
Serial.println("Failed to read from DHT sensor, so no MQTT publish"); if(isnan(t)) {
} Serial.println("Failed to read from DHT sensor, so no MQTT publish");
else { }
String message; else {
const size_t capacity = JSON_OBJECT_SIZE(3); String message;
DynamicJsonDocument doc(capacity); const size_t capacity = JSON_OBJECT_SIZE(3);
doc["variable"] = "temperature"; DynamicJsonDocument doc(capacity);
doc["value"] = t; doc["variable"] = "temperature";
doc["unit"] = "C"; doc["value"] = t;
serializeJson(doc, message); doc["unit"] = "C";
retain(mqtt_topic, message); serializeJson(doc, message);
} retain(mqtt_topic, message);
}
//humidity //humidity
if(isnan(h)) { if(isnan(h)) {
Serial.println("Failed to read from DHT sensor, so no MQTT publish"); Serial.println("Failed to read from DHT sensor, so no MQTT publish");
} }
else { else {
String message; String message;
const size_t capacity = JSON_OBJECT_SIZE(3); const size_t capacity = JSON_OBJECT_SIZE(3);
DynamicJsonDocument doc(capacity); DynamicJsonDocument doc(capacity);
doc["variable"] = "humidity"; doc["variable"] = "humidity";
doc["value"] = h; doc["value"] = h;
doc["unit"] = "%R.H."; doc["unit"] = "%R.H.";
serializeJson(doc, message); serializeJson(doc, message);
retain(mqtt_topic, message); retain(mqtt_topic, message);
} }
}
} }
} }