no message
This commit is contained in:
+12
-21
@@ -48,8 +48,6 @@ class VGT_Sub extends IPSModule
|
|||||||
* FEEDBACK REQUEST Variablen (read-only)
|
* FEEDBACK REQUEST Variablen (read-only)
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
||||||
|
|
||||||
// WICHTIG: Kein ConnectParent mehr hier -> Modul ist nur Client/Device
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -57,9 +55,6 @@ class VGT_Sub extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
// Kein ConnectParent mehr -> Parent wird in der Konsole verknüpft
|
|
||||||
// (MQTT Server ODER MQTT Client Gateway)
|
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
if ($device === '') {
|
if ($device === '') {
|
||||||
return;
|
return;
|
||||||
@@ -80,10 +75,6 @@ class VGT_Sub extends IPSModule
|
|||||||
{
|
{
|
||||||
$this->SetValue($Ident, $Value);
|
$this->SetValue($Ident, $Value);
|
||||||
|
|
||||||
// Optional: Hier könntest du auch direkt publizieren,
|
|
||||||
// wenn eine Variable geändert wird.
|
|
||||||
// Beispiel (auskommentiert, nur als Vorlage):
|
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
if ($device !== '') {
|
if ($device !== '') {
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
@@ -105,7 +96,6 @@ class VGT_Sub extends IPSModule
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -114,6 +104,11 @@ class VGT_Sub extends IPSModule
|
|||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
private function Subscribe(string $topic): void
|
private function Subscribe(string $topic): void
|
||||||
{
|
{
|
||||||
|
if (!$this->HasActiveParent()) {
|
||||||
|
$this->SendDebug('MQTT', 'Subscribe ohne aktiven Parent: ' . $topic, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$packet = [
|
$packet = [
|
||||||
'PacketType' => 8, // SUBSCRIBE
|
'PacketType' => 8, // SUBSCRIBE
|
||||||
'QualityOfService' => 0,
|
'QualityOfService' => 0,
|
||||||
@@ -133,6 +128,11 @@ class VGT_Sub extends IPSModule
|
|||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
private function Publish(string $topic, string $payload): void
|
private function Publish(string $topic, string $payload): void
|
||||||
{
|
{
|
||||||
|
if (!$this->HasActiveParent()) {
|
||||||
|
$this->SendDebug('MQTT', 'Publish ohne aktiven Parent: ' . $topic, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$packet = [
|
$packet = [
|
||||||
'PacketType' => 3, // PUBLISH
|
'PacketType' => 3, // PUBLISH
|
||||||
'QualityOfService' => 0,
|
'QualityOfService' => 0,
|
||||||
@@ -160,6 +160,8 @@ class VGT_Sub extends IPSModule
|
|||||||
$topic = $data['Topic'] ?? '';
|
$topic = $data['Topic'] ?? '';
|
||||||
$payload = $data['Payload'] ?? '';
|
$payload = $data['Payload'] ?? '';
|
||||||
|
|
||||||
|
$this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0);
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
if ($device === '') {
|
if ($device === '') {
|
||||||
return;
|
return;
|
||||||
@@ -167,21 +169,16 @@ class VGT_Sub extends IPSModule
|
|||||||
|
|
||||||
/** -------------------------------------------
|
/** -------------------------------------------
|
||||||
* 1️⃣ FEEDBACK REQUEST
|
* 1️⃣ FEEDBACK REQUEST
|
||||||
* request: feedback-request/deviceId
|
|
||||||
* response: feedback-response/deviceId
|
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
if ($topic === "feedback-request/$device") {
|
if ($topic === "feedback-request/$device") {
|
||||||
|
|
||||||
// 1. Payload speichern
|
|
||||||
$this->SetValue('FeedbackRequestPayload', $payload);
|
$this->SetValue('FeedbackRequestPayload', $payload);
|
||||||
|
|
||||||
// 2. JSON interpretieren (falls vorhanden)
|
|
||||||
$json = json_decode($payload, true);
|
$json = json_decode($payload, true);
|
||||||
if (!is_array($json)) {
|
if (!is_array($json)) {
|
||||||
$json = [];
|
$json = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Antwort-Mix erstellen (Payload + Status)
|
|
||||||
$response = array_merge($json, [
|
$response = array_merge($json, [
|
||||||
"power_production" => $this->GetValue('PowerProduction'),
|
"power_production" => $this->GetValue('PowerProduction'),
|
||||||
"is_ready" => $this->GetValue('IsReady'),
|
"is_ready" => $this->GetValue('IsReady'),
|
||||||
@@ -191,20 +188,15 @@ class VGT_Sub extends IPSModule
|
|||||||
"max_soc" => $this->GetValue('MaxSOC')
|
"max_soc" => $this->GetValue('MaxSOC')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 4. Antwort senden
|
|
||||||
$this->Publish("feedback-response/$device", json_encode($response));
|
$this->Publish("feedback-response/$device", json_encode($response));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------------------------
|
/** -------------------------------------------
|
||||||
* 2️⃣ REMOTE CONTROL REQUEST
|
* 2️⃣ REMOTE CONTROL REQUEST
|
||||||
* request: remote-control-request/deviceId
|
|
||||||
* response: remote-control-response/deviceId
|
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
if ($topic === "remote-control-request/$device") {
|
if ($topic === "remote-control-request/$device") {
|
||||||
|
|
||||||
// 1. Payload speichern
|
|
||||||
$this->SetValue('RemoteControlPayload', $payload);
|
$this->SetValue('RemoteControlPayload', $payload);
|
||||||
|
|
||||||
$json = json_decode($payload, true);
|
$json = json_decode($payload, true);
|
||||||
@@ -219,7 +211,6 @@ class VGT_Sub extends IPSModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Echo Response
|
|
||||||
$this->Publish("remote-control-response/$device", $payload);
|
$this->Publish("remote-control-response/$device", $payload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user