weatherstation/firmware/influxdb.ino

38 lines
2 KiB
Arduino
Raw Normal View History

void pushToInfluxDB(String device, float sensorValues[]) {
2019-01-27 16:29:58 +01:00
#ifdef DEBUG
String msg = "weather,device=" + device + " temperature=" + String(sensorValues[SENSOR_TEMPERATURE])
+ ",humidity=" + String(sensorValues[SENSOR_HUMIDITY])
+ ",light=" + String(sensorValues[SENSOR_LIGHT])
+ ",windspeed=" + String(sensorValues[SENSOR_WINDSPEED])
+ ",pressure=" + String(sensorValues[SENSOR_PRESSURE])
2019-02-02 10:09:00 +01:00
+ ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE])
+ ",esavemode=" + String(sensorValues[SENSOR_ESAVEMODE])
+ ",batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]);
2019-01-27 16:29:58 +01:00
Serial.println(msg);
#endif
uint8_t tries = 0;
do {
tries++;
2019-01-27 16:29:58 +01:00
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]));
2019-02-02 10:09:00 +01:00
if (!(isnan(sensorValues[SENSOR_ESAVEMODE])))
influxdb.write("weather,device=" + device + " esavemode=" + String(sensorValues[SENSOR_ESAVEMODE]));
if (!(isnan(sensorValues[SENSOR_BATCHARGESTATE])))
influxdb.write("weather,device=" + device + " batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]));
} while (influxdb.response() != DB_SUCCESS and tries < 5);
}