Fixed influxdb write
This commit is contained in:
parent
2bdc615ddb
commit
29c52d0a34
1 changed files with 63 additions and 29 deletions
92
firmware/influxdb.ino
Normal file → Executable file
92
firmware/influxdb.ino
Normal file → Executable file
|
@ -1,37 +1,71 @@
|
|||
|
||||
void pushToInfluxDB(String device, float sensorValues[]) {
|
||||
|
||||
#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])
|
||||
+ ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE])
|
||||
+ ",esavemode=" + String(sensorValues[SENSOR_ESAVEMODE])
|
||||
+ ",batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]);
|
||||
uint8_t tries = 0;
|
||||
boolean addComma = false;
|
||||
|
||||
tries++;
|
||||
String msg = "weather,device=" + device + " ";
|
||||
if (!(isnan(sensorValues[SENSOR_TEMPERATURE])))
|
||||
{
|
||||
msg += "temperature=" + String(sensorValues[SENSOR_TEMPERATURE]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_HUMIDITY])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "humidity=" + String(sensorValues[SENSOR_HUMIDITY]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_LIGHT])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "light=" + String(sensorValues[SENSOR_LIGHT]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_WINDSPEED])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "windspeed=" + String(sensorValues[SENSOR_WINDSPEED]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_PRESSURE])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "pressure=" + String(sensorValues[SENSOR_PRESSURE]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_BAT_VOLTAGE])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_ESAVEMODE])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "esavemode=" + String(sensorValues[SENSOR_ESAVEMODE]);
|
||||
addComma = true;
|
||||
}
|
||||
if (!(isnan(sensorValues[SENSOR_BATCHARGESTATE])))
|
||||
{
|
||||
if (true == addComma)
|
||||
msg += ",";
|
||||
msg += "batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]);
|
||||
addComma = true;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println(msg);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uint8_t tries = 0;
|
||||
do {
|
||||
tries++;
|
||||
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]));
|
||||
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]));
|
||||
influxdb.write(msg);
|
||||
} while (influxdb.response() != DB_SUCCESS and tries < 5);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue