no message
This commit is contained in:
@@ -42,7 +42,16 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
$this->SetReceiveDataFilter('.*');
|
$suffix = $this->ReadPropertyString('TopicSuffix');
|
||||||
|
|
||||||
|
if ($suffix == '') {
|
||||||
|
$this->SetStatus(IS_INACTIVE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = '.*"Topic":"(feedback-request|remote-control-request)\/' . preg_quote($suffix, '/') . '".*';
|
||||||
|
|
||||||
|
$this->SetReceiveDataFilter($filter);
|
||||||
|
|
||||||
$this->SetStatus(IS_ACTIVE);
|
$this->SetStatus(IS_ACTIVE);
|
||||||
}
|
}
|
||||||
@@ -327,9 +336,44 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ReceiveData($JSONString)
|
public function ReceiveData($JSONString)
|
||||||
{
|
{
|
||||||
IPS_LogMessage('MQTTBatterySDL', $JSONString);
|
$data = json_decode($JSONString, true);
|
||||||
|
|
||||||
|
$this->SendDebug('ReceiveData', $JSONString, 0);
|
||||||
|
|
||||||
|
if (!is_array($data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$topic = $data['Topic'] ?? '';
|
||||||
|
$payload = $data['Payload'] ?? '';
|
||||||
|
|
||||||
|
$suffix = $this->ReadPropertyString('TopicSuffix');
|
||||||
|
|
||||||
|
if ($topic === 'feedback-request/' . $suffix) {
|
||||||
|
$json = $this->BuildReadResponse();
|
||||||
|
|
||||||
|
$this->PublishMQTT(
|
||||||
|
'feedback-response/' . $suffix,
|
||||||
|
$json
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($topic === 'remote-control-request/' . $suffix) {
|
||||||
|
$json = $this->HandleRemoteControlJSON($payload);
|
||||||
|
|
||||||
|
if ($json !== null) {
|
||||||
|
$this->PublishMQTT(
|
||||||
|
'remote-control-response/' . $suffix,
|
||||||
|
$json
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function IsValidVariable(int $id)
|
private function IsValidVariable(int $id)
|
||||||
|
|||||||
Reference in New Issue
Block a user