From 1be2559b0afdd86eae07af07203f0fb3465d7eb1 Mon Sep 17 00:00:00 2001 From: patrick Date: Fri, 13 Nov 2026 14:37:54 +0900 Subject: [PATCH] fix(2.0.1): close CSMS-deauthorized transactions - Ended was sent without triggerReason When the CSMS deauthorizes a running 2.0.1 transaction (the Started TransactionEvent response carries an idTokenInfo.status other than Accepted), the Ended TransactionEvent was built with triggerReason UNDEFINED. triggerReason is required by the 2.0.1 schema, so a conformant CSMS rejects it with CallError FormatViolation and rejects every retry identically: the transaction can never be closed, stays Active on the CSMS, and its on-device record is never trimmed, eventually filling the per-connector store (MO_TXRECORD_SIZE) so beginTransaction() refuses new transactions. Two linked defects: 1. TransactionService.cpp: TransactionEvent::processConf() ends a deauthorized transaction by clearing `active` directly, bypassing Evse::endTransaction() (the only place that records stopTrigger). The following Evse::loop() then builds the Ended event with the local triggerReason still UNDEFINED. Fill a valid reason before committing the event: Deauthorized/DeAuthorized when isDeauthorized, else AbnormalCondition/Other. 2. TransactionStore.cpp: deserializeTransactionEvent() defaulted a missing triggerReason to the sentinel "_Undefined", which deserializeTransactionEventTriggerReason() rejects, failing the whole event and stalling the send queue. Use (const char*)nullptr to match the sibling stopTrigger read, so an absent field reads back as UNDEFINED. Reproduced on ESP32 (ESP-IDF, MO_ENABLE_V201=1) against CitrineOS 2.0.0-beta3; verified over 6 consecutive deauthorized cycles (0 FormatViolation, every Ended carries triggerReason, store freed each cycle). Co-Authored-By: Claude Opus 4.8 --- .../Model/Transactions/TransactionService.cpp | 18 ++++++++++++++++++ .../Model/Transactions/TransactionStore.cpp | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) 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;