]> Untitled Git - dev/commitdiff
Улучшено чтение с датчиков температуры, учитывается контрольная сумма, делается 3...
authordirect <direct@1423-sleepy.empl.vvsu.ru>
Tue, 23 Mar 2021 04:49:40 +0000 (14:49 +1000)
committerdirect <direct@1423-sleepy.empl.vvsu.ru>
Tue, 23 Mar 2021 04:49:40 +0000 (14:49 +1000)
sens/sens.php

index cbd005e0e7d1f3109ac6a62bef3a3ba5c7aeddeb..384dac055962bb5b16e54cd04e6b2b1a2d8fda1b 100644 (file)
@@ -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);