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