From 07ed99f9a2de994d30b6110d38c49d4e8df02a65 Mon Sep 17 00:00:00 2001 From: Thomas Kopp <20.kopp@gmail.com> Date: Sun, 27 Jan 2019 16:29:58 +0100 Subject: [PATCH] Pushing only valid values --- firmware/influxdb.ino | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) mode change 100755 => 100644 firmware/influxdb.ino diff --git a/firmware/influxdb.ino b/firmware/influxdb.ino old mode 100755 new mode 100644 index 3312d4d..e6aea1b --- a/firmware/influxdb.ino +++ b/firmware/influxdb.ino @@ -1,13 +1,7 @@ void pushToInfluxDB(String device, float sensorValues[]) { - /*influxdb.write("weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE])); - influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY])); - influxdb.write("weather,device=" + device + " light=" + String(sensorValues[SENSOR_LIGHT])); - influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED])); - influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE])); - influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]));*/ - + #ifdef DEBUG String msg = "weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE]) + ",humidity=" + String(sensorValues[SENSOR_HUMIDITY]) + ",light=" + String(sensorValues[SENSOR_LIGHT]) @@ -15,12 +9,24 @@ void pushToInfluxDB(String device, float sensorValues[]) { + ",pressure=" + String(sensorValues[SENSOR_PRESSURE]) + ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]); - uint8_t tries = 0; + Serial.println(msg); + #endif + + uint8_t tries = 0; do { tries++; - influxdb.write(msg); + if (!(isnan(sensorValues[SENSOR_TEMPERATURE]))) + influxdb.write("weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE])); + if (!(isnan(sensorValues[SENSOR_HUMIDITY]))) + influxdb.write("weather,device=" + device + " humidity=" + String(sensorValues[SENSOR_HUMIDITY])); + if (!(isnan(sensorValues[SENSOR_LIGHT]))) + influxdb.write("weather,device=" + device + " light=" + String(sensorValues[SENSOR_LIGHT])); + if (!(isnan(sensorValues[SENSOR_WINDSPEED]))) + influxdb.write("weather,device=" + device + " windspeed=" + String(sensorValues[SENSOR_WINDSPEED])); + if (!(isnan(sensorValues[SENSOR_PRESSURE]))) + influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE])); + if (!(isnan(sensorValues[SENSOR_BAT_VOLTAGE]))) + influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE])); } while (influxdb.response() != DB_SUCCESS and tries < 5); - - } - +