no message
This commit is contained in:
+64
-4
@@ -152,13 +152,28 @@ class VGT_Sub extends IPSModule
|
|||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
// äußere Hülle vom MQTT-Client
|
||||||
if (!is_array($data)) {
|
$data = json_decode($JSONString);
|
||||||
|
if ($data === null) {
|
||||||
|
$this->SendDebug('MQTT', 'Ungültiges JSON: ' . $JSONString, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topic = $data['Topic'] ?? '';
|
// aktuelles MQTT-Client-Format: Topic/Payload stecken in Buffer
|
||||||
$payload = $data['Payload'] ?? '';
|
if (isset($data->Buffer)) {
|
||||||
|
$buffer = json_decode($data->Buffer, true);
|
||||||
|
} else {
|
||||||
|
// Fallback auf direkte Struktur
|
||||||
|
$buffer = json_decode($JSONString, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($buffer)) {
|
||||||
|
$this->SendDebug('MQTT', 'Buffer ist kein Array: ' . print_r($buffer, true), 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$topic = $buffer['Topic'] ?? '';
|
||||||
|
$payload = $buffer['Payload'] ?? '';
|
||||||
|
|
||||||
$this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0);
|
$this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0);
|
||||||
|
|
||||||
@@ -167,6 +182,51 @@ class VGT_Sub extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1) feedback-request/<device>
|
||||||
|
if ($topic === "feedback-request/$device") {
|
||||||
|
|
||||||
|
$this->SetValue('FeedbackRequestPayload', $payload);
|
||||||
|
|
||||||
|
$json = json_decode($payload, true);
|
||||||
|
if (!is_array($json)) {
|
||||||
|
$json = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = array_merge($json, [
|
||||||
|
"power_production" => $this->GetValue('PowerProduction'),
|
||||||
|
"is_ready" => $this->GetValue('IsReady'),
|
||||||
|
"is_running" => $this->GetValue('IsRunning'),
|
||||||
|
"state_of_charge" => $this->GetValue('StateOfCharge'),
|
||||||
|
"min_soc" => $this->GetValue('MinSOC'),
|
||||||
|
"max_soc" => $this->GetValue('MaxSOC')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->Publish("feedback-response/$device", json_encode($response));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) remote-control-request/<device>
|
||||||
|
if ($topic === "remote-control-request/$device") {
|
||||||
|
|
||||||
|
$this->SetValue('RemoteControlPayload', $payload);
|
||||||
|
|
||||||
|
$json = json_decode($payload, true);
|
||||||
|
if (is_array($json)) {
|
||||||
|
|
||||||
|
if (array_key_exists('power_setpoint', $json)) {
|
||||||
|
$this->SetValue('PowerSetpoint', (int)$json['power_setpoint']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('strategy', $json)) {
|
||||||
|
$this->SetValue('Strategy', (string)$json['strategy']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->Publish("remote-control-response/$device", $payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** -------------------------------------------
|
/** -------------------------------------------
|
||||||
* 1️⃣ FEEDBACK REQUEST
|
* 1️⃣ FEEDBACK REQUEST
|
||||||
* ------------------------------------------*/
|
* ------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user