forked from nathankellenicki/node-poweredup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webble_test.html
73 lines (59 loc) · 1.65 KB
/
webble_test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>node-poweredup Web Bluetooth Test</title>
<script>
const scan = async function () {
const WEDO2_SMART_HUB = "00001523-1212-efde-1523-785feabcd123";
const LPF2_HUB = "00001623-1212-efde-1623-785feabcd123";
const LPF2_ALL = "00001624-1212-efde-1623-785feabcd123"
const device = await navigator.bluetooth.requestDevice({
filters: [
{
services: [
WEDO2_SMART_HUB
]
},
{
services: [
LPF2_HUB
]
}
]
});
const server = await device.gatt.connect();
console.log(server);
let connectComplete = false;
let hubType = 0;
let isLPF2Hub = false;
let service;
try {
service = await server.getPrimaryService(WEDO2_SMART_HUB);
hubType = 1;
} catch (error) {}
try {
service = await server.getPrimaryService(LPF2_HUB);
isLPF2Hub = true;
} catch (error) {}
const characteristics = await service.getCharacteristics();
const charMap = {};
for (const characteristic of characteristics) {
charMap[characteristic.uuid] = characteristic;
}
charMap[LPF2_ALL].addEventListener("characteristicvaluechanged", (event) => {
console.log(event.target.value.buffer);
});
charMap[LPF2_ALL].startNotifications();
if (isLPF2Hub) {
const hubTypeCmd = new Uint8Array([0x05, 0x00, 0x01, 0x0b, 0x05]);
charMap[LPF2_ALL].writeValue(hubTypeCmd);
}
}
</script>
</head>
<body>
<div>
<button onclick="scan()">Scan</button>
</div>
</body>
</html>