diff --git a/modules/API/API.cpp b/modules/API/API.cpp index c64d550dd..65eee0b82 100644 --- a/modules/API/API.cpp +++ b/modules/API/API.cpp @@ -489,12 +489,15 @@ void API::init() { std::string cmd_set_limit = cmd_base + "set_limit_amps"; - this->mqtt.subscribe(cmd_set_limit, [&evse, &r_evse_manager_energy_sink = this->r_evse_manager_energy_sink, + const auto& evse_energy_sink = this->r_evse_manager_energy_sink.at(evse_id); + + this->mqtt.subscribe(cmd_set_limit, [&evse_manager_check = this->evse_manager_check, + &evse_energy_sink = evse_energy_sink, evse_id](const std::string& data) { try { const auto external_limits = get_external_limits(data, false); - this->evse_manager_check.wait_ready(); - r_evse_manager_energy_sink.at(evse_id - 1)->call_set_external_limits(external_limits); + evse_manager_check.wait_ready(); + evse_energy_sink->call_set_external_limits(external_limits); } catch (const std::invalid_argument& e) { EVLOG_warning << "Invalid limit: No conversion of given input could be performed."; } catch (const std::out_of_range& e) { @@ -504,20 +507,20 @@ void API::init() { std::string cmd_set_limit_watts = cmd_base + "set_limit_watts"; - this->mqtt.subscribe( - cmd_set_limit_watts, - [&evse, &r_evse_manager_energy_sink = this->r_evse_manager_energy_sink, evse_id](const std::string& data) { - try { - const auto external_limits = get_external_limits(data, true); - this->evse_manager_check.wait_ready(); - r_evse_manager_energy_sink.at(evse_id - 1)->call_set_external_limits(external_limits); // FIX access - } catch (const std::invalid_argument& e) { - EVLOG_warning << "Invalid limit: No conversion of given input could be performed."; - } catch (const std::out_of_range& e) { - EVLOG_warning << "Invalid limit: Out of range."; - } - }); - + this->mqtt.subscribe(cmd_set_limit_watts, [&evse_manager_check = this->evse_manager_check, + &evse_energy_sink = evse_energy_sink, + evse_id](const std::string& data) { + try { + const auto external_limits = get_external_limits(data, true); + evse_manager_check.wait_ready(); + evse_energy_sink->call_set_external_limits(external_limits); + } catch (const std::invalid_argument& e) { + EVLOG_warning << "Invalid limit: No conversion of given input could be performed."; + } catch (const std::out_of_range& e) { + EVLOG_warning << "Invalid limit: Out of range."; + } + }); + std::string cmd_force_unlock = cmd_base + "force_unlock"; this->mqtt.subscribe(cmd_force_unlock, [this, &evse](const std::string& data) { int connector_id = 1; diff --git a/modules/OCPP/OCPP.cpp b/modules/OCPP/OCPP.cpp index 52cc6b771..c7aa5b14a 100644 --- a/modules/OCPP/OCPP.cpp +++ b/modules/OCPP/OCPP.cpp @@ -102,7 +102,7 @@ void OCPP::set_external_limits(const std::mapr_evse_manager_energy_sink.empty()) { EVLOG_debug << "OCPP sets the following external limits for connector 0: \n" << limits; - this->r_evse_manager_energy_sink.at(0)->call_set_external_limits(limits); + this->r_evse_manager_energy_sink.first()->call_set_external_limits(limits); } else { EVLOG_debug << "OCPP cannot set external limits for connector 0. No " "sink is configured."; diff --git a/modules/OCPP/doc.rst b/modules/OCPP/doc.rst index 0201ce257..c1b382fec 100644 --- a/modules/OCPP/doc.rst +++ b/modules/OCPP/doc.rst @@ -38,7 +38,7 @@ OCPP1.6 defines the SmartCharging feature profile to allow the CSMS to control o This module integrates the composite schedule(s) within EVerests energy management. For further information about smart charging and the composite schedule calculation please refer to the OCPP1.6 specification. -The integration of the composite schedules are turned out by the optional requirement(s) `evse_manager_energy_sink`(interface: `external_energy_limits`) +The integration of the composite schedules are implemented through the optional requirement(s) `evse_manager_energy_sink`(interface: `external_energy_limits`) of this module. Depending on the number of EVSEs configured, each composite limit is communicated via a seperate sink, including the composite schedule for EVSE with id 0 (representing the whole charging station). The easiest way to explain this is with an example. If your charging station has two EVSEs you need to connect three modules that implement the `external_energy_limits` interface: One representing evse id 0 and