-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.html
More file actions
67 lines (61 loc) · 2.14 KB
/
test.html
File metadata and controls
67 lines (61 loc) · 2.14 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hidden Form Example</title>
<style>
/* Hide the form */
#hiddenForm {
display: none;
}
</style>
</head>
<body>
<h1>Hidden Form Example</h1>
<!-- Hidden Form -->
<form id="hiddenForm" action="/submit" method="POST">
<input type="text" id="name" name="name">
<input type="email" id="email" name="email">
<input type="submit" value="Submit">
</form>
<button onclick="fillAndSubmitForm()">Fill and Submit Form</button>
<button onclick="sendData(42)">Send Sensor Data</button> <!-- Button to send sensor data -->
<script>
let devID = -1; // Initialize devID
async function sendData(x) {
const BASE_URL = 'https://awaited-definite-cockatoo.ngrok-free.app';
console.log(x);
try {
const response = await fetch(`${BASE_URL}/sendSensorValues`, {
method: 'POST',
mode: 'cors',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
deviceID: devID,
sensorValue: x,
}),
});
const data = await response.json();
console.log({ data });
if (devID === -1) {
devID = data['deviceID'];
console.log(devID);
}
} catch (e) {
console.log(e);
}
}
function fillAndSubmitForm() {
// Fill in the form inputs
document.getElementById('name').value = 'John Doe';
document.getElementById('email').value = 'john.doe@example.com';
// Submit the form
document.getElementById('hiddenForm').submit();
}
</script>
</body>
</html>