Skip to content

Commit

Permalink
* Send status notification if offline period exceeds threshold
Browse files Browse the repository at this point in the history
* Store the connector status when offline into a map
* send status notification for changed connectors when back online

Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: pietfried <pietgoempel@gmail.com>
  • Loading branch information
SNSubramanya authored and Pietfried committed Sep 18, 2023
1 parent 33c3546 commit 73c97f5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ class ChargePoint : ocpp::ChargingStationBase {
int network_configuration_priority;
bool disable_automatic_websocket_reconnects;

// store the connector status
struct EvseConnectorPair {
int32_t evse_id;
int32_t connector_id;

// Define a comparison operator for the struct
bool operator<(const EvseConnectorPair& other) const {
// Compare based on name, then age
if (evse_id != other.evse_id) {
return evse_id < other.evse_id;
}
return connector_id < other.connector_id;
}
};

std::map<EvseConnectorPair, ConnectorStatusEnum> conn_state_per_evse;
std::chrono::time_point<std::chrono::steady_clock> time_disconnected;

/// \brief Used when an 'OnIdle' reset is requested, to perform the reset after the charging has stopped.
bool reset_scheduled;
/// \brief If `reset_scheduled` is true and the reset is for a specific evse id, it will be stored in this member.
Expand Down
48 changes: 48 additions & 0 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,35 @@ void ChargePoint::init_websocket() {
this->websocket->register_connected_callback([this](const int security_profile) {
this->message_queue->resume();
this->websocket_connection_status = WebsocketConnectionStatusEnum::Connected;

if (this->registration_status == RegistrationStatusEnum::Accepted) {
// handle offline threshold
// Get the current time point using steady_clock
std::chrono::steady_clock::duration offline_duration = std::chrono::steady_clock::now() - time_disconnected;

// B04.FR.01
// If offline period exceeds offline threshold then send the status notification for all connectors
if (offline_duration > std::chrono::seconds(this->device_model->get_value<int>(
ControllerComponentVariables::OfflineThreshold))) {
EVLOG_debug << "offline for more than offline threshold ";
for (auto const& [evse_id, evse] : this->evses) {
evse->trigger_status_notification_callbacks();
}
} else {
// B04.FR.02
// If offline period doesn't exceed offline threshold then send the status notification for all
// connectors that changed state
EVLOG_debug << "offline for less than offline threshold ";
for (auto const& [evse_id, evse] : this->evses) {
int number_of_connectors = evse->get_number_of_connectors();
for (int connector_id = 1; connector_id <= number_of_connectors; connector_id++) {
if (conn_state_per_evse[{evse_id, connector_id}] != evse->get_state(connector_id)) {
evse->trigger_status_notification_callback(connector_id);
}
}
}
}
}
});

this->websocket->register_closed_callback(
Expand All @@ -480,6 +509,25 @@ void ChargePoint::init_websocket() {
this->websocket_connection_status = WebsocketConnectionStatusEnum::Disconnected;
this->message_queue->pause();

// check if offline threshold has been defined
if (this->device_model->get_value<int>(ControllerComponentVariables::OfflineThreshold) != 0) {
// get the status of all the connectors
for (auto const& [evse_id, evse] : this->evses) {
int number_of_connectors = evse->get_number_of_connectors();
EvseConnectorPair conn_states_struct_key;
EVLOG_debug << "evseId: " << evse_id << " numConn: " << number_of_connectors;
for (int connector_id = 1; connector_id <= number_of_connectors; connector_id++) {
conn_states_struct_key.evse_id = evse_id;
conn_states_struct_key.connector_id = connector_id;
conn_state_per_evse[conn_states_struct_key] = evse->get_state(connector_id);
EVLOG_debug << "conn_id: " << conn_states_struct_key.connector_id
<< " State: " << conn_state_per_evse[conn_states_struct_key];
}
}
// Get the current time point using steady_clock
time_disconnected = std::chrono::steady_clock::now();
}

if (!this->disable_automatic_websocket_reconnects) {
this->websocket_timer.timeout(
[this, reason]() {
Expand Down

0 comments on commit 73c97f5

Please sign in to comment.