forked from mgshadow/rasp_climate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor.php
executable file
·97 lines (89 loc) · 2.26 KB
/
sensor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
include("include/sensorclass.php");
$db = mysqli_connect("localhost","datalogger","datalogger") or die("DB Connect error");
mysqli_select_db($db, "datalogger");
echo ("<br>reading Sensor Data");
function readSensor($db, $sensor)
{
echo ("\nReading Sensor $sensor");
$output = array();
$return_var = 0;
$i=1;
exec('sudo /usr/local/bin/loldht '.$sensor, $output, $return_var);
while (substr($output[$i],0,1)!="H")
{
$i++;
if ($i>20)
{
echo ("\nno Sensor Value");
$err=new ErrorEntry($sensor,1);
$err->writeToDB($db);
return;
}
}
echo ("\nValue found");
$osensor=SensorFactory::getSensor($sensor);
$humid=substr($output[$i],11,5);
if ((int)$humid>$osensor->humWarningMax)
{
$err=new ErrorEntry($sensor,11);
$err->writeToDB($db);
}
if ((int)$humid<$osensor->humWarningMin)
{
$err=new ErrorEntry($sensor,10);
$err->writeToDB($db);
}
$temp=substr($output[$i],33,5);
if ((int)$temp>$osensor->tempWarningMax)
{
$err=new ErrorEntry($sensor,21);
$err->writeToDB($db);
}
if ((int)$temp<$osensor->tempWarningMin)
{
$err=new ErrorEntry($sensor,20);
$err->writeToDB($db);
}
$q = "INSERT INTO datalogger VALUES (now(), $sensor, '$temp', '$humid',0)";
echo ("\n".$q);
mysqli_query($db, $q);
return;
}
readSensor($db, 21);
readSensor($db, 9);
readSensor($db, 8);
readSensor($db, 7);
$inSensor=SensorFactory::getInsideSensor();
$inValue=$inSensor->getValue($db);
$box1Sensor=SensorFactory::getBox1Sensor();
$box1Value=$box1Sensor->getValue($db);
$box2Sensor=SensorFactory::getBox2Sensor();
$box2Value=$box2Sensor->getValue($db);
$humTolerance=5;
if ($inValue->isValid() && $box1Value->isValid())
{
echo ("\nCheck box1");
if ($box1Value->hum < $inValue->hum - $humTolerance)
{
$err=new ErrorEntry($box1Sensor,12);
$err->writeToDB($db);
echo ("\nValue not OK");
}
else
echo ("\nValueOK");
}
if ($inValue->isValid() && $box2Value->isValid())
{
echo ("\nCheck box2");
if ($box2Value->hum < $inValue->hum - $humTolerance)
{
$err=new ErrorEntry($box2Sensor,12);
$err->writeToDB($db);
echo ("\nValue not OK");
}
else
echo ("\nValueOK");
}
mysqli_close($db);
?>