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

Add temp and humidity to rest message

This commit is contained in:
Sander Vanhove 2021-09-01 16:09:03 +02:00
parent b1766c1b3f
commit 56a53b0a1c

View File

@ -584,7 +584,6 @@ void loop() {
} else { } else {
// Check if there is a humidity sensor // Check if there is a humidity sensor
if (isnan(h) || isnan(t)) { if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
// Only display CO2 value (the old way) // Only display CO2 value (the old way)
// some MH-Z19's go to 10000 but the display has space for 4 digits // some MH-Z19's go to 10000 but the display has space for 4 digits
display_ppm(co2 > 9999 ? 9999 : co2); display_ppm(co2 > 9999 ? 9999 : co2);
@ -612,10 +611,7 @@ void loop() {
if(mqtt_temp_hum_enabled) { if(mqtt_temp_hum_enabled) {
//temperature //temperature
if(isnan(t)) { if(!isnan(t)) {
Serial.println("Failed to read from DHT sensor, so no MQTT publish");
}
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);
@ -627,10 +623,7 @@ void loop() {
} }
//humidity //humidity
if(isnan(h)) { if(!isnan(h)) {
Serial.println("Failed to read from DHT sensor, so no MQTT publish");
}
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);
@ -653,9 +646,11 @@ void loop() {
every(rest_interval) { every(rest_interval) {
if (co2 <= 0) break; if (co2 <= 0) break;
const size_t capacity = JSON_OBJECT_SIZE(2); const size_t capacity = JSON_OBJECT_SIZE(4);
DynamicJsonDocument message(capacity); DynamicJsonDocument message(capacity);
message["co2"] = co2; message["co2"] = co2;
message["temperature"] = t;
message["humidity"] = h;
message["id"] = rest_resource_id.c_str(); message["id"] = rest_resource_id.c_str();
if (wificlientsecure.connected() || wificlientsecure.connect(&rest_domain[0], rest_port)) { if (wificlientsecure.connected() || wificlientsecure.connect(&rest_domain[0], rest_port)) {