Skip to content

Commit

Permalink
zgSetCertif + cleanup + daemons restart if queue > 50msg
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Aug 14, 2024
1 parent 68df522 commit 58ea655
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 187 deletions.
8 changes: 5 additions & 3 deletions core/class/Abeille.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,10 @@ public static function cron() {
log::add('Abeille', 'info', "cron(): ERREUR: Pb d'accès à la queue '".$queueName."' (id ".$queueId.")");
continue;
}
if (msg_stat_queue($queue)["msg_qnum"] > 100)
log::add('Abeille', 'info', "cron(): ERREUR: La queue '".$queueName."' (id ".$queueId.") contient plus de 100 messages.");
if (msg_stat_queue($queue)["msg_qnum"] > 50) {
log::add('Abeille', 'error', "cron(): La queue '".$queueName."' (id ".$queueId.") contient plus de 50 messages => redémarrage des démons.");
self::deamon_start();
}
}

// https://github.com/jeelabs/esp-link
Expand Down Expand Up @@ -449,7 +451,7 @@ public static function cron() {
$lastComm = strtotime($lastComm);
// log::add('Abeille', 'info', "lastComm2=".$lastComm);
if ((time() - $lastComm) > (2 * 60)) {
log::add('Abeille', 'info', "Pas de réponse de la Zigate ".$gtwId." depuis plus de 2min");
log::add('Abeille', 'info', "Pas de réponse de la Zigate ".$gtwId." depuis plus de 2min => reset");
$zgType = $config['ab::gtwSubType'.$gtwId];
$zgPort = $config['ab::gtwPort'.$gtwId];
if (($zgType == "USB") || ($zgType == "USBv2")) {
Expand Down
204 changes: 29 additions & 175 deletions core/class/AbeilleCmdProcess.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,60 +787,6 @@ function readAttribute($priority, $dest, $addr, $dstEp, $clustId, $attribId, $ma
// $this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data, $address);
// }

/**
* reviewPriority()
*
* See if we need to change the priority reaquested for a message
*
* @param Command
* @return priority re-evaluated
*
*/
// function reviewPriority($Command) {
// if (isset($Command['priority'])) {
// // TODO: Eq Address and Group Address can't be distingueshed here. Probability to have a group address = eq address is low but exist.
// if (isset($Command['cmdParams']['address'])) {
// if ($NE = Abeille::byLogicalId($Command['dest'].'/'.$Command['cmdParams']['address'], 'Abeille')) {
// if ($NE->getIsEnable()) {
// if (( time() - strtotime($NE->getStatus('lastCommunication'))) < (60*$NE->getTimeout()) ) {
// if ($NE->getStatus('APS_ACK', '1') == '1') {
// return $Command['priority'];
// }
// else {
// cmdLog('debug', " NE n a pas repondu lors de precedente commande alors je mets la priorite au minimum.");
// return priorityLostNE;
// }
// }
// else {
// cmdLog('debug', " NE en Time Out alors je mets la priorite au minimum.");
// return priorityLostNE;
// }
// }
// else {
// /* Tcharp38: Preventing cmd to be sent if EQ is disabled is not good here.
// If EQ was disabled but now under pairing process (dev announce)
// this prevents interrogation of EQ and therefore reinclusion.
// This check should be done at source not here. At least don't filter
// requests from parser. */
// // cmdLog('debug', " NE desactive, je n envoie pas de commande.");
// // return -1;
// return $Command['priority'];
// }
// }
// else {
// cmdLog('debug', " NE n existe pas dans Abeille, une annonce/une commande de groupe, je ne touche pas à la priorite.");
// return $Command['priority'];
// }
// }
// else {
// return $Command['priority'];
// }
// }
// else {
// cmdLog('debug', " priority not defined !!!");
// return priorityInterrogation;
// }
// }

/**
* processCmd()
Expand Down Expand Up @@ -904,52 +850,14 @@ function processCmd($Command) {
// }

// abeilleList abeilleListAll
if (isset($Command['abeilleList'])) {
if ($Command['name'] == 'abeilleList') {

cmdLog('debug', " Get Abeilles List", $this->debug['processCmd']);
// $this->addCmdToQueue($priority,$dest,"0015","0000","");
$this->addCmdToQueue2(PRIO_NORM, $dest, "0015");
return;
}

if (isset($Command['setCertificationCE'])) {
cmdLog('debug', " setCertificationCE", $this->debug['processCmd']);
$cmd = "0019";
$data = "01";

// $length = sprintf("%04s", dechex(strlen($data) / 2));
// $this->addCmdToQueue($priority, $dest, $cmd, $length, $data);
$this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data);
return;
}

if (isset($Command['setCertificationFCC'])) {
cmdLog('debug', " setCertificationFCC", $this->debug['processCmd']);
$cmd = "0019";
$data = "02";

// $length = sprintf("%04s", dechex(strlen($data) / 2));
// $this->addCmdToQueue($priority, $dest, $cmd, $length, $data);
$this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data);
return;
}


// // https://github.com/fairecasoimeme/ZiGate/issues/145
// // PHY_PIB_TX_POWER_DEF (default - 0x80)
// // PHY_PIB_TX_POWER_MIN (minimum - 0)
// // PHY_PIB_TX_POWER_MAX (maximum - 0xbf)
// if (isset($Command['cmdParams']['txPower']) ) { // Obsolete !! Replaced by zgSetTxPower
// cmdLog('debug', " TxPower", $this->debug['processCmd']);
// $cmd = "0806";
// $data = $Command['cmdParams']['txPower'];
// if ($data < 10 ) $data = '0'.$data;

// // $length = sprintf("%04s", dechex(strlen($data) / 2));
// // $this->addCmdToQueue($priority, $dest, $cmd, $length, $data);
// $this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data);
// return;
// }

//----------------------------------------------------------------------
// Bind
// Title => 000B57fffe3025ad (IEEE de l ampoule)
Expand Down Expand Up @@ -1716,55 +1624,6 @@ function processCmd($Command) {
return;
}

// /* Expected format:
// net/0000 ActiveEndpointRequest address=<addr>*/
// if (isset($Command['ActiveEndPoint'])) // OBSOLETE: Use getActiveEndpoints instead
// {
// $cmd = "0045";

// // <target short address: uint16_t>

// $address = $Command['cmdParams']['address']; // -> 4

// // 4 = 4/2 => 2
// // $length = "0002";

// $data = $address;

// // $this->addCmdToQueue($priority, $dest, $cmd, $length, $data, $address);
// $this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data, $address);
// return;
// }

//----------------------------------------------------------------------------
// OBSOLETE: Replaced by getNwkAddress()
// if (isset($Command['Network_Address_request']))
// {
// $cmd = "0040";

// // <target short address: uint16_t> -> 4
// // <extended address:uint64_t> -> 16
// // <request type: uint8_t> -> 2
// // <start index: uint8_t> -> 2
// // Request Type:
// // 0 = Single Request 1 = Extended Request
// // -> 24 / 2 = 12 => 0x0C

// $address = $Command['cmdParams']['address'];
// $IeeeAddress = $Command['IEEEAddress'];
// $requestType = "01";
// $startIndex = "00";

// $data = $address.$IeeeAddress.$requestType.$startIndex ;
// // $length = "000C"; // A verifier

// cmdLog('debug', ' Network_Address_request: '.$data.' - '.$length, $this->debug['processCmd'] );

// // $this->addCmdToQueue($priority, $dest, $cmd, $length, $data, $address);
// $this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data, $address);
// return;
// }

// Don't know how to make it works
if ($Command['name'] == 'touchLinkFactoryResetTarget') {

Expand Down Expand Up @@ -2183,37 +2042,6 @@ function processCmd($Command) {
return;
}

// if (isset($Command['getManufacturerName']) && isset($Command['cmdParams']['address']))
// {
// if ($Command['cmdParams']['destinationEndpoint'] == "" ) { $Command['cmdParams']['destinationEndpoint'] = "01"; }
// $this->readAttribute(PRIO_NORM, $dest, $Command['cmdParams']['address'], $Command['cmdParams']['destinationEndpoint'], "0000", "0004");
// return;
// }

// if (isset($Command['getName']) && isset($Command['cmdParams']['address']))
// {
// if ($Command['cmdParams']['destinationEndpoint'] == "" ) { $Command['cmdParams']['destinationEndpoint'] = "01"; }
// $this->readAttribute(PRIO_NORM, $dest, $Command['cmdParams']['address'], $Command['cmdParams']['destinationEndpoint'], "0000", "0005");
// return;
// }

// if (isset($Command['getLocation']) && isset($Command['cmdParams']['address']))
// {
// if ($Command['cmdParams']['destinationEndpoint'] == "" ) { $Command['cmdParams']['destinationEndpoint'] = "01"; }
// $this->readAttribute(PRIO_NORM, $dest, $Command['cmdParams']['address'], $Command['cmdParams']['destinationEndpoint'], "0000", "0010");
// return;
// }

// Tcharp38: Seems no longer used
// if (isset($Command['setLocation']) && isset($Command['cmdParams']['address']))
// {
// if ($Command['location'] == "" ) { $Command['location'] = "Not Def"; }
// if ($Command['cmdParams']['destinationEndpoint'] == "" ) { $Command['cmdParams']['destinationEndpoint'] = "01"; }

// $this->setParam2( $dest, $Command['cmdParams']['address'], "0000", "0010",$Command['cmdParams']['destinationEndpoint'],$Command['location'], "42" );
// return;
// }

if ($Command['name'] == 'MgtLeave') {

// Zigbee specification
Expand Down Expand Up @@ -2298,7 +2126,7 @@ function processCmd($Command) {
* Zigate specific commands
*/

// Zigate specific command
// Zigate specific command: Set mode (raw, hybrid, normal)
if ($cmdName == 'zgSetMode') {
$mode = $Command['cmdParams']['mode'];
if ($mode == "raw") {
Expand All @@ -2312,8 +2140,34 @@ function processCmd($Command) {
return;
}

// Zigate specific command: Set certfication (CE, FCC)
else if ($cmdName == 'zgSetCertification') {
$required = ['certif'];
if (!$this->checkRequiredParams($required, $Command))
return;

$zgCmd = "0019";
$certif = $Command['cmdParams']['certif'];
if ($certif == "CE")
$data = "01";
else if ($certif == "FCC")
$data = "02";
else {
cmdLog('error', ' zgSetCertification: Certification invalide ! ('.$certif.')');
return;
}

cmdLog('debug', " zgSetCertification: Certif=${data}/${certif}");
$this->addCmdToQueue2(PRIO_NORM, $dest, $zgCmd, $data);
return;
}

// Zigate specific command
else if ($cmdName == 'zgSetPermitMode') {
$required = ['mode'];
if (!$this->checkRequiredParams($required, $Command))
return;

$mode = $Command['cmdParams']['mode'];
if ($mode == "start") {
$cmd = "0049";
Expand Down
2 changes: 1 addition & 1 deletion core/class/AbeilleCmdQueue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ function processCmdQueues() {
if (isset($GLOBALS["dbgMonitorAddr"]) && ($cmd['addr'] != "") && ($GLOBALS["dbgMonitorAddr"] != "") && !strncasecmp($cmd['addr'], $GLOBALS["dbgMonitorAddr"], 4))
monMsgToZigate($cmd['addr'], $cmd['cmd'].'-'.$cmd['datas']); // Monitor this addr ?
cmdLog('debug', " Zigate=".json_encode($GLOBALS['zigates'][$zgId]));
// cmdLog('debug', " Zigate=".json_encode($GLOBALS['zigates'][$zgId]));
}
} // End zigates loop
}
Expand Down
3 changes: 1 addition & 2 deletions core/config/AbeilleInternalCmds.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"WindowsCoveringGroup": {},

"abeilleList": {},
"setCertificationCE": {},
"setCertificationFCC": {},
"setExtendedPANID": {},
"bind": {},
"setReportRaw": {},
Expand All @@ -56,6 +54,7 @@
"MgtLeave": {},
"Remove": {},
"zgSetMode": {},
"zgSetCertification": {},
"zgSetPermitMode": {},
"permitJoin": {},
"zgGetNetworkStatus": {},
Expand Down
10 changes: 8 additions & 2 deletions core/php/AbeilleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,15 @@ function parserLog2($level, $addr, $msg, $type = '') {
Msg format is now flexible and can transport a bunch of infos coming from zigbee event instead of splitting them
into several messages to Abeille. */
function msgToAbeille2($msg) {
$msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES);
global $queueXToAbeille;
if (msg_send($queueXToAbeille, 1, json_encode($msg, JSON_UNESCAPED_SLASHES), false, false, $errCode) == false) {
parserLog("debug", "msgToAbeille2(): ERROR ".$errCode);
// Note: '@' to suppress PHP warning message.
if (@msg_send($queueXToAbeille, 1, $msgJson, false, false, $errCode) == false) {
// Err 11 = EAGAIN = Queue full ?
$errDesc = "";
if ($errCode == 11)
$errDesc = "/queue FULL";
parserLog("debug", "msgToAbeille2(): ERROR ${errCode}${errDesc}");
}
}

Expand Down
1 change: 0 additions & 1 deletion core/php/AbeilleSerialRead.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

/* Developers mode ? */
if (file_exists(dbgFile)) {
// include_once dbgFile;
/* Dev mode: enabling PHP errors logging */
error_reporting(E_ALL);
ini_set('error_log', __DIR__.'/../../../../log/AbeillePHP.log');
Expand Down
5 changes: 2 additions & 3 deletions desktop/js/Abeille.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,8 @@ function sendZigate(action, param) {
else payload = "value=0";
break;
case "setCertif":
if (param == "CE")
topic = "CmdAbeille" + zgId + "/0000/setCertificationCE";
else topic = "CmdAbeille" + zgId + "/0000/setCertificationFCC";
topic = "CmdAbeille" + zgId + "/0000/zgSetCertification";
payload = param; // 'CE' or 'FCC'
break;
case "startNetwork": // Not required for end user but for developper.
topic = "CmdAbeille" + zgId + "/0000/zgStartNetwork";
Expand Down
3 changes: 3 additions & 0 deletions docs/fr_FR/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- Amélioration: Cmd: Ajout support 'repeat' pour repeter une action jusqu'a acquittement (Attention !! Limiter son usage).
- Améliorations: Interne cmd.
- Améliorations: Interne main daemon: Config sauvé en global.
- Amélioration: Interne parser: Suppression warning si queue 'main' pleine.
- Amélioration: Redémarrage de tous les démons si une des queues est saturée (>50 messages).
- Amélioration: Interne cmd: setCertificationCE/FCC => 'zgSetCertification'.

## 240808-BETA-1

Expand Down

0 comments on commit 58ea655

Please sign in to comment.