no message
This commit is contained in:
@@ -41,10 +41,16 @@ class Int_VGT extends IPSModule
|
|||||||
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20);
|
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20);
|
||||||
$this->RegisterVariableString('Strategy', 'Strategy', '', 21);
|
$this->RegisterVariableString('Strategy', 'Strategy', '', 21);
|
||||||
|
|
||||||
// Für Debugging
|
// Debug
|
||||||
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 30);
|
$this->RegisterVariableString('RemoteControlPayload', 'Remote Control Payload', '', 30);
|
||||||
|
|
||||||
|
|
||||||
|
/** -------------------------------------------
|
||||||
|
* FEEDBACK REQUEST Variablen (read-only)
|
||||||
|
* ------------------------------------------*/
|
||||||
|
$this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40);
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------------------------
|
/** -------------------------------------------
|
||||||
* MQTT SERVER verbinden
|
* MQTT SERVER verbinden
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
@@ -56,18 +62,18 @@ class Int_VGT extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
// Sicherheitshalber erneut verbinden
|
|
||||||
$this->ConnectParent('{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}');
|
$this->ConnectParent('{C6D2AEB3-6E1F-4B2E-8E69-3A1A00246850}');
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
if ($device === '') {
|
if ($device === '') {
|
||||||
$this->SendDebug('ApplyChanges', 'Keine DeviceID gesetzt', 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscriptions setzen
|
// READ
|
||||||
$this->Subscribe("feedback-request/$device");
|
$this->Subscribe("feedback-request/$device");
|
||||||
$this->Subscribe("remote-control-response/$device");
|
|
||||||
|
// WRITE
|
||||||
|
$this->Subscribe("remote-control-request/$device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,10 +91,8 @@ class Int_VGT extends IPSModule
|
|||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
private function Subscribe(string $topic): void
|
private function Subscribe(string $topic): void
|
||||||
{
|
{
|
||||||
$this->SendDebug('Subscribe', $topic, 0);
|
|
||||||
|
|
||||||
$packet = [
|
$packet = [
|
||||||
'PacketType' => 8, // SUBSCRIBE
|
'PacketType' => 8,
|
||||||
'QualityOfService' => 0,
|
'QualityOfService' => 0,
|
||||||
'Retain' => false,
|
'Retain' => false,
|
||||||
'Topic' => $topic,
|
'Topic' => $topic,
|
||||||
@@ -106,10 +110,8 @@ class Int_VGT extends IPSModule
|
|||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
private function Publish(string $topic, string $payload): void
|
private function Publish(string $topic, string $payload): void
|
||||||
{
|
{
|
||||||
$this->SendDebug('Publish', "Topic: $topic Payload: $payload", 0);
|
|
||||||
|
|
||||||
$packet = [
|
$packet = [
|
||||||
'PacketType' => 3, // PUBLISH
|
'PacketType' => 3,
|
||||||
'QualityOfService' => 0,
|
'QualityOfService' => 0,
|
||||||
'Retain' => false,
|
'Retain' => false,
|
||||||
'Topic' => $topic,
|
'Topic' => $topic,
|
||||||
@@ -128,42 +130,54 @@ class Int_VGT extends IPSModule
|
|||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$topic = $data['Topic'] ?? '';
|
$topic = $data['Topic'] ?? '';
|
||||||
$payload = $data['Payload'] ?? '';
|
$payload = $data['Payload'] ?? '';
|
||||||
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
|
|
||||||
$this->SendDebug('Receive', "Topic: $topic Payload: $payload", 0);
|
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------------------------
|
/** -------------------------------------------
|
||||||
* 1️⃣ FEEDBACK REQUEST → Statusvariablen senden
|
* 1️⃣ FEEDBACK REQUEST
|
||||||
|
* request: feedback-request/deviceId
|
||||||
|
* response: feedback-response/deviceId
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
if ($topic === "feedback-request/$device") {
|
if ($topic === "feedback-request/$device") {
|
||||||
|
|
||||||
$response = [
|
// 1. Payload speichern
|
||||||
|
$this->SetValue('FeedbackRequestPayload', $payload);
|
||||||
|
|
||||||
|
// 2. JSON interpretieren (falls vorhanden)
|
||||||
|
$json = json_decode($payload, true);
|
||||||
|
if (!is_array($json)) {
|
||||||
|
$json = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Antwort-Mix erstellen (Payload + Status)
|
||||||
|
$response = array_merge($json, [
|
||||||
"power_production" => $this->GetValue('PowerProduction'),
|
"power_production" => $this->GetValue('PowerProduction'),
|
||||||
"is_ready" => $this->GetValue('IsReady'),
|
"is_ready" => $this->GetValue('IsReady'),
|
||||||
"is_running" => $this->GetValue('IsRunning'),
|
"is_running" => $this->GetValue('IsRunning'),
|
||||||
"state_of_charge" => $this->GetValue('StateOfCharge'),
|
"state_of_charge" => $this->GetValue('StateOfCharge'),
|
||||||
"min_soc" => $this->GetValue('MinSOC'),
|
"min_soc" => $this->GetValue('MinSOC'),
|
||||||
"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 → write-only Variablen
|
* 2️⃣ REMOTE CONTROL REQUEST
|
||||||
|
* request: remote-control-request/deviceId
|
||||||
|
* response: remote-control-response/deviceId
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
if ($topic === "remote-control-response/$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);
|
||||||
@@ -178,16 +192,9 @@ class Int_VGT extends IPSModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Echo Response
|
||||||
|
$this->Publish("remote-control-response/$device", $payload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** -------------------------------------------
|
|
||||||
* OPTIONAL CALLBACK
|
|
||||||
* ------------------------------------------*/
|
|
||||||
protected function HandleRemoteControl(string $payload): void
|
|
||||||
{
|
|
||||||
$this->SendDebug('RemoteControl', $payload, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user