Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current Shaper now use "max_current" instead of "charge_current". #495

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/current_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ unsigned long CurrentShaperTask::loop(MicroTasks::WakeReason reason) {
if (_enabled && !_evse->clientHasClaim(EvseClient_OpenEVSE_Divert)) {
EvseProperties props;
if (_changed) {
props.setChargeCurrent(_chg_cur);
if (_chg_cur < evse.getMinCurrent() ) {
props.setMaxCurrent(_max_cur);
if (_max_cur < evse.getMinCurrent() ) {
// pause temporary, not enough amps available
props.setState(EvseState::Disabled);
}
Expand All @@ -36,7 +36,8 @@ unsigned long CurrentShaperTask::loop(MicroTasks::WakeReason reason) {
event["shaper"] = 1;
event["shaper_live_pwr"] = _live_pwr;
event["shaper_max_pwr"] = _max_pwr;
event["shaper_cur"] = _chg_cur;
event["shaper_cur"] = _max_cur;
event["shaper_updated"] = true;
event_send(event);
}
if (millis() - _timer > EVSE_SHAPER_FAILSAFE_TIME) {
Expand All @@ -48,7 +49,8 @@ unsigned long CurrentShaperTask::loop(MicroTasks::WakeReason reason) {
event["shaper"] = 1;
event["shaper_live_pwr"] = _live_pwr;
event["shaper_max_pwr"] = _max_pwr;
event["shaper_cur"] = _chg_cur;
event["shaper_cur"] = _max_cur;
event["shaper_updated"] = false;
event_send(event);
}
}
Expand All @@ -69,7 +71,7 @@ void CurrentShaperTask::begin(EvseManager &evse) {
this -> _evse = &evse;
this -> _max_pwr = current_shaper_max_pwr;
this -> _live_pwr = 0;
this -> _chg_cur = 0;
this -> _max_cur = 0;
MicroTask.startTask(this);
StaticJsonDocument<128> event;
event["shaper"] = 1;
Expand Down Expand Up @@ -110,7 +112,7 @@ void CurrentShaperTask::setState(bool state) {
}

void CurrentShaperTask::shapeCurrent() {
_chg_cur = round(((_max_pwr - _live_pwr) / evse.getVoltage()) + (evse.getAmps()));
_max_cur = round(((_max_pwr - _live_pwr) / evse.getVoltage()) + (evse.getAmps()));
_changed = true;
}

Expand All @@ -120,8 +122,9 @@ int CurrentShaperTask::getMaxPwr() {
int CurrentShaperTask::getLivePwr() {
return _live_pwr;
}
uint8_t CurrentShaperTask::getChgCur() {
return _chg_cur;

uint8_t CurrentShaperTask::getMaxCur() {
return _max_cur;
}
bool CurrentShaperTask::getState() {
return _enabled;
Expand Down
5 changes: 3 additions & 2 deletions src/current_shaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class CurrentShaperTask: public MicroTasks::Task
bool _enabled;
bool _changed;
int _max_pwr; // total current available from the grid
int _live_pwr; // current available to EVSE
int _live_pwr; // current available to EVSE
uint8_t _chg_cur; // calculated charge current to claim
uint8_t _max_cur; // shaper calculated max current
uint32_t _timer;

protected:
Expand All @@ -46,7 +47,7 @@ class CurrentShaperTask: public MicroTasks::Task
bool getState();
int getMaxPwr();
int getLivePwr();
uint8_t getChgCur();
uint8_t getMaxCur();
bool isActive();

void notifyConfigChanged(bool enabled, uint32_t max_pwr);
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
else if (topic_string == mqtt_live_pwr)
{
shaper.setLivePwr(payload_str.toInt());
DBUGF("shaper: available amps:%dA", shaper.getChgCur());
DBUGF("shaper: Live Pwr:%dW", shaper.getLivePwr());
}
else if (topic_string == mqtt_vrms)
{
Expand Down
3 changes: 2 additions & 1 deletion src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ void buildStatus(DynamicJsonDocument &doc) {

doc["shaper"] = shaper.getState()?1:0;
doc["shaper_live_pwr"] = shaper.getLivePwr();
doc["shaper_chg_cur"] = shaper.getChgCur();
// doc["shaper_cur"] = shaper.getChgCur();
doc["shaper_cur"] = shaper.getMaxCur();

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

Expand Down