Skip to content

Commit

Permalink
Add websocket option update on component variable change (#263)
Browse files Browse the repository at this point in the history
* add websocket option update on component variable change

Signed-off-by: Fabian Klemm <[email protected]>

* Update lib/ocpp/v201/charge_point.cpp

Co-authored-by: Dominik-K <[email protected]>
Signed-off-by: Fabian Klemm <[email protected]>

---------

Signed-off-by: Fabian Klemm <[email protected]>
Co-authored-by: Dominik-K <[email protected]>
  • Loading branch information
2 people authored and valentin-dimov committed Nov 16, 2023
1 parent 95db166 commit d0d9e66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/ocpp/common/websocket/websocket_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ WebsocketBase::~WebsocketBase() {
}

void WebsocketBase::set_connection_options_base(const WebsocketConnectionOptions& connection_options) {
this->connection_attempts = 0;
this->connection_options = connection_options;
}

Expand Down
28 changes: 28 additions & 0 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,23 @@ void ChargePoint::handle_scheduled_change_availability_requests(const int32_t ev
}
}

/**
* Determine for a component variable whether it affects the Websocket Connection Options (cf.
* get_ws_connection_options); return true if it is furthermore writable and does not require a reconnect
*
* @param component_variable
* @return
*/
static bool component_variable_change_requires_websocket_option_update_without_reconnect(
const ComponentVariable& component_variable) {

return component_variable == ControllerComponentVariables::RetryBackOffRandomRange ||
component_variable == ControllerComponentVariables::RetryBackOffRepeatTimes ||
component_variable == ControllerComponentVariables::RetryBackOffWaitMinimum ||
component_variable == ControllerComponentVariables::NetworkProfileConnectionAttempts ||
component_variable == ControllerComponentVariables::WebSocketPingInterval;
}

void ChargePoint::handle_variable_changed(const SetVariableData& set_variable_data) {

ComponentVariable component_variable = {set_variable_data.component, std::nullopt, set_variable_data.variable};
Expand Down Expand Up @@ -1219,6 +1236,17 @@ void ChargePoint::handle_variable_changed(const SetVariableData& set_variable_da
if (component_variable == ControllerComponentVariables::AlignedDataInterval) {
this->update_aligned_data_interval();
}

if (component_variable_change_requires_websocket_option_update_without_reconnect(component_variable)) {
EVLOG_debug << "Reconfigure websocket due to relevant change of ControllerComponentVariable";
const auto configuration_slot =
ocpp::get_vector_from_csv(
this->device_model->get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority))
.at(this->network_configuration_priority);
const auto connection_options = this->get_ws_connection_options(std::stoi(configuration_slot));
this->websocket->set_connection_options(connection_options);
}

// TODO(piet): other special handling of changed variables can be added here...
}

Expand Down

0 comments on commit d0d9e66

Please sign in to comment.