Skip to content

Commit

Permalink
Fix for DEV V4.0 Lifetime energy incorrectly displayes 0kWh #153
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypoulter committed Feb 28, 2021
1 parent 687721f commit a6b09ea
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/evse_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
#define EVSE_MONITOR_FAULT_COUNT_BOOT_READY (1 << 0)
#define EVSE_MONITOR_FLAGS_BOOT_READY (1 << 1)
#define EVSE_MONITOR_CURRENT_BOOT_READY (1 << 2)
#define EVSE_MONITOR_ENERGY_BOOT_READY (1 << 3)

#define EVSE_MONITOR_BOOT_READY (\
#define EVSE_MONITOR_BOOT_READY ( \
EVSE_MONITOR_FAULT_COUNT_BOOT_READY | \
EVSE_MONITOR_FLAGS_BOOT_READY | \
EVSE_MONITOR_CURRENT_BOOT_READY \
EVSE_MONITOR_CURRENT_BOOT_READY | \
EVSE_MONITOR_ENERGY_BOOT_READY \
)

EvseMonitor::EvseStateEvent::EvseStateEvent() :
Expand Down Expand Up @@ -200,6 +202,17 @@ void EvseMonitor::evseBoot(const char *firmware)
}
});

_openevse.getEnergy([this](int ret, double session_wh, double total_kwh)
{
if(RAPI_RESPONSE_OK == ret)
{
DBUGF("session_wh = %.2f, total_kwh = %.2f", session_wh, total_kwh);
_total_kwh = total_kwh;

_boot_ready.ready(EVSE_MONITOR_ENERGY_BOOT_READY);
}
});

_openevse.heartbeatEnable(EVSE_HEATBEAT_INTERVAL, EVSE_HEARTBEAT_CURRENT, [this](int ret, int interval, int current, int triggered) {
_heartbeat = RAPI_RESPONSE_OK == ret;
});
Expand Down Expand Up @@ -262,7 +275,7 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)
if(_state.isCharging())
{
DBUGLN("Get charge current/voltage status");
OpenEVSE.getChargeCurrentAndVoltage([this](int ret, double a, double volts)
_openevse.getChargeCurrentAndVoltage([this](int ret, double a, double volts)
{
if(RAPI_RESPONSE_OK == ret)
{
Expand All @@ -282,7 +295,7 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)
if(0 == _count % EVSE_MONITOR_TEMP_TIME)
{
DBUGLN("Get tempurature status");
OpenEVSE.getTemperature([this](int ret, double t1, bool t1_valid, double t2, bool t2_valid, double t3, bool t3_valid)
_openevse.getTemperature([this](int ret, double t1, bool t1_valid, double t2, bool t2_valid, double t3, bool t3_valid)
{
if(RAPI_RESPONSE_OK == ret)
{
Expand Down Expand Up @@ -316,7 +329,7 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)
if(_state.isCharging())
{
DBUGLN("Get charge energy usage");
OpenEVSE.getEnergy([this](int ret, double session_wh, double total_kwh)
_openevse.getEnergy([this](int ret, double session_wh, double total_kwh)
{
if(RAPI_RESPONSE_OK == ret)
{
Expand All @@ -339,7 +352,7 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)

bool EvseMonitor::begin(RapiSender &sender)
{
OpenEVSE.begin(sender, [this](bool connected, const char *firmware, const char *protocol)
_openevse.begin(sender, [this](bool connected, const char *firmware, const char *protocol)
{
if(connected)
{
Expand Down

0 comments on commit a6b09ea

Please sign in to comment.