From 6978cf22a4a08cfb1621fb7342ce8dd67c9021ce Mon Sep 17 00:00:00 2001 From: Michael Maroszek Date: Wed, 22 Oct 2025 21:29:45 +0200 Subject: [PATCH 1/2] sum charging by id tag under the splitter instance --- OCPP Charging Point/module.php | 12 ++++++++++-- OCPP Splitter/module.php | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/OCPP Charging Point/module.php b/OCPP Charging Point/module.php index c90a44b..7363221 100644 --- a/OCPP Charging Point/module.php +++ b/OCPP Charging Point/module.php @@ -14,7 +14,6 @@ class OCPPChargingPoint extends IPSModule private const START_ID_BOTH = 3; private const START_MANUALLY = 4; - public function Create() { //Never delete this line! @@ -63,6 +62,7 @@ public function ReceiveData($JSONString) $messageType = $message['Message'][2]; $payload = $message['Message'][3]; + $result = ""; switch ($messageType) { case 'BootNotification': $this->SetValue('Vendor', $payload['chargePointVendor']); @@ -80,7 +80,7 @@ public function ReceiveData($JSONString) $this->processStartTransaction($messageID, $payload); break; case 'StopTransaction': - $this->processStopTransaction($messageID, $payload); + $result = json_encode($this->processStopTransaction($messageID, $payload)); break; case 'Authorize': $this->processAuthorize($messageID, $payload); @@ -97,6 +97,8 @@ public function ReceiveData($JSONString) default: break; } + + return $result; } public function RequestAction($Ident, $Value) @@ -490,6 +492,12 @@ private function processStopTransaction(string $messageID, $payload) $status = isset($payload['idTag']) ? $this->getIdTagStatus($payload['idTag']) : 'Accepted'; $this->send($this->getStopTransactionResponse($messageID, $status)); + + // Return consumption data to properly forward it to the splitter + return [ + "IdTag" => $this->GetValue(sprintf('Transaction_ID_Tag_%d', $connectorId)), + "Consumption" => $this->GetValue(sprintf('TransactionConsumption_%d', $connectorId)), + ]; } private function processAuthorize(string $messageID, $payload) diff --git a/OCPP Splitter/module.php b/OCPP Splitter/module.php index fe1546f..beb8cbe 100644 --- a/OCPP Splitter/module.php +++ b/OCPP Splitter/module.php @@ -80,13 +80,25 @@ protected function ProcessHookData() return; } - //Send it to the children - $this->SendDataToChildren(json_encode([ + // Send it to the children + $responses = $this->SendDataToChildren(json_encode([ 'DataID' => '{54E04042-D715-71A0-BA80-ADD8B6CDF151}', 'ChargePointIdentity' => $chargePointIdentity, 'Message' => $message ])); + // We want to check the response, if a charging was completed and we need to collect the charging data + foreach($responses as $response) { + $data = json_decode($response, true); + + $ident = sprintf("Consumption_%s", $data['IdTag']); + $this->RegisterVariableInteger($ident, sprintf($this->Translate('Consumption (IdTag %s)'), $data['IdTag']), [ + 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, + 'SUFFIX' => ' Wh' + ]); + $this->SetValue($ident, $this->GetValue($ident) + $data['Consumption']); + } + /** * OCPP-j-1.6-specification Page 13 * Input[1] is the MessageID From 7fbc412c01ebe930d7b601064ae5c21dce6a6fdc Mon Sep 17 00:00:00 2001 From: Michael Maroszek Date: Wed, 22 Oct 2025 22:03:50 +0200 Subject: [PATCH 2/2] small fixes --- OCPP Charging Point/module.php | 2 +- OCPP Splitter/module.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/OCPP Charging Point/module.php b/OCPP Charging Point/module.php index 7363221..fc65ca3 100644 --- a/OCPP Charging Point/module.php +++ b/OCPP Charging Point/module.php @@ -449,7 +449,7 @@ private function processStartTransaction(string $messageID, $payload) $payload['idTag'] = $this->GetValue('IdTag'); } - $this->SetValue('Transaction_ID_Tag_%d', $payload['idTag']); + $this->SetValue($ident, $payload['idTag']); $ident = sprintf('TransactionConsumption_%d', $payload['connectorId']); $this->RegisterVariableInteger($ident, sprintf($this->Translate('Transaction Consumption (Connector %d)'), $payload['connectorId']), [ diff --git a/OCPP Splitter/module.php b/OCPP Splitter/module.php index beb8cbe..8521b59 100644 --- a/OCPP Splitter/module.php +++ b/OCPP Splitter/module.php @@ -92,7 +92,8 @@ protected function ProcessHookData() $data = json_decode($response, true); $ident = sprintf("Consumption_%s", $data['IdTag']); - $this->RegisterVariableInteger($ident, sprintf($this->Translate('Consumption (IdTag %s)'), $data['IdTag']), [ + $idTag = $data['IdTag'] ? sprintf('IdTag %s', $data['IdTag']) : "No IdTag"; + $this->RegisterVariableInteger($ident, sprintf($this->Translate('Consumption (%s)'), $idTag), [ 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' Wh' ]);