diff --git a/src/MicroOcpp/Model/Transactions/TransactionService.cpp b/src/MicroOcpp/Model/Transactions/TransactionService.cpp index d0e58e1f..75e70f8d 100644 --- a/src/MicroOcpp/Model/Transactions/TransactionService.cpp +++ b/src/MicroOcpp/Model/Transactions/TransactionService.cpp @@ -345,6 +345,24 @@ void TransactionService::Evse::loop() { return; } + // triggerReason is required by the 2.0.1 schema. Some stop paths + // reach here with it UNDEFINED - notably a CSMS deAuthorization + // (TransactionEvent::processConf clears `active` directly, without + // going through endTransaction, so no stopTrigger is recorded). An + // Ended with no triggerReason is rejected by the CSMS + // (FormatViolation) and retried forever, stalling the tx queue. + // Fill a valid reason before the event is built and committed. + if (triggerReason == TransactionEventTriggerReason::UNDEFINED) { + triggerReason = transaction->isDeauthorized + ? TransactionEventTriggerReason::Deauthorized + : TransactionEventTriggerReason::AbnormalCondition; + } + if (stoppedReason == Ocpp201::Transaction::StoppedReason::UNDEFINED) { + stoppedReason = transaction->isDeauthorized + ? Ocpp201::Transaction::StoppedReason::DeAuthorized + : Ocpp201::Transaction::StoppedReason::Other; + } + transaction->stopTrigger = triggerReason; transaction->stoppedReason = stoppedReason; diff --git a/src/MicroOcpp/Model/Transactions/TransactionStore.cpp b/src/MicroOcpp/Model/Transactions/TransactionStore.cpp index 39c096ba..509b54d2 100644 --- a/src/MicroOcpp/Model/Transactions/TransactionStore.cpp +++ b/src/MicroOcpp/Model/Transactions/TransactionStore.cpp @@ -536,7 +536,7 @@ bool TransactionStoreEvse::deserializeTransactionEvent(TransactionEventData& txE } TransactionEventTriggerReason triggerReason; - if (!deserializeTransactionEventTriggerReason(txEventJson["triggerReason"] | "_Undefined", triggerReason)) { + if (!deserializeTransactionEventTriggerReason(txEventJson["triggerReason"] | (const char*)nullptr, triggerReason)) { return false; } txEvent.triggerReason = triggerReason;