no message
This commit is contained in:
@@ -3,19 +3,10 @@
|
|||||||
"name": "VGT_Sub",
|
"name": "VGT_Sub",
|
||||||
"type": 3,
|
"type": 3,
|
||||||
"vendor": "Belevo",
|
"vendor": "Belevo",
|
||||||
"aliases": [
|
"aliases": ["VGT MQTT Client"],
|
||||||
"VGT MQTT Client"
|
|
||||||
],
|
|
||||||
"prefix": "VGT",
|
"prefix": "VGT",
|
||||||
|
"parentRequirements": [],
|
||||||
"parentRequirements": [
|
|
||||||
"{F5F433EB-61AB-470F-8964-A6322A9B88F9}"
|
|
||||||
],
|
|
||||||
|
|
||||||
"childRequirements": [],
|
"childRequirements": [],
|
||||||
"implemented": [
|
"implemented": ["{018EF6B5-AB94-40C6-AA53-46943E824ACF}"],
|
||||||
"{018EF6B5-AB94-40C6-AA53-46943E824ACF}"
|
|
||||||
],
|
|
||||||
|
|
||||||
"version": "1.0"
|
"version": "1.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ class VGT_Sub extends IPSModule
|
|||||||
public function Create()
|
public function Create()
|
||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
$this->RegisterPropertyString('DeviceID', '');
|
$this->RegisterPropertyString('DeviceID', '');
|
||||||
|
|
||||||
// Status Variablen (bearbeitbar)
|
|
||||||
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10);
|
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10);
|
||||||
$this->EnableAction('PowerProduction');
|
$this->EnableAction('PowerProduction');
|
||||||
|
|
||||||
@@ -29,71 +27,37 @@ class VGT_Sub extends IPSModule
|
|||||||
$this->RegisterVariableFloat('MaxSoc', 'Max SoC', '', 15);
|
$this->RegisterVariableFloat('MaxSoc', 'Max SoC', '', 15);
|
||||||
$this->EnableAction('MaxSoc');
|
$this->EnableAction('MaxSoc');
|
||||||
|
|
||||||
// Remote-Control Variablen (readonly)
|
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 20);
|
||||||
$this->RegisterVariableInteger('PowerSetpoint', 'Power Setpoint', '', 30);
|
|
||||||
IPS_SetVariableCustomAction($this->GetIDForIdent('PowerSetpoint'), 0);
|
IPS_SetVariableCustomAction($this->GetIDForIdent('PowerSetpoint'), 0);
|
||||||
|
|
||||||
$this->RegisterVariableString('Strategy', 'Strategy', '', 31);
|
$this->RegisterVariableString('Strategy', 'Strategy', '', 21);
|
||||||
IPS_SetVariableCustomAction($this->GetIDForIdent('Strategy'), 0);
|
IPS_SetVariableCustomAction($this->GetIDForIdent('Strategy'), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ForwardData($JSONString)
|
||||||
{
|
|
||||||
parent::ApplyChanges();
|
|
||||||
|
|
||||||
// RICHTIGER Parent: Offizieller MQTT Client
|
|
||||||
$this->ConnectParent('{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}');
|
|
||||||
|
|
||||||
$this->SubscribeTopics();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function SubscribeTopics()
|
|
||||||
{
|
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
|
||||||
if ($device == '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$topics = [
|
|
||||||
"feedback-request/$device",
|
|
||||||
"remote-control-request/$device"
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($topics as $topic) {
|
|
||||||
|
|
||||||
$this->SendDebug("SUBSCRIBE", $topic, 0);
|
|
||||||
|
|
||||||
$this->SendDataToParent(json_encode([
|
|
||||||
"DataID" => "{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}",
|
|
||||||
"PacketType" => 8, // Subscribe
|
|
||||||
"Topic" => $topic,
|
|
||||||
"QoS" => 0
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ReceiveData($JSONString)
|
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
|
|
||||||
$topic = $data['Topic'] ?? '';
|
if (!isset($data['Topic']) || !isset($data['Payload'])) {
|
||||||
$payload = $data['Payload'] ?? '';
|
return '';
|
||||||
|
}
|
||||||
$this->SendDebug("RX TOPIC", $topic, 0);
|
|
||||||
$this->SendDebug("RX PAYLOAD", $payload, 0);
|
|
||||||
|
|
||||||
|
$topic = $data['Topic'];
|
||||||
|
$payload = $data['Payload'];
|
||||||
$device = $this->ReadPropertyString('DeviceID');
|
$device = $this->ReadPropertyString('DeviceID');
|
||||||
|
|
||||||
if ($topic === "feedback-request/$device") {
|
if ($topic === "feedback-request/$device") {
|
||||||
$this->HandleFeedbackRequest($device);
|
$this->handleFeedback($device);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($topic === "remote-control-request/$device") {
|
if ($topic === "remote-control-request/$device") {
|
||||||
$this->HandleRemoteControlRequest($device, $payload);
|
$this->handleRemote($device, $payload);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function HandleFeedbackRequest($device)
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleFeedback($device)
|
||||||
{
|
{
|
||||||
$response = [
|
$response = [
|
||||||
"power_production" => GetValue($this->GetIDForIdent('PowerProduction')),
|
"power_production" => GetValue($this->GetIDForIdent('PowerProduction')),
|
||||||
@@ -104,49 +68,33 @@ class VGT_Sub extends IPSModule
|
|||||||
"max_soc" => GetValue($this->GetIDForIdent('MaxSoc'))
|
"max_soc" => GetValue($this->GetIDForIdent('MaxSoc'))
|
||||||
];
|
];
|
||||||
|
|
||||||
$json = json_encode($response);
|
$this->publish("feedback-response/$device", json_encode($response));
|
||||||
$topic = "feedback-response/$device";
|
|
||||||
|
|
||||||
$this->SendDebug("TX FEEDBACK", $json, 0);
|
|
||||||
|
|
||||||
$this->SendDataToParent(json_encode([
|
|
||||||
"DataID" => "{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}",
|
|
||||||
"PacketType" => 3, // Publish
|
|
||||||
"Topic" => $topic,
|
|
||||||
"Payload" => $json,
|
|
||||||
"QoS" => 0,
|
|
||||||
"Retain" => false
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function HandleRemoteControlRequest($device, $payload)
|
private function handleRemote($device, $payload)
|
||||||
{
|
{
|
||||||
$json = @json_decode($payload, true);
|
$in = json_decode($payload, true);
|
||||||
if (!is_array($json)) {
|
if (!is_array($in)) {
|
||||||
$this->SendDebug("ERROR", "Ungültiges JSON empfangen!", 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json['power_setpoint'])) {
|
if (isset($in['power_setpoint'])) {
|
||||||
SetValue($this->GetIDForIdent('PowerSetpoint'), (int)$json['power_setpoint']);
|
SetValue($this->GetIDForIdent('PowerSetpoint'), (int)$in['power_setpoint']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json['strategy'])) {
|
if (isset($in['strategy'])) {
|
||||||
SetValueString($this->GetIDForIdent('Strategy'), (string)$json['strategy']);
|
SetValueString($this->GetIDForIdent('Strategy'), (string)$in['strategy']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$replyTopic = "remote-control-response/$device";
|
$this->publish("remote-control-response/$device", json_encode($in));
|
||||||
$replyPayload = json_encode($json);
|
}
|
||||||
|
|
||||||
$this->SendDebug("TX REMOTE", $replyPayload, 0);
|
|
||||||
|
|
||||||
|
private function publish($topic, $payload)
|
||||||
|
{
|
||||||
$this->SendDataToParent(json_encode([
|
$this->SendDataToParent(json_encode([
|
||||||
"DataID" => "{3CFF0FD9-A6AF-4A9A-8C41-62E71D93AF40}",
|
"DataID" => "{018EF6B5-AB94-40C6-AA53-46943E824ACF}",
|
||||||
"PacketType" => 3, // Publish
|
"Topic" => $topic,
|
||||||
"Topic" => $replyTopic,
|
"Payload" => $payload
|
||||||
"Payload" => $replyPayload,
|
|
||||||
"QoS" => 0,
|
|
||||||
"Retain" => false
|
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,4 +103,5 @@ class VGT_Sub extends IPSModule
|
|||||||
SetValue($this->GetIDForIdent($Ident), $Value);
|
SetValue($this->GetIDForIdent($Ident), $Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user