-
Notifications
You must be signed in to change notification settings - Fork 0
/
esppost.php
61 lines (60 loc) · 2.71 KB
/
esppost.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
<?php
include 'main_functions/init.php';
if (empty($_GET)) {
echo "empty";
} else {
$sensorIsNumeric = false;
$configuration = get_configuration($_GET['configurationID']);
if (is_numeric($_GET['sensorValue'])) {
$sensorValue = floatval($_GET['sensorValue']);
$sensorIsNumeric = true;
} else {
$sensorValue = $_GET['sensorValue'];
}
switch ($configuration['sensor_condition']) {
case 'equal':
if (($sensorIsNumeric && $sensorValue == $configuration['sensor_value']) || (!$sensorIsNumeric && strcasecmp($sensorValue, $configuration['sensor_value']) == 0)) {
$data = array("actuatorValue" => $configuration['actuator_value_if']);
} else {
$data = array("actuatorValue" => $configuration['actuator_value_else']);
}
break;
case 'different':
if (($sensorIsNumeric && $sensorValue != $configuration['sensor_value']) || (!$sensorIsNumeric && strcasecmp($sensorValue, $configuration['sensor_value']) != 0)) {
$data = array("actuatorValue" => $configuration['actuator_value_if']);
} else {
$data = array("actuatorValue" => $configuration['actuator_value_else']);
}
break;
case 'greater':
if ($sensorIsNumeric && $sensorValue > $configuration['sensor_value']) {
$data = array("actuatorValue" => $configuration['actuator_value_if']);
} else {
$data = array("actuatorValue" => $configuration['actuator_value_else']);
}
break;
case 'greaterOrEqual':
if ($sensorIsNumeric && $sensorValue >= $configuration['sensor_value']) {
$data = array("actuatorValue" => $configuration['actuator_value_if']);
} else {
$data = array("actuatorValue" => $configuration['actuator_value_else']);
}
break;
case 'less':
if ($sensorIsNumeric && $sensorValue < $configuration['sensor_value']) {
$data = array("actuatorValue" => $configuration['actuator_value_if']);
} else {
$data = array("actuatorValue" => $configuration['actuator_value_else']);
}
break;
case 'lessOrEqual':
if ($sensorIsNumeric && $sensorValue <= $configuration['sensor_value']) {
$data = array("actuatorValue" => $configuration['actuator_value_if']);
} else {
$data = array("actuatorValue" => $configuration['actuator_value_else']);
}
break;
}
echo json_encode($data);
}
?>