Browse Source

Pushing only valid values

Thomas Kopp 1 year ago
parent
commit
07ed99f9a2
1 changed files with 18 additions and 12 deletions
  1. 18
    12
      firmware/influxdb.ino

+ 18
- 12
firmware/influxdb.ino View File

@@ -1,13 +1,7 @@
1 1
 
2 2
 void pushToInfluxDB(String device, float sensorValues[]) {
3 3
 
4
-  /*influxdb.write("weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE]));
5
-  influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY]));
6
-  influxdb.write("weather,device=" + device + " light=" + String(sensorValues[SENSOR_LIGHT]));
7
-  influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED]));
8
-  influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
9
-  influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]));*/
10
-
4
+  #ifdef DEBUG
11 5
   String msg = "weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE])
12 6
                + ",humidity=" + String(sensorValues[SENSOR_HUMIDITY])
13 7
                + ",light=" + String(sensorValues[SENSOR_LIGHT])
@@ -15,12 +9,24 @@ void pushToInfluxDB(String device, float sensorValues[]) {
15 9
                + ",pressure=" + String(sensorValues[SENSOR_PRESSURE])
16 10
                + ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]);
17 11
 
18
-  uint8_t tries = 0;
12
+  Serial.println(msg);
13
+  #endif
14
+
15
+ uint8_t tries = 0;
19 16
   do {
20 17
     tries++;
21
-    influxdb.write(msg);
18
+    if (!(isnan(sensorValues[SENSOR_TEMPERATURE])))
19
+      influxdb.write("weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE]));
20
+    if (!(isnan(sensorValues[SENSOR_HUMIDITY])))
21
+      influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY]));
22
+    if (!(isnan(sensorValues[SENSOR_LIGHT])))
23
+      influxdb.write("weather,device=" + device + " light=" + String(sensorValues[SENSOR_LIGHT]));
24
+    if (!(isnan(sensorValues[SENSOR_WINDSPEED])))
25
+      influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED]));
26
+    if (!(isnan(sensorValues[SENSOR_PRESSURE])))
27
+      influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
28
+    if (!(isnan(sensorValues[SENSOR_BAT_VOLTAGE])))
29
+      influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]));
22 30
   } while (influxdb.response() != DB_SUCCESS and tries < 5);
23
-
24
-
25 31
 }
26
-
32
+

Loading…
Cancel
Save