Skip to content

Commit 6289c6c

Browse files
committed
If the humidity sensor fails do not use humidity compensation
This also uses the new error codes
1 parent 2c5a41e commit 6289c6c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/Wemos/Wemos.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <Arduino.h>
15+
#include <math.h>
1516
#include <DHT.h> // Adafruit's DHT sensor library https://github.com/adafruit/DHT-sensor-library
1617
#include <DHT_U.h>
1718
#include <DNSServer.h> // Local DNS Server used for redirecting all requests to the configuration portal
@@ -86,7 +87,11 @@ void loop() {
8687

8788
// Compensate for humidity
8889
float humidity = dht.readHumidity();
90+
if (isnan(humidity)) {
91+
data.error |= H_ERROR_HUMIDITY;
92+
} else {
8993
sensor.humidityCompensation(data, humidity);
94+
}
9095

9196
// Send the data to the hackAIR server
9297
String dataJson = "{\"reading\":{\"PM2.5_AirPollutantValue\":\"";
@@ -98,7 +103,7 @@ void loop() {
98103
dataJson += "\",\"tamper\":\"";
99104
dataJson += "0";
100105
dataJson += "\",\"error\":\"";
101-
dataJson += "0";
106+
dataJson += data.error;
102107
dataJson += "\"}";
103108
if (client.connect("api.hackair.eu", 443)) {
104109
Serial.println("connected");

0 commit comments

Comments
 (0)