From 7771a02be734d4f794172d41dd1159f57ddb789f Mon Sep 17 00:00:00 2001 From: Kai Hermann Date: Tue, 10 Dec 2024 10:34:42 +0100 Subject: [PATCH] OCPP 1.6: support multiple temperature readings (#986) * OCPP 1.6: support multiple teamperature readings Add optional location to temperature type * Add a simulated temperature to JsYetiSimulator powermeter * Bump libocpp dependency --------- Signed-off-by: Kai-Uwe Hermann --- dependencies.yaml | 2 +- modules/OCPP/OCPP.cpp | 3 +++ modules/OCPP/conversions.cpp | 13 +++++++++++++ modules/OCPP/conversions.hpp | 3 +++ modules/simulation/JsYetiSimulator/index.js | 6 ++++++ types/temperature.yaml | 5 +++-- 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dependencies.yaml b/dependencies.yaml index ba80b2e47..d7186c819 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -67,7 +67,7 @@ libevse-security: # OCPP libocpp: git: https://github.com/EVerest/libocpp.git - git_tag: 469629c615e369f4bb77b3b2f861e0d56b550d15 + git_tag: 2f005e04460149f71a223e381733b2e2471abdc0 cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBOCPP" # Josev Josev: diff --git a/modules/OCPP/OCPP.cpp b/modules/OCPP/OCPP.cpp index 595044f89..b9d8d6d9c 100644 --- a/modules/OCPP/OCPP.cpp +++ b/modules/OCPP/OCPP.cpp @@ -265,6 +265,9 @@ void OCPP::init_evse_subscriptions() { // soc is present, so add this to the measurement measurement.soc_Percent = ocpp::StateOfCharge{this->evse_soc_map[evse_id].value()}; } + if (powermeter.temperatures.has_value()) { + measurement.temperature_C = conversions::to_ocpp_temperatures(powermeter.temperatures.value()); + } this->charge_point->on_meter_values(evse_id, measurement); }); diff --git a/modules/OCPP/conversions.cpp b/modules/OCPP/conversions.cpp index 7fb62a649..07f61a099 100644 --- a/modules/OCPP/conversions.cpp +++ b/modules/OCPP/conversions.cpp @@ -245,6 +245,19 @@ ocpp::Powermeter to_ocpp_power_meter(const types::powermeter::Powermeter& powerm return ocpp_powermeter; } +std::vector to_ocpp_temperatures(const std::vector& temperatures) { + std::vector ocpp_temperatures; + for (const auto temperature : temperatures) { + ocpp::Temperature ocpp_temperature; + ocpp_temperature.value = temperature.temperature; + if (temperature.location.has_value()) { + ocpp_temperature.location = temperature.location.value(); + } + ocpp_temperatures.push_back(ocpp_temperature); + } + return ocpp_temperatures; +} + ocpp::v201::HashAlgorithmEnum to_ocpp_hash_algorithm_enum(const types::iso15118_charger::HashAlgorithm hash_algorithm) { switch (hash_algorithm) { case types::iso15118_charger::HashAlgorithm::SHA256: diff --git a/modules/OCPP/conversions.hpp b/modules/OCPP/conversions.hpp index 108fa5499..416bfb315 100644 --- a/modules/OCPP/conversions.hpp +++ b/modules/OCPP/conversions.hpp @@ -63,6 +63,9 @@ ocpp::v16::BootReasonEnum to_ocpp_boot_reason_enum(const types::system::BootReas /// \brief Converts a given types::powermeter::Powermeter \p powermeter to a ocpp::Powermeter ocpp::Powermeter to_ocpp_power_meter(const types::powermeter::Powermeter& powermeter); +/// \brief Converts a given vector of types::temperature::Temperature \p powermeter to a vector of ocpp::Temperature +std::vector to_ocpp_temperatures(const std::vector& temperatures); + /// \brief Converts a given types::iso15118_charger::HashAlgorithm \p hash_algorithm to a ocpp::v201::HashAlgorithmEnum. ocpp::v201::HashAlgorithmEnum to_ocpp_hash_algorithm_enum(const types::iso15118_charger::HashAlgorithm hash_algorithm); diff --git a/modules/simulation/JsYetiSimulator/index.js b/modules/simulation/JsYetiSimulator/index.js index 5bf3dcdc2..2d5c9ff90 100644 --- a/modules/simulation/JsYetiSimulator/index.js +++ b/modules/simulation/JsYetiSimulator/index.js @@ -912,6 +912,12 @@ function power_meter_external(p) { L2: p.freqL2, L3: p.freqL3, }, + temperatures: [ + { + temperature: p.tempL1, + location: "Body" + } + ] }); } diff --git a/types/temperature.yaml b/types/temperature.yaml index 9c7cc06d9..240cabb27 100644 --- a/types/temperature.yaml +++ b/types/temperature.yaml @@ -13,5 +13,6 @@ types: identification: description: A (vendor specific) ID if required type: string - - + location: + description: Location of the measurement + type: string