-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.php
More file actions
55 lines (48 loc) · 1.46 KB
/
fetch.php
File metadata and controls
55 lines (48 loc) · 1.46 KB
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
<?php
$query = "select * FROM data ORDER BY rollno DESC LIMIT 1";
$res = mysqli_query($conn, $query);
$data = mysqli_fetch_array($res);
$query1 = "Select * FROM irrigation_status ORDER BY rollno DESC LIMIT 1";
$res1 = mysqli_query($conn, $query1);
$data1 = mysqli_fetch_array($res1);
$temp = $data['temp'];
$hum = $data['hum'];
$soil_moisture = $data['soil_moisture'];
$i_status = $data1['status'];
$_trigger_status;
// if($i_status == 1){
// $_trigger_status = "ON";
// }else{
// $_trigger_status = "OFF";
// }
if ($soil_moisture >= 700) {
$_trigger_status = "ON";
} else {
$_trigger_status = "OFF";
}
?>
<script>
function irragationTrigger() {
var trig_status = document.getElementById("switch");
if (trig_status.checked == true) {
document.getElementById("trigger").innerHTML = "ON";
// alert("Trigger On");
fetch("http://localhost/Smart_Agri/irrigation_on.php");
} else {
document.getElementById("trigger").innerHTML = "OFF";
// alert("Trigger OFf");
fetch("http://localhost/Smart_Agri/irrigation_off.php");
}
}
function FetchData() {
fetch("http://localhost/test/fetch.php")
.then((res1) => res1.text())
.then((data) => {
if (status == 1) {
testnode.checked = true;
} else {
testnode.checked = false;
}
});
}
</script>