From: direct Date: Tue, 23 Mar 2021 04:49:40 +0000 (+1000) Subject: Улучшено чтение с датчиков температуры, учитывается контрольная сумма, делается 3... X-Git-Url: http://git.ultra-x.su/?a=commitdiff_plain;h=c1ae6b8218306c04cf2baa622a4d774a22587d5b;p=dev Улучшено чтение с датчиков температуры, учитывается контрольная сумма, делается 3 попытки в случае неудачи. --- diff --git a/sens/sens.php b/sens/sens.php index cbd005e..384dac0 100644 --- a/sens/sens.php +++ b/sens/sens.php @@ -33,12 +33,33 @@ class temp_reader extends Children protected function readTempData($device) { - $value = @file_get_contents('/sys/bus/w1/devices/'.$device.'/temperature'); - if ($value === FALSE) + for ($try = 0; $try <3; $try++) { - return FALSE; + $value = @file_get_contents('/sys/bus/w1/devices/'.$device.'/w1_slave'); + if ($value === FALSE) + { + continue; + } + $C = preg_match('/.*crc=..\s(.*)\n.*t=(.*)\n/m', $value, $match); + if ($C == 0) + { + continue; + } + if ($match[1] != 'YES') + { + continue; + } + $result = $match[2]; + break; + } + if (isset($result)) + { + return $result; + } + else + { + return false; } - return $value; } protected function ChildBody($data) @@ -51,8 +72,11 @@ class temp_reader extends Children foreach ($DEVS as $DEV) { - $DATA[$DEV] = $this->readTempData($DEV); - + $RDATA = $this->readTempData($DEV); + if ($RDATA !== false) + { + $DATA[$DEV] = $this->readTempData($DEV); + } } $SR = $this->SendEvent('data', $DATA); sleep(30);