no message
This commit is contained in:
@@ -12,9 +12,7 @@ class VGT_Sub extends IPSModule
|
|||||||
|
|
||||||
$this->RegisterPropertyString('DeviceID', '');
|
$this->RegisterPropertyString('DeviceID', '');
|
||||||
|
|
||||||
/** -------------------------------------------
|
// Status Variablen (schreibbar)
|
||||||
* STATUS Variablen (schreibbar)
|
|
||||||
* ------------------------------------------*/
|
|
||||||
$this->RegisterVariableInteger('PowerProduction', 'Power Production', '', 10);
|
$this->RegisterVariableInteger('PowerProduction', 'Power Production', '', 10);
|
||||||
$this->EnableAction('PowerProduction');
|
$this->EnableAction('PowerProduction');
|
||||||
|
|
||||||
@@ -33,18 +31,12 @@ class VGT_Sub extends IPSModule
|
|||||||
$this->RegisterVariableInteger('MaxSOC', 'Max SOC', '', 15);
|
$this->RegisterVariableInteger('MaxSOC', 'Max SOC', '', 15);
|
||||||
$this->EnableAction('MaxSOC');
|
$this->EnableAction('MaxSOC');
|
||||||
|
|
||||||
/** -------------------------------------------
|
// Remote-control (read-only)
|
||||||
* REMOTE CONTROL Variablen (read-only)
|
|
||||||
* ------------------------------------------*/
|
|
||||||
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20);
|
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20);
|
||||||
$this->RegisterVariableString('Strategy', 'Strategy', '', 21);
|
$this->RegisterVariableString('Strategy', 'Strategy', '', 21);
|
||||||
|
|
||||||
// Debug
|
|
||||||
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 30);
|
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 30);
|
||||||
|
|
||||||
/** -------------------------------------------
|
// Feedback-Request (read-only)
|
||||||
* FEEDBACK REQUEST Variablen (read-only)
|
|
||||||
* ------------------------------------------*/
|
|
||||||
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,13 +44,13 @@ class VGT_Sub extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
// Parent registrieren
|
// Parent verbinden
|
||||||
$this->ConnectParent('{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}');
|
$this->ConnectParent('{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}');
|
||||||
|
|
||||||
// Subscribe erst ausführen, wenn Parent wirklich aktiv ist
|
// Subscribes erst, wenn Parent aktiv wird
|
||||||
$this->Subscribed = false;
|
$this->Subscribed = false;
|
||||||
|
|
||||||
// Statusänderungen anhören (Instanz + Parent)
|
// Statusänderungen überwachen
|
||||||
$this->RegisterMessage($this->InstanceID, IM_CHANGESTATUS);
|
$this->RegisterMessage($this->InstanceID, IM_CHANGESTATUS);
|
||||||
|
|
||||||
$parent = @IPS_GetInstance($this->InstanceID)['ConnectionID'] ?? 0;
|
$parent = @IPS_GetInstance($this->InstanceID)['ConnectionID'] ?? 0;
|
||||||
@@ -76,19 +68,17 @@ class VGT_Sub extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newStatus = $Data[0] ?? 0;
|
$new = $Data[0] ?? 0;
|
||||||
|
|
||||||
// Eigene Instanz aktiv
|
// Eigene Instanz aktiv
|
||||||
if ($SenderID === $this->InstanceID && $newStatus === IS_ACTIVE) {
|
if ($SenderID === $this->InstanceID && $new === IS_ACTIVE) {
|
||||||
$this->TrySubscribe();
|
$this->TrySubscribe();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent aktiv
|
// Parent aktiv
|
||||||
$parent = @IPS_GetInstance($this->InstanceID)['ConnectionID'] ?? 0;
|
$parent = @IPS_GetInstance($this->InstanceID)['ConnectionID'] ?? 0;
|
||||||
if ($parent > 0 && $SenderID === $parent && $newStatus === IS_ACTIVE) {
|
if ($SenderID === $parent && $new === IS_ACTIVE) {
|
||||||
$this->TrySubscribe();
|
$this->TrySubscribe();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +88,7 @@ class VGT_Sub extends IPSModule
|
|||||||
private function HasActiveParent(): bool
|
private function HasActiveParent(): bool
|
||||||
{
|
{
|
||||||
$parent = @IPS_GetInstance($this->InstanceID)['ConnectionID'] ?? 0;
|
$parent = @IPS_GetInstance($this->InstanceID)['ConnectionID'] ?? 0;
|
||||||
|
|
||||||
if ($parent === 0 || !IPS_InstanceExists($parent)) {
|
if ($parent === 0 || !IPS_InstanceExists($parent)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -105,20 +96,20 @@ class VGT_Sub extends IPSModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* Safe Sender
|
* Safe Sender – garantiert keine Fehler mehr
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
private function SafeSendToParent(array $packet)
|
private function SafeSendToParent(array $packet)
|
||||||
{
|
{
|
||||||
if (!$this->HasActiveParent()) {
|
if (!$this->HasActiveParent()) {
|
||||||
$this->SendDebug('MQTT', 'Parent not active → send skipped', 0);
|
$this->SendDebug("MQTT", "Parent not active – send skipped", 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@$this->SendDataToParent(json_encode($packet));
|
@ $this->SendDataToParent(json_encode($packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* Safe Subscribe
|
* Subscribe (safe)
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
private function TrySubscribe()
|
private function TrySubscribe()
|
||||||
{
|
{
|
||||||
@@ -137,38 +128,31 @@ class VGT_Sub extends IPSModule
|
|||||||
$this->Subscribe("remote-control-request/$device");
|
$this->Subscribe("remote-control-request/$device");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
private function Subscribe(string $topic)
|
||||||
* Subscribe
|
|
||||||
* ---------------------------------------------------------*/
|
|
||||||
private function Subscribe(string $topic): void
|
|
||||||
{
|
{
|
||||||
$packet = [
|
$this->SafeSendToParent([
|
||||||
'DataID' => '{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}',
|
'DataID' => '{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}',
|
||||||
'PacketType' => 8,
|
'PacketType' => 8,
|
||||||
'QualityOfService' => 0,
|
'QualityOfService' => 0,
|
||||||
'Retain' => false,
|
'Retain' => false,
|
||||||
'Topic' => $topic,
|
'Topic' => $topic,
|
||||||
'Payload' => ''
|
'Payload' => ''
|
||||||
];
|
]);
|
||||||
|
|
||||||
$this->SafeSendToParent($packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
* Publish
|
* Publish (safe)
|
||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
private function Publish(string $topic, string $payload): void
|
private function Publish(string $topic, string $payload)
|
||||||
{
|
{
|
||||||
$packet = [
|
$this->SafeSendToParent([
|
||||||
'DataID' => '{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}',
|
'DataID' => '{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}',
|
||||||
'PacketType' => 3,
|
'PacketType' => 3,
|
||||||
'QualityOfService' => 0,
|
'QualityOfService' => 0,
|
||||||
'Retain' => false,
|
'Retain' => false,
|
||||||
'Topic' => $topic,
|
'Topic' => $topic,
|
||||||
'Payload' => $payload
|
'Payload' => $payload
|
||||||
];
|
]);
|
||||||
|
|
||||||
$this->SafeSendToParent($packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------
|
/* ---------------------------------------------------------
|
||||||
@@ -210,7 +194,6 @@ class VGT_Sub extends IPSModule
|
|||||||
* ---------------------------------------------------------*/
|
* ---------------------------------------------------------*/
|
||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
// Beim ersten Paket: subscriben
|
|
||||||
$this->TrySubscribe();
|
$this->TrySubscribe();
|
||||||
|
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
@@ -221,24 +204,20 @@ class VGT_Sub extends IPSModule
|
|||||||
$topic = $data['Topic'] ?? '';
|
$topic = $data['Topic'] ?? '';
|
||||||
$payload = $data['Payload'] ?? '';
|
$payload = $data['Payload'] ?? '';
|
||||||
|
|
||||||
$this->SendDebug('MQTT', 'Receive: ' . $topic . ' → ' . $payload, 0);
|
$this->SendDebug('MQTT', "Receive: $topic => $payload", 0);
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
if ($device === '') {
|
if ($device === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** -------------------------------------------
|
/* --- Feedback Request --- */
|
||||||
* 1️⃣ FEEDBACK REQUEST
|
|
||||||
* ------------------------------------------*/
|
|
||||||
if ($topic === "feedback-request/$device") {
|
if ($topic === "feedback-request/$device") {
|
||||||
|
|
||||||
$this->SetValue('FeedbackRequestPayload', $payload);
|
$this->SetValue('FeedbackRequestPayload', $payload);
|
||||||
|
|
||||||
$json = json_decode($payload, true);
|
$json = json_decode($payload, true);
|
||||||
if (!is_array($json)) {
|
if (!is_array($json)) $json = [];
|
||||||
$json = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = array_merge($json, [
|
$response = array_merge($json, [
|
||||||
"power_production" => $this->GetValue('PowerProduction'),
|
"power_production" => $this->GetValue('PowerProduction'),
|
||||||
@@ -253,9 +232,7 @@ class VGT_Sub extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** -------------------------------------------
|
/* --- Remote Control Request --- */
|
||||||
* 2️⃣ REMOTE CONTROL REQUEST
|
|
||||||
* ------------------------------------------*/
|
|
||||||
if ($topic === "remote-control-request/$device") {
|
if ($topic === "remote-control-request/$device") {
|
||||||
|
|
||||||
$this->SetValue('RemoteControlPayload', $payload);
|
$this->SetValue('RemoteControlPayload', $payload);
|
||||||
@@ -265,7 +242,6 @@ class VGT_Sub extends IPSModule
|
|||||||
if (isset($json['power_setpoint'])) {
|
if (isset($json['power_setpoint'])) {
|
||||||
$this->SetValue('PowerSetpoint', (int)$json['power_setpoint']);
|
$this->SetValue('PowerSetpoint', (int)$json['power_setpoint']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json['strategy'])) {
|
if (isset($json['strategy'])) {
|
||||||
$this->SetValue('Strategy', (string)$json['strategy']);
|
$this->SetValue('Strategy', (string)$json['strategy']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user