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

Only send status notifications on reconnect if we received a disconnect callback #216

Merged
merged 1 commit into from
Oct 16, 2023
Merged
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
10 changes: 7 additions & 3 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <ocpp/v201/messages/FirmwareStatusNotification.hpp>
#include <ocpp/v201/messages/LogStatusNotification.hpp>

using namespace std::literals::chrono_literals;

namespace ocpp {
namespace v201 {

Expand Down Expand Up @@ -511,10 +513,11 @@ void ChargePoint::init_websocket() {
AttributeEnum::Actual, std::to_string(security_profile));
}

if (this->registration_status == RegistrationStatusEnum::Accepted) {
if (this->registration_status == RegistrationStatusEnum::Accepted and
this->time_disconnected.time_since_epoch() != 0s) {
// 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;
auto offline_duration = std::chrono::steady_clock::now() - this->time_disconnected;

// B04.FR.01
// If offline period exceeds offline threshold then send the status notification for all connectors
Expand All @@ -539,6 +542,7 @@ void ChargePoint::init_websocket() {
}
}
}
this->time_disconnected = std::chrono::time_point<std::chrono::steady_clock>();
});

this->websocket->register_closed_callback(
Expand All @@ -565,7 +569,7 @@ void ChargePoint::init_websocket() {
}
}
// Get the current time point using steady_clock
time_disconnected = std::chrono::steady_clock::now();
this->time_disconnected = std::chrono::steady_clock::now();
}

if (!this->disable_automatic_websocket_reconnects) {
Expand Down