-
Notifications
You must be signed in to change notification settings - Fork 0
/
WateringSchedule.php
160 lines (116 loc) · 3.85 KB
/
WateringSchedule.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
include_once 'dbc.php';
$deviceCode = (is_null($_GET['deviceCode']) ? 'null' : $_GET['deviceCode']);
$previousResponse = (is_null($_GET['previousResponse']) ? 'null' : $_GET['previousResponse']);
$availableRam = (is_null($_GET['availableRam']) ? 'null' : $_GET['availableRam']);
//$timezone = date_default_timezone_get();
//echo "The current server timezone is: " . $timezone;
//$date =SELECT * FROM optilawn_main.ZoneWateringSchedule WHERE DeviceID = '234234' AND StartTime < NOW() AND EndTime > NOW() date('m/d/Y h:i:s a', time());
//echo $date;
$sql_query = "SELECT * FROM optilawn_main.ZoneWateringSchedule WHERE StartTime < NOW() AND EndTime > NOW() and deviceID = $deviceCode";
//echo $sql_query;
$results = mysql_query($sql_query,$link) or die(mysql_error());
$sql_reset_query = "select result from optilawn_main.reset_time where deviceID = $deviceCode and now() between Tstart and Tend";
$resetquery = mysql_query($sql_reset_query,$link) or die(mysql_error());
$array = mysql_fetch_array($resetquery);
if(mysql_num_rows($results) > 0){
$row = mysql_fetch_array($results);
$zone = $row['ZoneNumber'];
echo "{".$zone.",1}";
//$insert = "$zone,1";
$sql_insertquery = "Insert into Device_Requests (DeviceID,response,availableRam) Values($deviceCode,'$previousResponse','$availableRam')";
mysql_query($sql_insertquery,$link) or die(mysql_error());
}
elseif($array['result']){
echo "{0,9}"; /// to reset {0,9}
$insert = "0,9";
$sql_insertquery = "Insert into Device_Requests (DeviceID,response,availableRam) Values($deviceCode,'$insert','$availableRam')";
mysql_query($sql_insertquery,$link) or die(mysql_error());
}
else{
echo "{0,0}"; /// to reset {0,9}
$insert = "0,0";
$sql_insertquery = "Insert into Device_Requests (DeviceID,response,availableRam) Values($deviceCode,'$insert','$availableRam')";
mysql_query($sql_insertquery,$link) or die(mysql_error());
}
/*
$final = array();
$num = 1;
while($row = mysql_fetch_array($results)) {
$final[] = array(
"Day $num"=> array(
"Date" => $row['day'],
"Start Time" => $row['StartTime'],
"BaseTimeToWaterPerZone" => $row['BaseTimeToWaterPerZone'],
"zone" => array(
"z1pct" => $row['zone1pct'],
"z2pct" => $row['zone1pct'],
"z3pct" => $row['zone1pct'],
"z4pct" => $row['zone1pct'],
"z5pct" => $row['zone1pct'],
"z6pct" => $row['zone1pct'],
"z7pct" => $row['zone1pct'],
"z8pct" => $row['zone1pct'],
),
"Device ID" => $row['deviceID'],
)
);
$num++;
}
*/
//echo json_encode($final);
//echo "{2,1}"; // {zone,on/off}
//echo "<br>"; // break in printed echo
/*
$name = "Brian";
$obj = array("Gender" => "male",
"age" => "24"
//engaged: true,
//favorite_tv_shows: ['Lost', 'Dirty Jobs', 'Deadliest Catch', 'Man vs Wild'],
//family_members: [
// {name: "Frank", age: 57, relation: "father"},
// {name: "Tina", age: 26, relation: "sister"}
//]
);
$objUser = array("name" => $name);
$obj['user'] = $objUser;
echo $objUser;
$JsonObj = json_encode($obj);
echo $JsonObj;
//echo myObj.family_members[1].name;
//var propery = "age";
//echo myObj[propery];
//echo $deviceCode;
class User {
public $firstname = "";
public $lastname = "";
public $birthdate = "";
}
$user = new User();
$user->firstname = "foo";
$user->lastname = "bar";
// Returns: {"firstname":"foo","lastname":"bar"}
json_encode($user);
$user->birthdate = new DateTime();
/* Returns:
{
"firstname":"foo",
"lastname":"bar",
"birthdate": {
"date":"2012-06-06 08:46:58",
"timezone_type":3,
"timezone":"Europe\/Berlin"
}
}
*//*
echo json_encode($user);
$string = '{"foo": "bar", "cool": "attr"}';
$result = json_decode($string, true);
// Result: array(2) { ["foo"]=> string(3) "bar" ["cool"]=> string(4) "attr" }
var_dump($result);
// Prints "bar"
echo $result['foo'];
// Prints "attr"
echo $result['cool'];
*/
?>