From 9a24bead8191acd73c6843bf67e6580ad3dec8ed Mon Sep 17 00:00:00 2001 From: Tcharp38 Date: Fri, 4 Oct 2024 17:12:42 +0200 Subject: [PATCH] cmd fixes --- core/class/Abeille.class.php | 6 ++++-- core/class/AbeilleCmdProcess.class.php | 30 +++++++++++++------------- core/class/AbeilleCmdQueue.class.php | 21 ++++++++++-------- core/php/AbeilleCliToQueue.php | 2 +- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/core/class/Abeille.class.php b/core/class/Abeille.class.php index ede9cf78d0..fa71a1316e 100644 --- a/core/class/Abeille.class.php +++ b/core/class/Abeille.class.php @@ -2307,11 +2307,12 @@ public static function publishMosquitto($queueId, $priority, $topic, $payload) { } $msg = array(); + $msg['priority'] = $priority; $msg['topic'] = $topic; $msg['payload'] = $payload; $msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES); - if (msg_send($queue, $priority, $msgJson, false, false, $error_code)) { + if (msg_send($queue, 1, $msgJson, false, false, $error_code)) { log::add('Abeille', 'debug', " publishMosquitto(): Sent '".$msgJson."' to queue ".$queueId); $queueStatus[$queueId] = "ok"; // Status ok } else @@ -2348,11 +2349,12 @@ public static function msgToCmd($priority, $topic, $payload = "") { } $msg = array(); + $msg['priority'] = $priority; $msg['topic'] = $topic; $msg['payload'] = $payload; $msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES); - if (msg_send($queue, $priority, $msgJson, false, false, $error_code)) { + if (msg_send($queue, 1, $msgJson, false, false, $error_code)) { log::add('Abeille', 'debug', " msgToCmd(): Envoyé '".$msgJson."' vers queue ".$queueId); $queueStatus[$queueId] = "ok"; // Status ok } else diff --git a/core/class/AbeilleCmdProcess.class.php b/core/class/AbeilleCmdProcess.class.php index 6d7b970635..4c6b0be0b6 100755 --- a/core/class/AbeilleCmdProcess.class.php +++ b/core/class/AbeilleCmdProcess.class.php @@ -1975,11 +1975,11 @@ function processCmd($Command) { $this->addCmdToQueue2(PRIO_NORM, $dest, $zgCmd, $data, $address, $addrMode); // if ($addrMode == "02" ) { - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0006&attrId=0000" ); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+3), "ep=".$dstEp."&clustId=0008&attrId=0000" ); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0006&attrId=0000" ); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+3), "ep=".$dstEp."&clustId=0008&attrId=0000" ); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+$Command['cmdParams']['onTime']), "ep=".$dstEp."&clustId=0006&attrId=0000" ); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+$Command['cmdParams']['onTime']), "ep=".$dstEp."&clustId=0008&attrId=0000" ); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+$Command['cmdParams']['onTime']), "ep=".$dstEp."&clustId=0006&attrId=0000" ); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$address."/readAttribute&time=".(time()+$Command['cmdParams']['onTime']), "ep=".$dstEp."&clustId=0008&attrId=0000" ); // } return; } @@ -2185,7 +2185,7 @@ function processCmd($Command) { $this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data); - $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "Cmd".$dest."/0000/permitJoin", "Status" ); + $this->sendToCmd(priorityInterrogation, "Cmd".$dest."/0000/permitJoin", "Status" ); } elseif ($mode == "stop") { $cmd = "0049"; $data = "FFFC0000"; @@ -2201,7 +2201,7 @@ function processCmd($Command) { $this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data); - $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "Cmd".$dest."/0000/permitJoin", "Status"); + $this->sendToCmd(priorityInterrogation, "Cmd".$dest."/0000/permitJoin", "Status"); } return; } // End cmdName == 'zgSetPermitMode' @@ -3890,11 +3890,11 @@ function processCmd($Command) { $this->addCmdToQueue2(priorityUserCmd, $dest, $zgCmd, $data, $addr, $addrMode); // if ($addrMode == "02") { - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0006&attrId=0000"); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3), "ep=".$dstEp."&clustId=0008&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0006&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3), "ep=".$dstEp."&clustId=0008&attrId=0000"); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0006&attrId=0000"); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0008&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0006&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0008&attrId=0000"); // } return; } @@ -3932,11 +3932,11 @@ function processCmd($Command) { $this->addCmdToQueue2(priorityUserCmd, $dest, $zgCmd, $data, $addr, $addrMode); // if ($addrMode == "02") { - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0006&attrId=0000"); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3), "ep=".$dstEp."&clustId=0008&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0006&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3), "ep=".$dstEp."&clustId=0008&attrId=0000"); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0006&attrId=0000"); - // $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0008&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0006&attrId=0000"); + // $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+3+$Command['cmdParams']['duration']), "ep=".$dstEp."&clustId=0008&attrId=0000"); // } return; } @@ -4518,7 +4518,7 @@ function processCmd($Command) { $this->addCmdToQueue2(priorityUserCmd, $dest, $zgCmd, $data, $addr, $addrMode); if ($addrMode == "02") { - $this->publishMosquitto($abQueues['xToCmd']['id'], priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0300&attrId=0007" ); + $this->sendToCmd(priorityInterrogation, "TempoCmd".$dest."/".$addr."/readAttribute&time=".(time()+2), "ep=".$dstEp."&clustId=0300&attrId=0007" ); } return; } diff --git a/core/class/AbeilleCmdQueue.class.php b/core/class/AbeilleCmdQueue.class.php index c43b87d28c..f04d06b68e 100755 --- a/core/class/AbeilleCmdQueue.class.php +++ b/core/class/AbeilleCmdQueue.class.php @@ -93,17 +93,20 @@ public function addTempoCmdAbeille($topic, $msg, $priority) { } } - public function publishMosquitto($priority, $topic, $payload) { - global $abQueues; - $queue = msg_get_queue($abQueues['xToCmd']['id']); + public function sendToCmd($priority, $topic, $payload) { + // global $abQueues; + // $queue = msg_get_queue($abQueues['xToCmd']['id']); - $msg = array(); - $msg['topic'] = $topic; - $msg['payload'] = $payload; + $msg = array( + 'priority' => $priority, + 'topic' => $topic, + 'payload' => $payload, + ); $msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES); - if (msg_send($queue, $priority, $msgJson, false, false) == false) { - cmdLog('debug', ' publishMosquitto() ERROR: Could not add message '.$msgJson.' to queue xToCmd'); + global $queueXToCmd; + if (msg_send($queueXToCmd, 1, $msgJson, false, false) == false) { + cmdLog('debug', ' sendToCmd() ERROR: Could not add message '.$msgJson.' to queue xToCmd'); } } @@ -120,7 +123,7 @@ public function execTempoCmdAbeille() { continue; // cmdLog('debug', 'execTempoCmdAbeille BEFORE - tempoMessageQueue='.json_encode($tempoMessageQueue)); - $this->publishMosquitto($mqttMessage['priority'], $mqttMessage['topic'], $mqttMessage['params']); + $this->sendToCmd($mqttMessage['priority'], $mqttMessage['topic'], $mqttMessage['params']); // msgToCmd() // cmdLog('debug', 'execTempoCmdAbeille(): tempoMessageQueue='.json_encode($tempoMessageQueue[$key])); // unset($tempoMessageQueue[$key]); diff --git a/core/php/AbeilleCliToQueue.php b/core/php/AbeilleCliToQueue.php index 59bee6a9e0..945739ee11 100644 --- a/core/php/AbeilleCliToQueue.php +++ b/core/php/AbeilleCliToQueue.php @@ -48,7 +48,7 @@ $queueId = $_GET['queueId']; else $queueId = $abQueues['xToAbeille']['id']; - if (isset($dbgTcharp38)) logDebug("CliToQueue: queueId=".$queueId); + if (isset($dbgTcharp38)) logDebug("CliToQueue: queueId=".sprintf("0x%X", $queueId)); $queue = msg_get_queue($queueId); if ($queue === false) { if (isset($dbgTcharp38)) logDebug("CliToQueue: ERROR: Invalid queue ID ".$queueId);