-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBleRead.js
37 lines (34 loc) · 1.23 KB
/
BleRead.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
const noble = require("@abandonware/noble");
const hrmServiceUuid = "180d";
const hrmHeartRateCharacteristicUuid = "2a37";
const serviceUuids = [hrmServiceUuid];
const characteristicUuids = [hrmHeartRateCharacteristicUuid];
noble.on("discover", (peripheral) => {
noble.stopScanning();
console.log(
peripheral.address + ", " +
peripheral.advertisement.localName);
peripheral.connect((err) => {
console.log("connected");
peripheral.discoverServices(serviceUuids, (err, services) => {
services.forEach((service) => {
console.log("found service:", service.uuid);
service.discoverCharacteristics(characteristicUuids, (err, characteristics) => {
characteristics.forEach((characteristic) => {
console.log("found characteristic:", characteristic.uuid);
characteristic.read((error, data) => {
const value = data.readUInt8(1);
console.log("read characteristic value:", value);
peripheral.disconnect((err) => {
console.log("disconnected");
process.exit();
});
});
});
});
});
});
});
});
console.log("scanning...");
noble.startScanning(serviceUuids, false);