forked from tamberg/fhnw-iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BleWrite.js
38 lines (35 loc) · 1.25 KB
/
BleWrite.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
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);
// TODO: write
// characteristic.read((error, data) => {
// const value = data.readUInt8(0);
// console.log("read characteristic value:", value);
peripheral.disconnect((err) => {
console.log("disconnected");
process.exit();
});
});
});
});
});
});
});
});
console.log("scanning...");
noble.startScanning(serviceUuids, false);