49 lines
961 B
HTML
49 lines
961 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<title>node-poweredup Web Bluetooth Test</title>
|
|
<script src="./dist/bundle.js"></script>
|
|
<script>
|
|
|
|
const poweredUP = new PoweredUP.PoweredUP();
|
|
|
|
const scan = async function () {
|
|
|
|
poweredUP.scan(); // Start scanning for hubs
|
|
|
|
poweredUP.on("discover", async (hub) => { // Wait to discover hubs
|
|
|
|
hub.on("attach", (port, device) => {
|
|
console.log("ATTACH", port, device);
|
|
});
|
|
|
|
hub.on("button", (button, state) => {
|
|
console.log("BUTTON", button, state);
|
|
})
|
|
|
|
hub.on("distance", (port, distance) => {
|
|
console.log("DISTANCE", port, distance);
|
|
});
|
|
|
|
await hub.connect(); // Connect to hub
|
|
console.log(`Connected to ${hub.name}!`);
|
|
|
|
hub.on("disconnect", () => {
|
|
console.log("Hub disconnected");
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<div>
|
|
<button onclick="scan()">Scan</button>
|
|
</div>
|
|
</body>
|
|
|
|
</html> |