Skip to content

Commit

Permalink
Merge pull request #501 from KipK/shaper_updated
Browse files Browse the repository at this point in the history
fix missing shaper_updated in /status
  • Loading branch information
jeremypoulter committed Dec 15, 2022
2 parents 3fdc923 + 35c6876 commit 90e818c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/current_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,29 @@ unsigned long CurrentShaperTask::loop(MicroTasks::WakeReason reason) {
props.setState(EvseState::None);
}
_changed = false;
_updated = true;
_timer = millis();
evse.claim(EvseClient_OpenEVSE_Shaper,EvseManager_Priority_Safety, props);
StaticJsonDocument<128> event;
event["shaper"] = 1;
event["shaper_live_pwr"] = _live_pwr;
event["shaper_max_pwr"] = _max_pwr;
event["shaper_cur"] = _max_cur;
event["shaper_updated"] = true;
event["shaper_updated"] = _updated;
event_send(event);
}
if (millis() - _timer > EVSE_SHAPER_FAILSAFE_TIME) {
//available power has not been updated since EVSE_SHAPER_FAILSAFE_TIME, pause charge
DBUGF("shaper_live_pwr has not been updated in time, pausing charge");
_updated = false;
props.setState(EvseState::Disabled);
evse.claim(EvseClient_OpenEVSE_Shaper,EvseManager_Priority_Limit, props);
StaticJsonDocument<128> event;
event["shaper"] = 1;
event["shaper_live_pwr"] = _live_pwr;
event["shaper_max_pwr"] = _max_pwr;
event["shaper_cur"] = _max_cur;
event["shaper_updated"] = false;
event["shaper_updated"] = _updated;
event_send(event);
}
}
Expand All @@ -71,7 +73,8 @@ void CurrentShaperTask::begin(EvseManager &evse) {
this -> _evse = &evse;
this -> _max_pwr = current_shaper_max_pwr;
this -> _live_pwr = 0;
this -> _max_cur = 0;
this -> _max_cur = 0;
this -> _updated = false;
MicroTask.startTask(this);
StaticJsonDocument<128> event;
event["shaper"] = 1;
Expand Down Expand Up @@ -112,6 +115,7 @@ void CurrentShaperTask::setState(bool state) {
}

void CurrentShaperTask::shapeCurrent() {
_updated = true;
_max_cur = round(((_max_pwr - _live_pwr) / evse.getVoltage()) + (evse.getAmps()));
_changed = true;
}
Expand All @@ -132,4 +136,8 @@ bool CurrentShaperTask::getState() {

bool CurrentShaperTask::isActive() {
return _evse->clientHasClaim(EvseClient_OpenEVSE_Shaper);
}

bool CurrentShaperTask::isUpdated() {
return _updated;
}
2 changes: 2 additions & 0 deletions src/current_shaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CurrentShaperTask: public MicroTasks::Task
uint8_t _chg_cur; // calculated charge current to claim
uint8_t _max_cur; // shaper calculated max current
uint32_t _timer;
bool _updated;

protected:
void setup();
Expand All @@ -49,6 +50,7 @@ class CurrentShaperTask: public MicroTasks::Task
int getLivePwr();
uint8_t getMaxCur();
bool isActive();
bool isUpdated();

void notifyConfigChanged(bool enabled, uint32_t max_pwr);
};
Expand Down
2 changes: 1 addition & 1 deletion src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void buildStatus(DynamicJsonDocument &doc) {
doc["shaper_live_pwr"] = shaper.getLivePwr();
// doc["shaper_cur"] = shaper.getChgCur();
doc["shaper_cur"] = shaper.getMaxCur();

doc["shaper_updated"] = shaper.isUpdated();
doc["service_level"] = static_cast<uint8_t>(evse.getActualServiceLevel());

doc["ota_update"] = (int)Update.isRunning();
Expand Down

0 comments on commit 90e818c

Please sign in to comment.