-
Notifications
You must be signed in to change notification settings - Fork 0
/
phptest.html
48 lines (43 loc) · 1.69 KB
/
phptest.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
<!DOCTYPE html>
<html>
<head>
<title>Phone IMU Sensor Data</title>
</head>
<body>
<h1>Phone IMU Sensor Data</h1>
<p>Accelerometer X: <span id="accel-x"></span></p>
<p>Accelerometer Y: <span id="accel-y"></span></p>
<p>Accelerometer Z: <span id="accel-z"></span></p>
<p>Gyroscope X: <span id="gyro-x"></span></p>
<p>Gyroscope Y: <span id="gyro-y"></span></p>
<p>Gyroscope Z: <span id="gyro-z"></span></p>
<button onclick="sendData()">Send Data</button>
<script>
window.addEventListener("devicemotion", handleMotion, true);
function handleMotion(event) {
// Get accelerometer data
var accelX = event.acceleration.x;
var accelY = event.acceleration.y;
var accelZ = event.acceleration.z;
// Get gyroscope data
var gyroX = event.rotationRate.alpha;
var gyroY = event.rotationRate.beta;
var gyroZ = event.rotationRate.gamma;
// Update HTML page with sensor data
document.getElementById("accel-x").innerHTML = accelX;
document.getElementById("accel-y").innerHTML = accelY;
document.getElementById("accel-z").innerHTML = accelZ;
document.getElementById("gyro-x").innerHTML = gyroX;
document.getElementById("gyro-y").innerHTML = gyroY;
document.getElementById("gyro-z").innerHTML = gyroZ;
// Send the data to the server
function sendData() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "store_data.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("accelX=" + accelX + "&accelY=" + accelY + "&accelZ=" + accelZ + "&gyroX=" + gyroX + "&gyroY=" + gyroY + "&gyroZ=" + gyroZ);
}
}
</script>
</body>
</html>