no message

This commit is contained in:
2025-11-28 07:09:06 +01:00
parent 4f1fabbb19
commit 4b10bd4df5

View File

@@ -8,10 +8,10 @@ class VGT_Sub extends IPSModule
{
parent::Create();
// Device-ID
// Konfig: Device-ID
$this->RegisterPropertyString("DeviceID", "");
// 6 editable values (response payload)
// 6 editable values
$this->RegisterVariableFloat("PowerProduction", "Power Production", "", 10);
$this->EnableAction("PowerProduction");
@@ -30,52 +30,50 @@ class VGT_Sub extends IPSModule
$this->RegisterVariableInteger("MaxSOC", "Max SOC", "", 60);
$this->EnableAction("MaxSOC");
// Remote control readonly values
// Remote-control incoming (readonly)
$this->RegisterVariableFloat("RC_PowerSetpoint", "RC Power Setpoint", "", 70);
$this->RegisterVariableString("RC_Strategy", "RC Strategy", "", 80);
// Attach to MQTT Client Splitter
// Parent MQTT Splitter
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
}
public function ApplyChanges()
{
parent::ApplyChanges();
// Reconnect parent
// reconnect parent
$this->ConnectParent('{F7A0DD2E-7684-95C0-64C2-D2A9DC47577B}');
$device = $this->ReadPropertyString("DeviceID");
// Required incoming topics
// subscribe to required topics
$topics = [
"feedback-request/" . $device,
"remote-control-request/" . $device
];
// Subscribe each topic using the CORRECT DataID
foreach ($topics as $t) {
$this->SendDataToParent(json_encode([
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}", // <- correct for subscribe
"Topic" => $t,
"Retain" => false
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}",
"PacketType" => 8, // SUBSCRIBE
"QualityOfService" => 0,
"Retain" => false,
"Topic" => $t
]));
}
}
public function RequestAction($Ident, $Value)
{
SetValue($this->GetIDForIdent($Ident), $Value);
}
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString);
// This format is correct for your MQTT client splitter:
// expected structure:
// { "Topic": "...", "Payload": "..." }
if (!isset($data->Topic) || !isset($data->Payload)) {
@@ -96,10 +94,9 @@ class VGT_Sub extends IPSModule
}
}
// ----------------------------------------------------------------------------
// FEEDBACK REQUEST → SEND STATE JSON
// ----------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Feedback Request Response
// --------------------------------------------------------------------------
private function HandleFeedbackRequest()
{
$response = [
@@ -116,10 +113,9 @@ class VGT_Sub extends IPSModule
$this->SendToMQTT($topic, json_encode($response));
}
// ----------------------------------------------------------------------------
// REMOTE CONTROL REQUEST → WRITE VALUES + RESPOND
// ----------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Remote-Control → write incoming values & respond
// --------------------------------------------------------------------------
private function HandleRemoteControlRequest(string $payload)
{
$data = json_decode($payload, true);
@@ -135,26 +131,26 @@ class VGT_Sub extends IPSModule
SetValue($this->GetIDForIdent("RC_Strategy"), $data["strategy"]);
}
// Respond back
// send back same JSON
$topic = "remote-control-response/" . $this->ReadPropertyString("DeviceID");
$this->SendToMQTT($topic, json_encode($data));
}
// ----------------------------------------------------------------------------
// MQTT PUBLISH (correct format for your splitter!)
// ----------------------------------------------------------------------------
// --------------------------------------------------------------------------
// FINAL MQTT PUBLISH FORMAT (correct for your splitter!)
// --------------------------------------------------------------------------
private function SendToMQTT(string $topic, string $payload)
{
$this->SendDataToParent(json_encode([
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}", // CORRECT!
"Topic" => $topic,
"Payload" => $payload,
"Retain" => false
"DataID" => "{043EA491-0325-4ADD-8FC2-A30C8EEB4D3F}",
"PacketType" => 3, // PUBLISH
"QualityOfService" => 0,
"Retain" => false,
"Topic" => $topic,
"Payload" => $payload
]));
}
public function GetConfigurationForm()
{
return json_encode([
@@ -169,4 +165,4 @@ class VGT_Sub extends IPSModule
}
}
?>
?>