Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions OCPP Charging Point/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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']);
Expand All @@ -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);
Expand All @@ -97,6 +97,8 @@ public function ReceiveData($JSONString)
default:
break;
}

return $result;
}

public function RequestAction($Ident, $Value)
Expand Down Expand Up @@ -447,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']), [
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions OCPP Splitter/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,26 @@ 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']);
$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'
]);
$this->SetValue($ident, $this->GetValue($ident) + $data['Consumption']);
}

/**
* OCPP-j-1.6-specification Page 13
* Input[1] is the MessageID
Expand Down
Loading