ESP32-PowerGuard/src/InfluxDBModule.cpp

23 lines
926 B
C++
Raw Normal View History

2024-02-05 18:02:07 +00:00
// InfluxDBModule.cpp
#include "InfluxDBModule.h"
InfluxDBModule::InfluxDBModule(String url, String org, String bucket, String token)
: client(url, org, bucket, token, InfluxDbCloud2CACert) {}
bool InfluxDBModule::connectToInfluxDB() {
return client.validateConnection();
}
bool InfluxDBModule::sendData(float current, float busVoltage, float power, float avgPower, float totalEnergy, int relay1State, int relay2State) {
Point sensorData("sensor_data");
sensorData.addTag("device", "ESP32");
sensorData.addField("current", current);
sensorData.addField("busVoltage", busVoltage);
sensorData.addField("power", power);
sensorData.addField("avgPower", avgPower);
sensorData.addField("totalEnergy", totalEnergy);
sensorData.addField("relay1StateINT", relay1State);
sensorData.addField("relay2StateINT", relay2State);
return client.writePoint(sensorData);
}