-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
91 lines (80 loc) · 2.6 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ESP32 Sensor Data</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
h1 {
color: #333;
text-align: center;
}
#Value {
font-size: 2em;
color: #008080;
text-align: center;
}
#emergencyButton {
margin-top: 20px;
padding: 10px;
background-color: #ff0000;
color: #fff;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>ESP32 Sensor Data</h1>
<p id="Value">{ sensorValue }</p>
<button id="emergencyButton">Emergency</button>
<script>
function updateSensorValue(value) {
document.getElementById('Value').innerText = 'Value: ' + value;
}
function fetchData() {
const serverAddress = 'http://192.168.1.2:5000/update?value';
fetch(serverAddress)
.then(response => response.json())
.then(data => {
if (data.value !== undefined) {
updateSensorValue(data.value);
} else {
console.error('Invalid data format:', data);
}
})
.catch(error => {
console.error('Error fetching data:', error);
});
}
function sendEmergencyQuery() {
// Modify the server address and endpoint as needed
const emergencyEndpoint = 'http://192.168.1.2:5000/emergency';
fetch(emergencyEndpoint)
.then(response => response.json())
.then(data => {
// Handle the response if needed
console.log('Emergency query response:', data);
})
.catch(error => {
console.error('Error sending emergency query:', error);
});
}
fetchData();
setInterval(fetchData, 5000);
// Add event listener for the emergency button
document.getElementById('emergencyButton').addEventListener('click', sendEmergencyQuery);
</script>
</body>
</html>