-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostureproindex.html
More file actions
352 lines (310 loc) · 9.24 KB
/
postureproindex.html
File metadata and controls
352 lines (310 loc) · 9.24 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Posture Pro</title>
<link rel="stylesheet" href="styles.css">
</head>
<style>
/* Default styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
h1 {
margin: 0;
text-align: center; /* Center align title */
}
.wifi-info {
float: left;
}
.status {
float: right;
}
main {
padding: 20px;
display: flex;
flex-wrap: wrap;
}
.posture-section {
flex: 1;
padding-right: 10px;
margin-bottom: 20px;
}
#sensor-data-box {
flex: 1;
padding-left: 10px;
}
.data-box {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
padding: 20px;
}
.sensor-info {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
align-items: center;
/* padding-right: 20px; */
}
.sensor-info .label {
flex: 1;
font-weight: bold;
}
.sensor-info .value {
flex: 2;
font-weight: bold;
margin-left: 20px;
}
.motor-log {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 100%;
margin-top: 20px;
}
.theme-label {
margin-left: 10px;
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
/* Responsive styles */
@media screen and (max-width: 768px) {
header {
padding: 10px;
}
main {
padding: 10px;
flex-direction: column;
}
.data-box {
padding: 10px;
}
.sensor-info {
flex-direction: column;
margin-right: 0;
margin-bottom: 10px;
width: 100%;
}
.sensor-info .label {
margin-bottom: 5px;
}
}
@media screen and (max-width: 480px) {
.wifi-info,
.status {
float: none;
display: block;
text-align: center;
margin-bottom: 10px;
}
.sensor-info .label,
.sensor-info .value {
font-size: 14px;
}
.theme-label {
display: block;
margin-top: 10px;
}
}
</style>
<body>
<header>
<div class="wifi-info">
<div class="wifi-info">WiFi: <span id="wifiSSID">Loading...</span>, Signal Strength: <span id="wifiSignalStrength">Loading...</span></div>
</div>
<h1>Posture Pro</h1>
<div class="status" id="mpu-status">MPU6050 Status: Loading...</div>
</header>
<main>
<div class = "posture-section">
<div class = "data-box">
<h2>Posture Status</h2>
<div id = "posture-status">
<div class = "posture-info" id = "posture-condition">Posture Loading...</div>
<div class = "posture-info" id = "lean-type">Lean Type Loading...</div>
<div class = "posture-info" id = "posture-deviation">Deviation: Loading...</div>
</div>
</div>
</div>
<div class="data-box" id = "sensor-data-box">
<h2>MPU6050 Sensor Data</h2>
<div class="sensor-data" id="mpu-data">
<div class="sensor-info">
<span class="label">Acceleration:</span>
<span class="value">
X: <span id="accelerationX">0</span>  Y: <span id="accelerationY">0</span>  Z: <span id="accelerationZ">0</span>
</span>
</div>
<div class="sensor-info">
<span class="label">Rotation:</span>
<span class="value">
X: <span id="rotationX">0</span>  Y: <span id="rotationY">0</span>  Z: <span id="rotationZ">0</span>
</span>
</div>
<div class="sensor-info">
<span class="label">Temperature:</span>
<span class="value" id="temperature">0</span>
</div>
</div>
<div class="initial-readings">
<h2>Initial Readings</h2>
<div class="data">
<span class="label">Initial Acceleration:</span>
<span class="value" id="initialAcceleration">Loading...</span>
</div>
<div class="data">
<span class="label">Initial Gyro:</span>
<span class="value" id="initialGyro">Loading...</span>
</div>
<div class="data">
<span class="label">Temperature:</span>
<span class="value" id="initialTemperature">Loading...</span>
</div>
</div>
</div>
<div class="motor-log">
<h2>Motor Usage Log</h2>
<ul id="motor-usage">
<!-- Motor usage log will be dynamically populated here -->
</ul>
</div>
</main>
<footer>
<label class="switch">
<input type="checkbox" id="theme-toggle">
<span class="slider round"></span>
</label>
<span class="theme-label">Toggle Dark Theme</span>
</footer>
<script>
window.onload = function() {
function updateSensorData(data) {
// Update MPU6050 sensor data
document.getElementById("accelerationX").textContent = data.accelerationX;
document.getElementById("accelerationY").textContent = data.accelerationY;
document.getElementById("accelerationZ").textContent = data.accelerationZ;
document.getElementById("rotationX").textContent = data.rotationX;
document.getElementById("rotationY").textContent = data.rotationY;
document.getElementById("rotationZ").textContent = data.rotationZ;
document.getElementById("temperature").textContent = data.temperature;
}
// Function to update initial readings
function updateInitialReadings(data) {
const initialAcceleration = `X = ${data.initialX.toFixed(2)} Y = ${data.initialY.toFixed(2)} Z = ${data.initialZ.toFixed(2)}`;
const initialGyro = `X = ${data.initialGX.toFixed(2)} Y = ${data.initialGY.toFixed(2)} Z = ${data.initialGZ.toFixed(2)}`;
const initialTemperature = data.initialTemp.toFixed(2);
document.getElementById("initialAcceleration").textContent = initialAcceleration;
document.getElementById("initialGyro").textContent = initialGyro;
document.getElementById("initialTemperature").textContent = initialTemperature;
}
function updateWifiStatus(data) {
// Update WiFi SSID and signal strength
document.getElementById("wifiSSID").textContent = data.wifiSSID;
document.getElementById("wifiSignalStrength").textContent = data.wifiSignalStrength;
}
function updatePostureStatus(data) {
const postureCondition = data.isBadPosture ? "Bad Posture Detected" : "Good Posture";
const leanType = data.leanType;
const posturDeviation = '${data.postureDeviation} degrees';
document.getElementById("posture-condition").textContent = 'Posture: ${postureCondition}';
document.getElementById("lean-type").textContent = 'Lean Type: ${leanType}';
document.getElementById("posture-deviation").textContent = 'Deviation: ${postureDeviation}';
}
function updateMpuStatus(data) {
// Update MPU6050 connection status
const mpuStatusElement = document.getElementById("mpu-status");
if (data.mpuDetected) {
mpuStatusElement.textContent = "MPU6050 Status: Connected";
mpuStatusElement.style.color = "#00ff00"; // Green color
} else {
mpuStatusElement.textContent = "MPU6050 Status: Not Detected";
mpuStatusElement.style.color = "#ff0000"; // Red color
}
}
// Function to fetch sensor data from ESP32 and update HTML elements
function fetchData() {
fetch("/sensorData")
.then(response => response.json())
.then((data) => {
updateWifiStatus(data);
updateMpuStatus(data);
updateInitialReadings(data);
updateSensorData(data);
updatePostureStatus(data);
})
.catch(error => console.error("Error fetching data:", error));
}
// Fetch sensor data periodically
setInterval(fetchData, 1000); // Update every second
// Function to toggle dark theme
const themeToggle = document.getElementById("theme-toggle");
themeToggle.addEventListener("change", function() {
document.body.classList.toggle("dark-theme");
});
};
</script>
</body>
</html>