Skip to content

Commit

Permalink
Add energy consumed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Bettapro committed Feb 26, 2024
1 parent 35dd230 commit 6ee7e86
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 5 deletions.
5 changes: 4 additions & 1 deletion SolarTracerBlynk/src/core/VariableDefiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ VariableDefiner::VariableDefiner() {
this->initializeVariable(Variable::LOAD_FORCE_ONOFF, "Load force switch", VariableDatatype::DT_BOOL, VariableUOM::UOM_UNDEFINED, VariableSource::SR_REALTIME, VariableMode::MD_READ, nullptr, nullptr);
this->initializeVariable(Variable::LOAD_MANUAL_ONOFF, "Load switch", VariableDatatype::DT_BOOL, VariableUOM::UOM_UNDEFINED, VariableSource::SR_REALTIME, VariableMode::MD_READWRITE, vPIN_LOAD_ENABLED_DF, MQTT_TOPIC_LOAD_ENABLED_DF);
this->initializeVariable(Variable::REMOTE_BATTERY_TEMP, "Remote batt. temp.", VariableDatatype::DT_FLOAT, VariableUOM::UOM_TEMPERATURE_C, VariableSource::SR_REALTIME, VariableMode::MD_READ, vPIN_BATT_TEMP_DF, MQTT_TOPIC_BATT_TEMP_DF);
this->initializeVariable(Variable::CONSUMED_ENERGY_TODAY, "Energy consumed today", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_CONSUMED_TODAY_DF, MQTT_TOPIC_STAT_ENERGY_CONSUMED_TODAY_DF);
this->initializeVariable(Variable::CONSUMED_ENERGY_MONTH, "Energy consumed month", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_CONSUMED_THIS_MONTH_DF, MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_MONTH_DF);
this->initializeVariable(Variable::CONSUMED_ENERGY_YEAR, "Energy consumed year", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_CONSUMED_THIS_YEAR_DF, MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_YEAR_DF);
this->initializeVariable(Variable::CONSUMED_ENERGY_TOTAL, "Energy consumed", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_CONSUMED_TOTAL_DF, MQTT_TOPIC_STAT_ENERGY_CONSUMED_TOTAL_DF);
this->initializeVariable(Variable::GENERATED_ENERGY_TODAY, "Energy generated today", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_GENERATED_TODAY_DF, MQTT_TOPIC_STAT_ENERGY_GENERATED_TODAY_DF);
this->initializeVariable(Variable::GENERATED_ENERGY_MONTH, "Energy generated month", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_GENERATED_THIS_MONTH_DF, MQTT_TOPIC_STAT_ENERGY_GENERATED_THIS_MONTH_DF);
this->initializeVariable(Variable::GENERATED_ENERGY_YEAR, "Energy generated year", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_GENERATED_THIS_YEAR_DF, MQTT_TOPIC_STAT_ENERGY_GENERATED_THIS_YEAR_DF);
Expand Down Expand Up @@ -77,7 +81,6 @@ VariableDefiner::VariableDefiner() {
this->initializeVariable(Variable::BATTERY_BOOST_DURATION, "Boost duration", VariableDatatype::DT_UINT16, VariableUOM::UOM_MINUTE, VariableSource::SR_STATS, VariableMode::MD_READWRITE, vPIN_BATTERY_BOOST_DURATION_DF, MQTT_TOPIC_BATTERY_BOOST_DURATION_DF);
this->initializeVariable(Variable::BATTERY_TEMPERATURE_COMPENSATION_COEFFICIENT, "Batt. temp. compensation coeff.", VariableDatatype::DT_FLOAT, VariableUOM::UOM_UNDEFINED, VariableSource::SR_STATS, VariableMode::MD_READWRITE, vPIN_BATTERY_TEMPERATURE_COMPENSATION_COEFF_DF, MQTT_TOPIC_BATTERY_TEMPERATURE_COMPENSATION_COEFF_DF);
this->initializeVariable(Variable::BATTERY_MANAGEMENT_MODE, "Batt. management mode", VariableDatatype::DT_UINT16, VariableUOM::UOM_UNDEFINED, VariableSource::SR_STATS, VariableMode::MD_READWRITE, vPIN_BATTERY_MANAGEMENT_MODE_DF, MQTT_TOPIC_BATTERY_MANAGEMENT_MODE_DF);
this->initializeVariable(Variable::CONSUMED_ENERGY_TOTAL, "Energy consumed", VariableDatatype::DT_FLOAT, VariableUOM::UOM_KILOWATTHOUR, VariableSource::SR_STATS, VariableMode::MD_READ, vPIN_STAT_ENERGY_CONSUMED_TOTAL_DF, MQTT_TOPIC_STAT_ENERGY_CONSUMED_TOTAL_DF);
}

const VariableDefinition *VariableDefiner::getDefinitionByBlynkVPin(uint8_t pin) {
Expand Down
3 changes: 3 additions & 0 deletions SolarTracerBlynk/src/core/VariableDefiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ typedef enum {
BATTERY_BOOST_DURATION,
BATTERY_TEMPERATURE_COMPENSATION_COEFFICIENT,
BATTERY_MANAGEMENT_MODE, // 0 - voltage compensation, 1 - SOC
CONSUMED_ENERGY_TODAY,
CONSUMED_ENERGY_MONTH,
CONSUMED_ENERGY_YEAR,
CONSUMED_ENERGY_TOTAL,
//----------------
INTERNAL_STATUS,
Expand Down
15 changes: 15 additions & 0 deletions SolarTracerBlynk/src/incl/include_all_blynk_vpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@
#else
#define vPIN_BATTERY_MANAGEMENT_MODE_DF new uint8_t(vPIN_BATTERY_MANAGEMENT_MODE)
#endif
#ifndef vPIN_STAT_ENERGY_CONSUMED_TODAY
#define vPIN_STAT_ENERGY_CONSUMED_TODAY_DF nullptr
#else
#define vPIN_STAT_ENERGY_CONSUMED_TODAY_DF new uint8_t(vPIN_STAT_ENERGY_CONSUMED_TODAY)
#endif
#ifndef vPIN_STAT_ENERGY_CONSUMED_THIS_MONTH
#define vPIN_STAT_ENERGY_CONSUMED_THIS_MONTH_DF nullptr
#else
#define vPIN_STAT_ENERGY_CONSUMED_THIS_MONTH_DF new uint8_t(vPIN_STAT_ENERGY_CONSUMED_THIS_MONTH)
#endif
#ifndef vPIN_STAT_ENERGY_CONSUMED_THIS_YEAR
#define vPIN_STAT_ENERGY_CONSUMED_THIS_YEAR_DF nullptr
#else
#define vPIN_STAT_ENERGY_CONSUMED_THIS_YEAR_DF new uint8_t(vPIN_STAT_ENERGY_CONSUMED_THIS_YEAR)
#endif
#ifndef vPIN_STAT_ENERGY_CONSUMED_TOTAL
#define vPIN_STAT_ENERGY_CONSUMED_TOTAL_DF nullptr
#else
Expand Down
15 changes: 15 additions & 0 deletions SolarTracerBlynk/src/incl/include_all_mqtt_topic.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@
#else
#define MQTT_TOPIC_BATTERY_MANAGEMENT_MODE_DF MQTT_TOPIC_BATTERY_MANAGEMENT_MODE
#endif
#ifndef MQTT_TOPIC_STAT_ENERGY_CONSUMED_TODAY
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_TODAY_DF nullptr
#else
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_TODAY_DF MQTT_TOPIC_STAT_ENERGY_CONSUMED_TODAY
#endif
#ifndef MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_MONTH
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_MONTH_DF nullptr
#else
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_MONTH_DF MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_MONTH
#endif
#ifndef MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_YEAR
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_YEAR_DF nullptr
#else
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_YEAR_DF MQTT_TOPIC_STAT_ENERGY_CONSUMED_THIS_YEAR
#endif
#ifndef MQTT_TOPIC_STAT_ENERGY_CONSUMED_TOTAL
#define MQTT_TOPIC_STAT_ENERGY_CONSUMED_TOTAL_DF nullptr
#else
Expand Down
19 changes: 15 additions & 4 deletions SolarTracerBlynk/src/solartracer/epever/EPEVERSolarTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ EPEVERSolarTracer::EPEVERSolarTracer(Stream &serialCom, uint16_t serialTimeoutMs
this->setVariableEnable(Variable::GENERATED_ENERGY_MONTH);
this->setVariableEnable(Variable::GENERATED_ENERGY_YEAR);
this->setVariableEnable(Variable::GENERATED_ENERGY_TOTAL);
this->setVariableEnable(Variable::CONSUMED_ENERGY_TODAY);
this->setVariableEnable(Variable::CONSUMED_ENERGY_MONTH);
this->setVariableEnable(Variable::CONSUMED_ENERGY_YEAR);
this->setVariableEnable(Variable::CONSUMED_ENERGY_TOTAL);
this->setVariableEnable(Variable::MAXIMUM_PV_VOLTAGE_TODAY);
this->setVariableEnable(Variable::MINIMUM_PV_VOLTAGE_TODAY);
this->setVariableEnable(Variable::MAXIMUM_BATTERY_VOLTAGE_TODAY);
Expand Down Expand Up @@ -610,10 +614,17 @@ void EPEVERSolarTracer::updateStats() {

rs485readSuccess = this->lastControllerCommunicationStatus == this->node.ku8MBSuccess;
if (rs485readSuccess) {
this->setFloatVariable(Variable::MAXIMUM_PV_VOLTAGE_TODAY, this->node.getResponseBuffer(0x00) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MINIMUM_PV_VOLTAGE_TODAY, this->node.getResponseBuffer(0x01) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MAXIMUM_BATTERY_VOLTAGE_TODAY, this->node.getResponseBuffer(0x02) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MINIMUM_BATTERY_VOLTAGE_TODAY, this->node.getResponseBuffer(0x03) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MAXIMUM_PV_VOLTAGE_TODAY, this->node.getResponseBuffer(0) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MINIMUM_PV_VOLTAGE_TODAY, this->node.getResponseBuffer(1) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MAXIMUM_BATTERY_VOLTAGE_TODAY, this->node.getResponseBuffer(2) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::MINIMUM_BATTERY_VOLTAGE_TODAY, this->node.getResponseBuffer(3) / ONE_HUNDRED_FLOAT);

if(!this->isVariableOverWritten(Variable::CONSUMED_ENERGY_TOTAL)){
this->setFloatVariable(Variable::CONSUMED_ENERGY_TODAY, (this->node.getResponseBuffer(4) | this->node.getResponseBuffer(5) << 16) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::CONSUMED_ENERGY_MONTH, (this->node.getResponseBuffer(6) | this->node.getResponseBuffer(7) << 16) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::CONSUMED_ENERGY_YEAR, (this->node.getResponseBuffer(8) | this->node.getResponseBuffer(9) << 16) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::CONSUMED_ENERGY_TOTAL, (this->node.getResponseBuffer(10) | this->node.getResponseBuffer(11) << 16) / ONE_HUNDRED_FLOAT);
}

this->setFloatVariable(Variable::GENERATED_ENERGY_TODAY, (this->node.getResponseBuffer(12) | this->node.getResponseBuffer(13) << 16) / ONE_HUNDRED_FLOAT);
this->setFloatVariable(Variable::GENERATED_ENERGY_MONTH, (this->node.getResponseBuffer(14) | this->node.getResponseBuffer(15) << 16) / ONE_HUNDRED_FLOAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#define MODBUS_ADDRESS_CHARGING_EQUIPMENT_STATUS 0x3200
#define MODBUS_ADDRESS_DISCHARGING_EQUIPMENT_STATUS 0x3200
#define MODBUS_ADDRESS_STAT_MAX_PV_VOLTAGE_TODAY 0x3300
#define MODBUS_ADDRESS_STAT_CONSUMED_ENERGY_TODAY 0x3304
#define MODBUS_ADDRESS_STAT_CONSUMED_ENERGY_MONTH 0x3306
#define MODBUS_ADDRESS_STAT_CONSUMED_ENERGY_YEAR 0x3308
#define MODBUS_ADDRESS_STAT_GENERATED_ENERGY_TODAY 0x330C
#define MODBUS_ADDRESS_STAT_GENERATED_ENERGY_MONTH 0x330E
#define MODBUS_ADDRESS_STAT_GENERATED_ENERGY_YEAR 0x3310
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class LoadCurrentOverwrite {

tracer->setVariableOverWritten(Variable::LOAD_CURRENT, true);
tracer->setVariableOverWritten(Variable::LOAD_POWER, tracer->isVariableEnabled(Variable::BATTERY_VOLTAGE));
tracer->setVariableOverWritten(Variable::CONSUMED_ENERGY_TODAY, tracer->isVariableEnabled(Variable::BATTERY_VOLTAGE));
tracer->setVariableOverWritten(Variable::CONSUMED_ENERGY_MONTH, tracer->isVariableEnabled(Variable::BATTERY_VOLTAGE));
tracer->setVariableOverWritten(Variable::CONSUMED_ENERGY_YEAR, tracer->isVariableEnabled(Variable::BATTERY_VOLTAGE));
tracer->setVariableOverWritten(Variable::CONSUMED_ENERGY_TOTAL, tracer->isVariableEnabled(Variable::BATTERY_VOLTAGE));
tracer->setVariableOverWritten(Variable::BATTERY_OVERALL_CURRENT, tracer->isVariableEnabled(Variable::BATTERY_CHARGE_CURRENT));
}
Expand Down Expand Up @@ -97,6 +100,9 @@ class LoadCurrentOverwrite {
tracer->setVariableValue(Variable::LOAD_POWER, &loadPower, true);

totalLoadEnergy += loadEnergy;
tracer->setVariableValue(Variable::CONSUMED_ENERGY_TODAY, &totalLoadEnergy, true);
tracer->setVariableValue(Variable::CONSUMED_ENERGY_MONTH, &totalLoadEnergy, true);
tracer->setVariableValue(Variable::CONSUMED_ENERGY_YEAR, &totalLoadEnergy, true);
tracer->setVariableValue(Variable::CONSUMED_ENERGY_TOTAL, &totalLoadEnergy, true);
}

Expand Down

0 comments on commit 6ee7e86

Please sign in to comment.