no message
This commit is contained in:
+38
-22
@@ -38,24 +38,27 @@ class MQTTBatterySDL extends IPSModule
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
$suffix = $this->ReadPropertyString('TopicSuffix');
|
$suffix = $this->ReadPropertyString('TopicSuffix');
|
||||||
|
|
||||||
if ($suffix == '') {
|
if ($suffix == '') {
|
||||||
$this->SetStatus(IS_INACTIVE);
|
$this->SetStatus(IS_INACTIVE);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
$filter = '.*"Topic":"(feedback-request|remote-control-request)\/' . preg_quote($suffix, '/') . '".*';
|
|
||||||
|
|
||||||
$this->SetReceiveDataFilter($filter);
|
|
||||||
|
|
||||||
$this->SetStatus(IS_ACTIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filter =
|
||||||
|
'.*"Topic":"(feedback-request|remote-control-request)\/'
|
||||||
|
. preg_quote($suffix, '/')
|
||||||
|
. '".*';
|
||||||
|
|
||||||
|
$this->SetReceiveDataFilter($filter);
|
||||||
|
|
||||||
|
$this->SetStatus(IS_ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value)
|
||||||
{
|
{
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
@@ -340,19 +343,34 @@ public function ReceiveData($JSONString)
|
|||||||
{
|
{
|
||||||
$data = json_decode($JSONString, true);
|
$data = json_decode($JSONString, true);
|
||||||
|
|
||||||
$this->SendDebug('ReceiveData', $JSONString, 0);
|
|
||||||
|
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topic = $data['Topic'] ?? '';
|
if (($data['PacketType'] ?? 0) != 3) {
|
||||||
$payload = $data['Payload'] ?? '';
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$suffix = $this->ReadPropertyString('TopicSuffix');
|
if (!isset($data['Topic'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$topic = $data['Topic'];
|
||||||
|
|
||||||
|
if (strpos($topic, 'feedback-response/') === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($topic, 'remote-control-response/') === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SendDebug('ReceiveData', $JSONString, 0);
|
||||||
|
|
||||||
|
$payload = $data['Payload'] ?? '';
|
||||||
|
$suffix = $this->ReadPropertyString('TopicSuffix');
|
||||||
|
|
||||||
if ($topic === 'feedback-request/' . $suffix) {
|
if ($topic === 'feedback-request/' . $suffix) {
|
||||||
|
|
||||||
$json = $this->BuildReadResponse();
|
$json = $this->BuildReadResponse();
|
||||||
|
|
||||||
$this->PublishMQTT(
|
$this->PublishMQTT(
|
||||||
@@ -364,7 +382,6 @@ public function ReceiveData($JSONString)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($topic === 'remote-control-request/' . $suffix) {
|
if ($topic === 'remote-control-request/' . $suffix) {
|
||||||
|
|
||||||
$json = $this->HandleRemoteControlJSON($payload);
|
$json = $this->HandleRemoteControlJSON($payload);
|
||||||
|
|
||||||
if ($json !== null) {
|
if ($json !== null) {
|
||||||
@@ -379,7 +396,6 @@ public function ReceiveData($JSONString)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function PublishMQTT(string $topic, string $payload)
|
private function PublishMQTT(string $topic, string $payload)
|
||||||
{
|
{
|
||||||
$this->SendDebug(
|
$this->SendDebug(
|
||||||
|
|||||||
Reference in New Issue
Block a user