no message
This commit is contained in:
@@ -10,9 +10,9 @@ class VGT_Sub extends IPSModule
|
||||
|
||||
$this->RegisterPropertyString('DeviceID', '');
|
||||
|
||||
/** -------------------------------------------
|
||||
* STATUS Variablen (schreibbar)
|
||||
* ------------------------------------------*/
|
||||
/** -------------------------
|
||||
* STATUS Variablen
|
||||
* ------------------------- */
|
||||
$this->RegisterVariableInteger('PowerProduction', 'Power Production', '', 10);
|
||||
$this->EnableAction('PowerProduction');
|
||||
|
||||
@@ -31,33 +31,34 @@ class VGT_Sub extends IPSModule
|
||||
$this->RegisterVariableInteger('MaxSOC', 'Max SOC', '', 15);
|
||||
$this->EnableAction('MaxSOC');
|
||||
|
||||
/** -------------------------------------------
|
||||
* REMOTE CONTROL (readonly)
|
||||
* ------------------------------------------*/
|
||||
/** -------------------------
|
||||
* REMOTE CONTROL
|
||||
* ------------------------- */
|
||||
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20);
|
||||
$this->RegisterVariableString('Strategy', 'Strategy', '', 21);
|
||||
|
||||
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 30);
|
||||
|
||||
/** -------------------------------------------
|
||||
* FEEDBACK REQUEST (readonly)
|
||||
* ------------------------------------------*/
|
||||
/** -------------------------
|
||||
* FEEDBACK REQUEST
|
||||
* ------------------------- */
|
||||
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
||||
}
|
||||
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
$this->ConnectParent('{DBDA3967-E416-4354-A5C9-2FB9E7E2F5B3}'); // MQTT Client Gateway
|
||||
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}'); // Dein Splitter
|
||||
}
|
||||
|
||||
/** ----------------------------------------------------------
|
||||
* REQUEST ACTION → Statusvariablen schreibbar machen
|
||||
* REQUEST ACTION
|
||||
* ----------------------------------------------------------*/
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
$this->SetValue($Ident, $Value);
|
||||
$device = $this->ReadPropertyString('DeviceID');
|
||||
|
||||
$device = $this->ReadPropertyString('DeviceID');
|
||||
if ($device === '') {
|
||||
return;
|
||||
}
|
||||
@@ -85,25 +86,22 @@ class VGT_Sub extends IPSModule
|
||||
}
|
||||
|
||||
/** ----------------------------------------------------------
|
||||
* SUBSCRIBE (nur bei „MQTT_CONNECTED“)
|
||||
* SUBSCRIBE
|
||||
* ----------------------------------------------------------*/
|
||||
private function Subscribe(string $topic): void
|
||||
{
|
||||
if (!$this->HasActiveParent()) {
|
||||
$this->SendDebug('MQTT', 'Subscribe ohne aktiven Parent: ' . $topic, 0);
|
||||
$this->SendDebug("MQTT", "Parent offline – subscribe skipped: $topic", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->SendDebug('MQTT', 'Subscribe → ' . $topic, 0);
|
||||
|
||||
$this->SendDataToParent(json_encode([
|
||||
'DataID' => '{7F2A28E2-ABFA-4C77-B43F-042E1ED9F2D2}',
|
||||
'PacketType' => 8, // SUBSCRIBE
|
||||
'QualityOfService' => 0,
|
||||
'Retain' => false,
|
||||
'Topic' => $topic,
|
||||
'Payload' => ''
|
||||
'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}', // DataID deines Splitters → SUBSCRIBE
|
||||
'Type' => 'SUBSCRIBE',
|
||||
'Topic' => $topic
|
||||
]));
|
||||
|
||||
$this->SendDebug('MQTT', "Subscribed: $topic", 0);
|
||||
}
|
||||
|
||||
/** ----------------------------------------------------------
|
||||
@@ -112,20 +110,18 @@ class VGT_Sub extends IPSModule
|
||||
private function Publish(string $topic, string $payload): void
|
||||
{
|
||||
if (!$this->HasActiveParent()) {
|
||||
$this->SendDebug('MQTT', 'Publish ohne aktiven Parent: ' . $topic, 0);
|
||||
$this->SendDebug("MQTT", "Parent offline – publish skipped: $topic", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->SendDebug('MQTT', 'Publish → Topic=' . $topic . ' Payload=' . $payload, 0);
|
||||
|
||||
$this->SendDataToParent(json_encode([
|
||||
'DataID' => '{7F2A28E2-ABFA-4C77-B43F-042E1ED9F2D2}',
|
||||
'PacketType' => 3,
|
||||
'QualityOfService' => 0,
|
||||
'Retain' => false,
|
||||
'DataID' => '{A1B5C433-4F17-462D-AD71-383F5BBE4F5A}', // DataID deines Splitters → PUBLISH
|
||||
'Type' => 'PUBLISH',
|
||||
'Topic' => $topic,
|
||||
'Payload' => $payload
|
||||
]));
|
||||
|
||||
$this->SendDebug('MQTT', "Publish → $topic : $payload", 0);
|
||||
}
|
||||
|
||||
/** ----------------------------------------------------------
|
||||
@@ -139,11 +135,12 @@ class VGT_Sub extends IPSModule
|
||||
return;
|
||||
}
|
||||
|
||||
// --- MQTT CONNECTED EVENT ---
|
||||
if (isset($data['Event']) && $data['Event'] === 'MQTT_CONNECTED') {
|
||||
$this->SendDebug('MQTT', 'MQTT_CONNECTED → re-subscribing…', 0);
|
||||
/** --- MQTT CONNECTED EVENT vom Splitter --- */
|
||||
if (($data['Type'] ?? '') === 'MQTT_CONNECTED') {
|
||||
$this->SendDebug("MQTT", "Splitter connected → re-subscribing", 0);
|
||||
|
||||
$device = $this->ReadPropertyString('DeviceID');
|
||||
|
||||
if ($device !== '') {
|
||||
$this->Subscribe("feedback-request/$device");
|
||||
$this->Subscribe("remote-control-request/$device");
|
||||
@@ -151,19 +148,24 @@ class VGT_Sub extends IPSModule
|
||||
return;
|
||||
}
|
||||
|
||||
// --- Normale MQTT Messages ---
|
||||
/** --- Normale MQTT Daten vom Splitter --- */
|
||||
if (($data['Type'] ?? '') !== 'MESSAGE') {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = $data['Topic'] ?? '';
|
||||
$payload = $data['Payload'] ?? '';
|
||||
|
||||
$this->SendDebug('MQTT', "Receive: Topic=$topic Payload=$payload", 0);
|
||||
|
||||
$device = $this->ReadPropertyString('DeviceID');
|
||||
|
||||
$this->SendDebug("MQTT", "RX → $topic : $payload", 0);
|
||||
|
||||
if ($device === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
/** -------------------------------------------
|
||||
* 1️⃣ FEEDBACK REQUEST
|
||||
* FEEDBACK REQUEST
|
||||
* ------------------------------------------*/
|
||||
if ($topic === "feedback-request/$device") {
|
||||
|
||||
@@ -188,7 +190,7 @@ class VGT_Sub extends IPSModule
|
||||
}
|
||||
|
||||
/** -------------------------------------------
|
||||
* 2️⃣ REMOTE CONTROL REQUEST
|
||||
* REMOTE CONTROL REQUEST
|
||||
* ------------------------------------------*/
|
||||
if ($topic === "remote-control-request/$device") {
|
||||
|
||||
@@ -197,18 +199,15 @@ class VGT_Sub extends IPSModule
|
||||
$json = json_decode($payload, true);
|
||||
|
||||
if (is_array($json)) {
|
||||
if (array_key_exists('power_setpoint', $json)) {
|
||||
$this->SetValue('PowerSetpoint', (int) $json['power_setpoint']);
|
||||
if (isset($json['power_setpoint'])) {
|
||||
$this->SetValue('PowerSetpoint', (int)$json['power_setpoint']);
|
||||
}
|
||||
if (array_key_exists('strategy', $json)) {
|
||||
$this->SetValue('Strategy', (string) $json['strategy']);
|
||||
if (isset($json['strategy'])) {
|
||||
$this->SetValue('Strategy', (string)$json['strategy']);
|
||||
}
|
||||
}
|
||||
|
||||
// Antwort spiegeln
|
||||
$this->Publish("remote-control-response/$device", $payload);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user