Skip to content

Commit

Permalink
Properly handle setting the max current by setting in the value in th…
Browse files Browse the repository at this point in the history
…e EVSE EEPROM rather than the WiFi config

Fixes OpenEVSE#326
  • Loading branch information
jeremypoulter committed Mar 11, 2022
1 parent 51c3c42 commit 8a7d7ab
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lib_deps =
jeremypoulter/ArduinoMongoose@0.0.17
jeremypoulter/Micro Debug@0.0.5
jeremypoulter/ConfigJson@0.0.4
jeremypoulter/OpenEVSE@0.0.10
jeremypoulter/OpenEVSE@0.0.11
jeremypoulter/ESPAL@0.0.3
jeremypoulter/StreamSpy@0.0.1
jeremypoulter/MicroTasks@0.0.2
Expand Down
7 changes: 0 additions & 7 deletions src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ String tesla_vehicle_id;
uint8_t led_brightness;
#endif

long max_current_soft;

String esp_hostname_default = "openevse-"+ESPAL.getShortId();

void config_changed(String name);
Expand Down Expand Up @@ -156,9 +154,6 @@ ConfigOpt *opts[] =
new ConfigOptDefenition<uint8_t>(led_brightness, LED_DEFAULT_BRIGHTNESS, "led_brightness", "lb"),
#endif

// EVSE settings
new ConfigOptDefenition<long>(max_current_soft, LONG_MAX, "max_current_soft", "mcs"),

// Flags
&flagsOpt,

Expand Down Expand Up @@ -243,8 +238,6 @@ void config_changed(String name)
} else if(name == "led_brightness") {
ledManager.setBrightness(led_brightness);
#endif
} else if(name == "max_current_soft") {
evse.setMaxConfiguredCurrent(max_current_soft);
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/evse_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,9 @@ void EvseMonitor::updateCurrentSettings(long min_current, long max_hardware_curr
{
DBUGF("min_current = %ld, pilot = %ld, max_configured_current = %ld, max_hardware_current = %ld", min_current, pilot, max_configured_current, max_hardware_current);
_min_current = min_current;
// The max_configured_current is a write once value, so as fare as we are concerned that is the 'hardware' max. We manage the acrual soft limit in the WiFi code.
_max_hardware_current = max_configured_current;
_max_hardware_current = max_hardware_current;
_pilot = pilot;
if(_max_configured_current > _max_hardware_current || _max_configured_current < _min_current) {
_max_configured_current = _max_hardware_current;
}
_max_configured_current = max_configured_current;
}


Expand Down Expand Up @@ -654,10 +651,19 @@ void EvseMonitor::setMaxConfiguredCurrent(long amps)
amps = _min_current;
}

_max_configured_current = amps;
DBUGVAR(_max_configured_current);
_openevse.setCurrentCapacity(amps, true, [this, amps](int ret, long pilot)
{
if(RAPI_RESPONSE_OK == ret)
{
_max_configured_current = amps;
DBUGVAR(_max_configured_current);

_settings_changed.Trigger();
_pilot = pilot;
DBUGVAR(_pilot);

_settings_changed.Trigger();
}
});
}

void EvseMonitor::getStatusFromEvse(bool allowStart)
Expand Down
9 changes: 9 additions & 0 deletions src/web_server_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ handleConfigPost(MongooseHttpServerRequest *request, MongooseHttpServerResponseS
DBUGLN("service changed");
}
}
if(doc.containsKey("max_current_soft"))
{
long current = doc["max_current_soft"];
if(current != evse.getMaxConfiguredCurrent()) {
evse.setMaxConfiguredCurrent(current);
config_modified = true;
DBUGLN("max_current_soft changed");
}
}
if(doc.containsKey("scale") && doc.containsKey("offset"))
{
long scale = doc["scale"];
Expand Down
3 changes: 2 additions & 1 deletion test/claims.http
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Content-Type: application/json

{
"state": "active",
"auto_release": true
"auto_release": true,
"charge_current": 20
}

###
Expand Down

0 comments on commit 8a7d7ab

Please sign in to comment.