-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (47 loc) · 2.03 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Send To M5StickC Plus2</title>
</head>
<body>
<h2>Send Data to Firebase</h2>
<label for="opcode">Opcode:</label>
<input type="number" id="opcode" placeholder="Enter Opcode" />
<br />
<label for="byteData">Byte:</label>
<input type="number" id="byteData" placeholder="Enter Byte Data" />
<br />
<button onclick="Send()">Send</button>
<script>
function Send() {
// Get values from input fields
let opcode = document.getElementById("opcode").value;
let byteData = document.getElementById("byteData").value;
// Ensure that empty fields are sent as 0, not an empty string
opcode = opcode === "" ? 0 : Number(opcode);
byteData = byteData === "" ? 0 : Number(byteData);
// Firebase database URLs for different databases
const opcodeDatabaseURL = "https://local-roomba-control-default-rtdb.firebaseio.com/command.json";
const byteDatabaseURL = "https://local-roomba-control-bytes-default-rtdb.firebaseio.com/command.json";
fetch(opcodeDatabaseURL, {
method: "PUT",
body: JSON.stringify(opcode),
headers: { "Content-Type": "application/json" }
})
.then(response => response.json())
.then(data => console.log("Opcode Sent:", data))
.catch(error => console.error("Error with opcode:", error));
fetch(byteDatabaseURL, {
method: "PUT",
body: JSON.stringify(byteData),
headers: { "Content-Type": "application/json" }
})
.then(response => response.json())
.then(data => console.log("Byte Data Sent:", data))
.catch(error => console.error("Error with byte data:", error));
}
</script>
</body>
</html>