-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.js
45 lines (42 loc) · 1.51 KB
/
demo.js
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
const Client = require(".");
/**
* @param {Client} client
*/
function setupListeners(client) {
function hex(n) {
return `0x${n > 16 ? n.toString(16) : "0"+n.toString(16)}`
}
client.events.on("data", data => console.log("DATA", data));
client.events.on("mysteryData", (data, uuid) => console.log("MYSTERY", uuid, [...data].map(n => hex(n).join(" "))));
client.events.on("send", data => console.log("SEND", [...data].map(n => hex(n)).join(" ")));
client.events.on("error", err => console.log("ERROR", err));
}
(async () => {
try {
console.error("Scanning...");
const client = await Client.scan(process.argv[2], 10000);
setupListeners(client);
console.error("Connecting...");
await client.connect();
console.error("Connected...");
await new Promise(resolve => setTimeout(resolve, 3000))
console.error("Starting...");
await client.start({calories: 50});
await new Promise(resolve => setTimeout(resolve, 2000))
console.error("Setting level to 18...");
await client.setLevel(18);
await new Promise(resolve => setTimeout(resolve, 3000))
console.error("Setting level to 14...");
await client.setLevel(14);
await new Promise(resolve => setTimeout(resolve, 5000))
console.error("Pausing...");
await client.pause();
await new Promise(resolve => setTimeout(resolve, 10000))
console.error("Resuming...");
await client.resume();
await client.setLevel(18);
} catch (err) {
console.error(err);
process.exit(1);
}
})();