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

Add websocket option update on component variable change #263

Merged
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
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 @@ -1198,6 +1198,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 @@ -1228,6 +1245,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