Skip to content

Commit f0bd916

Browse files
committed
only send co2 sensor values if the sensor is ready; move intervals to config
1 parent 3f892ca commit f0bd916

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/config.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#define SCREEN_WIDTH 128 // OLED display width, in pixels
22
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
33

4+
#define READ_SENSOR_INTERVAL 60000 // in ms
5+
#define MQTT_UPDATE_INTERVAL 45000 // in ms
46
#define PASSWORD "waaatering"
57

68
int CO2_WARN_PPM = 1200;

src/main.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,12 @@ void sendInfo()
149149
JsonObject co2Meter = doc.createNestedObject("co2");
150150
co2Meter["isPreheating"] = isPreheating;
151151
co2Meter["isReady"] = isCo2SensorReady;
152-
co2Meter["temperature"] = lastTemperature;
153-
co2Meter["ppm"] = lastCo2Value;
152+
153+
if (isCo2SensorReady)
154+
{
155+
co2Meter["temperature"] = lastTemperature;
156+
co2Meter["ppm"] = lastCo2Value;
157+
}
154158

155159
String JS;
156160
serializeJson(doc, JS);
@@ -511,7 +515,7 @@ void loop()
511515
{
512516
appState = 2;
513517

514-
if (lastCo2Measurement == 0 || millis() - lastCo2Measurement >= 60000) // every minute
518+
if (lastCo2Measurement == 0 || millis() - lastCo2Measurement >= READ_SENSOR_INTERVAL)
515519
{
516520
lastTemperature = co2Sensor.getLastTemperature();
517521
lastCo2Value = co2Sensor.readCO2UART();
@@ -546,7 +550,7 @@ void loop()
546550

547551
if (isWifiConnected && isMqttConnected)
548552
{
549-
if (lastInfoSend == 0 || millis() - lastInfoSend >= 45000) // every 45 seconds
553+
if (lastInfoSend == 0 || millis() - lastInfoSend >= MQTT_UPDATE_INTERVAL)
550554
{
551555
sendInfo(); // TODO move to async timer
552556
}

0 commit comments

Comments
 (0)