Skip to content

Commit

Permalink
parser: mktime issue: poch doesn't fit in a PHP integer
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Sep 20, 2024
1 parent 6d9b436 commit 70bf8aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 2 additions & 6 deletions core/class/AbeilleCmdQueue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static function pushZigateCmd($zgId, $pri, $zgCmd, $payload, $repeat, $ad
'cmd' => $zgCmd, // Zigate message type
'datas' => $payload,
'zgOnly' => zgIsZigateOnly($zgCmd), // Msg for Zigate only if true, not to be transmitted
'status' => '', // '', 'SENT', '8000', '8012' or '8702', '8011'
'status' => '', // '', 'SENT'
'try' => maxRetryDefault + 1, // Number of retries if failed
'sentTime' => 0, // For lost cmds timeout
// Timeout: Zigate has 7s internal timeout when ACK
Expand Down Expand Up @@ -789,11 +789,7 @@ function checkZigatesStatus() {

if ($cmd['status'] == '')
continue; // Not sent yet
// Timeout: At least 4sec to let Zigate do its job but is that enough ?
// if ($cmd['ackAps'])
// $timeout = 8; // Zigate has 7s internal timeout when ACK
// else
// $timeout = 4;

$timeout = $cmd['timeout'];
if ($cmd['sentTime'] + $timeout > time())
continue; // Timeout not reached yet
Expand Down
15 changes: 10 additions & 5 deletions core/class/AbeilleParser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3294,11 +3294,16 @@ function decode8002($dest, $payload, $lqi) {
// PHP uses 00:00:00 @1st of jan 1970 (Linux ref)
// Attr 0007, type uint32/0x23
$lt = localtime(null, true);
$localTime = mktime($lt['tm_hour'], $lt['tm_min'], $lt['tm_sec'], $lt['tm_mon'], $lt['tm_mday'], $lt['tm_year']);
$localTime -= mktime(0, 0, 0, 1, 1, 2000); // PHP to Zigbee shift
$localTime = sprintf("%04X", $localTime);
msgToCmd(PRIO_NORM, "Cmd".$dest."/".$srcAddr."/sendReadAttributesResponse", 'ep='.$srcEp.'&clustId='.$clustId.'&attrId='.$attrId.'&status=00&attrType=23&attrVal='.$localTime);
parserLog2('debug', $srcAddr, " Attribute 0007/LocalTime: Answering to device");
// $localTime = @mktime($lt['tm_hour'], $lt['tm_min'], $lt['tm_sec'], $lt['tm_mon'], $lt['tm_mday'], $lt['tm_year']);
$localTime = @mktime($lt['tm_hour']);
if ($localTime === false) { // mktime(): Epoch doesn't fit in a PHP integer
parserLog2('error', $srcAddr, " Attribute 0007/LocalTime: CAN'T answer to device. mktime() failed.");
} else {
$localTime -= mktime(0, 0, 0, 1, 1, 2000); // PHP to Zigbee shift
$localTime = sprintf("%04X", $localTime);
msgToCmd(PRIO_NORM, "Cmd".$dest."/".$srcAddr."/sendReadAttributesResponse", 'ep='.$srcEp.'&clustId='.$clustId.'&attrId='.$attrId.'&status=00&attrType=23&attrVal='.$localTime);
parserLog2('debug', $srcAddr, " Attribute 0007/LocalTime: Answering to device");
}
} else {
parserLog2('debug', $srcAddr, " WARNING: Unsupported time cluster attribute ".$attrId);
}
Expand Down
1 change: 1 addition & 0 deletions docs/fr_FR/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Corrections: Interne: install.php & AbeilleTools.class.php
- Amélioration: Flasher PI Zigate: Création package standalone.
- Correction: Page santé. Crash interne si plusieurs autre passerelles désactivées.
- Correction: Parser: mktime() sur systeme 32bits.

## 240902-BETA-1

Expand Down

0 comments on commit 70bf8aa

Please sign in to comment.