Update Websocket und weiteres.
This commit is contained in:
+33
-10
@@ -13,6 +13,7 @@ class OCPP_Server extends IPSModule
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
$this->RegisterPropertyString('TransportMode', 'webhook_spike');
|
||||
$this->RegisterPropertyBoolean('EnableWebhook', true);
|
||||
$this->RegisterPropertyString('HookPath', '/hook/ocpp');
|
||||
$this->RegisterPropertyInteger('DefaultTargetInstance', 0);
|
||||
@@ -30,6 +31,9 @@ class OCPP_Server extends IPSModule
|
||||
$this->RegisterVariableInteger('ConnectionCount', 'ConnectionCount', '', 30);
|
||||
$this->RegisterVariableInteger('LastMessageTime', 'LastMessageTime', '', 31);
|
||||
$this->RegisterVariableInteger('OutboundQueueCount', 'OutboundQueueCount', '', 32);
|
||||
$this->RegisterVariableString('TransportModeStatus', 'TransportModeStatus', '', 33);
|
||||
$this->RegisterVariableBoolean('OutboundPushSupported', 'OutboundPushSupported', '~Switch', 34);
|
||||
$this->RegisterVariableString('TransportWarning', 'TransportWarning', '', 35);
|
||||
$this->RegisterVariableString('WebSocketSupportStatus', 'WebSocketSupportStatus', '', 40);
|
||||
$this->RegisterVariableString('LetzteMeldung', 'LetzteMeldung', '', 41);
|
||||
$this->RegisterVariableInteger('LetzteMeldungZeit', 'LetzteMeldungZeit', '', 42);
|
||||
@@ -46,11 +50,15 @@ class OCPP_Server extends IPSModule
|
||||
parent::ApplyChanges();
|
||||
|
||||
$this->SetTimerInterval('Timer_TransportWatchdog', max(5, $this->ReadPropertyInteger('HeartbeatSeconds')) * 1000);
|
||||
$summary = WebSocketEndpoint::supportSummary(method_exists($this, 'RegisterHook'), $this->ReadPropertyString('HookPath'));
|
||||
$transportMode = $this->ReadPropertyString('TransportMode');
|
||||
$summary = WebSocketEndpoint::supportSummary(method_exists($this, 'RegisterHook'), $this->ReadPropertyString('HookPath'), $transportMode);
|
||||
$this->SetValue('WebSocketSupportStatus', $summary['status'] . ': ' . $summary['detail']);
|
||||
$this->SetValue('TransportModeStatus', $transportMode);
|
||||
$this->SetValue('OutboundPushSupported', $transportMode !== 'webhook_spike');
|
||||
$this->SetValue('TransportWarning', $summary['warning']);
|
||||
$this->SetSummary($summary['status']);
|
||||
|
||||
if ($this->ReadPropertyBoolean('EnableWebhook')) {
|
||||
if ($transportMode === 'webhook_spike' && $this->ReadPropertyBoolean('EnableWebhook')) {
|
||||
$this->tryRegisterHook();
|
||||
}
|
||||
|
||||
@@ -74,12 +82,13 @@ class OCPP_Server extends IPSModule
|
||||
break;
|
||||
|
||||
case 'RouteInboundFrame':
|
||||
$this->RouteInboundFrame((string)$Value);
|
||||
break;
|
||||
return $this->RouteInboundFrame((string)$Value);
|
||||
|
||||
case 'ReceiveExternalFrame':
|
||||
return $this->RouteInboundFrame((string)$Value);
|
||||
|
||||
case 'DequeueOutboundFrame':
|
||||
$this->DequeueOutboundFrame((string)$Value);
|
||||
break;
|
||||
return $this->DequeueOutboundFrame((string)$Value);
|
||||
|
||||
case 'TransportWatchdog':
|
||||
$this->TransportWatchdog();
|
||||
@@ -101,6 +110,16 @@ class OCPP_Server extends IPSModule
|
||||
|
||||
protected function ProcessHookData($JSONString = '')
|
||||
{
|
||||
if ($this->ReadPropertyString('TransportMode') !== 'webhook_spike') {
|
||||
header('HTTP/1.1 501 Not Implemented');
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'status' => 'rejected',
|
||||
'reason' => 'ProcessHookData ist nur fuer den WebHook-Spike aktiv. Produktiver OCPP-Betrieb braucht einen echten WebSocket-Transport.'
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$raw = WebSocketEndpoint::readRawBody();
|
||||
if ($raw === '' && is_string($JSONString)) {
|
||||
$raw = $JSONString;
|
||||
@@ -141,7 +160,11 @@ class OCPP_Server extends IPSModule
|
||||
$this->SetValue('LastOutboundFrame', $frame);
|
||||
$this->SetValue('LastMessageTime', time());
|
||||
$this->enqueueOutboundFrame($chargePointId, $frame);
|
||||
$this->setMessage('Outbound Frame fuer ' . ($chargePointId === '' ? 'unbekannt' : $chargePointId) . ' gepuffert.');
|
||||
if ($this->ReadPropertyString('TransportMode') === 'webhook_spike') {
|
||||
$this->setMessage('Outbound Frame gepuffert, aber WebHook-Spike kann keinen echten Async-Push garantieren.');
|
||||
return;
|
||||
}
|
||||
$this->setMessage('Outbound Frame fuer echten WebSocket-Transport gepuffert: ' . ($chargePointId === '' ? 'unbekannt' : $chargePointId));
|
||||
}
|
||||
|
||||
public function RouteInboundFrame(string $json): string
|
||||
@@ -250,7 +273,7 @@ class OCPP_Server extends IPSModule
|
||||
{
|
||||
$last = (int)$this->GetValue('LastMessageTime');
|
||||
if ($last === 0) {
|
||||
$this->SetValue('TransportStatus', 'Wartet auf OCPP Verbindung');
|
||||
$this->SetValue('TransportStatus', $this->ReadPropertyString('TransportMode') === 'webhook_spike' ? 'WebHook-Spike wartet' : 'Wartet auf WebSocket Verbindung');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -261,7 +284,7 @@ class OCPP_Server extends IPSModule
|
||||
return;
|
||||
}
|
||||
|
||||
$this->SetValue('TransportStatus', 'Aktiv/Scaffold');
|
||||
$this->SetValue('TransportStatus', $this->ReadPropertyString('TransportMode') === 'webhook_spike' ? 'Aktiv/WebHook-Spike' : 'Aktiv/WebSocket-Transport');
|
||||
}
|
||||
|
||||
private function tryRegisterHook(): void
|
||||
@@ -270,7 +293,7 @@ class OCPP_Server extends IPSModule
|
||||
if (method_exists($this, 'RegisterHook')) {
|
||||
try {
|
||||
$this->RegisterHook($hook);
|
||||
$this->SetValue('WebSocketSupportStatus', 'RegisterHook aufgerufen fuer ' . $hook . '. WebSocket-Dauerbetrieb noch testen.');
|
||||
$this->SetValue('WebSocketSupportStatus', 'RegisterHook aufgerufen fuer ' . $hook . '. Nur WebHook-Spike, kein produktiver OCPP-WebSocket-Dauerbetrieb.');
|
||||
$this->setMessage('Webhook registriert: ' . $hook);
|
||||
return;
|
||||
} catch (Throwable $e) {
|
||||
|
||||
Reference in New Issue
Block a user