mirror of
https://github.com/revspace/operame
synced 2024-11-01 05:57:30 +00:00
Merge pull request #9 from SanderVanhove/main
Add temperature and humidity to rest message
This commit is contained in:
commit
f9c3d05ce9
55
operame.ino
55
operame.ino
@ -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);
|
||||||
@ -602,9 +601,9 @@ void loop() {
|
|||||||
connect_mqtt();
|
connect_mqtt();
|
||||||
//CO2
|
//CO2
|
||||||
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"] = "CO2";
|
doc["variable"] = "CO2";
|
||||||
doc["value"] = co2;
|
doc["value"] = co2;
|
||||||
doc["unit"] = "ppm";
|
doc["unit"] = "ppm";
|
||||||
serializeJson(doc, message);
|
serializeJson(doc, message);
|
||||||
@ -612,34 +611,28 @@ 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");
|
String message;
|
||||||
}
|
const size_t capacity = JSON_OBJECT_SIZE(3);
|
||||||
else {
|
DynamicJsonDocument doc(capacity);
|
||||||
String message;
|
doc["variable"] = "temperature";
|
||||||
const size_t capacity = JSON_OBJECT_SIZE(3);
|
doc["value"] = t;
|
||||||
DynamicJsonDocument doc(capacity);
|
doc["unit"] = "C";
|
||||||
doc["variable"] = "temperature";
|
serializeJson(doc, message);
|
||||||
doc["value"] = t;
|
retain(mqtt_topic_temperature, message);
|
||||||
doc["unit"] = "C";
|
|
||||||
serializeJson(doc, message);
|
|
||||||
retain(mqtt_topic_temperature, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//humidity
|
//humidity
|
||||||
if(isnan(h)) {
|
if(!isnan(h)) {
|
||||||
Serial.println("Failed to read from DHT sensor, so no MQTT publish");
|
String message;
|
||||||
}
|
const size_t capacity = JSON_OBJECT_SIZE(3);
|
||||||
else {
|
DynamicJsonDocument doc(capacity);
|
||||||
String message;
|
doc["variable"] = "humidity";
|
||||||
const size_t capacity = JSON_OBJECT_SIZE(3);
|
doc["value"] = h;
|
||||||
DynamicJsonDocument doc(capacity);
|
doc["unit"] = "%R.H.";
|
||||||
doc["variable"] = "humidity";
|
serializeJson(doc, message);
|
||||||
doc["value"] = h;
|
retain(mqtt_topic_humidity, message);
|
||||||
doc["unit"] = "%R.H.";
|
}
|
||||||
serializeJson(doc, message);
|
|
||||||
retain(mqtt_topic_humidity, message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user