diff --git a/src/hub.ts b/src/hub.ts index 684fd5c..9e3df17 100644 --- a/src/hub.ts +++ b/src/hub.ts @@ -30,6 +30,7 @@ export class Hub extends EventEmitter { protected _batteryLevel: number = 100; protected _voltage: number = 0; protected _current: number = 0; + protected _rssi: number = -60; protected _bleDevice: IBLEDevice; @@ -100,6 +101,15 @@ export class Hub extends EventEmitter { } + /** + * @readonly + * @property {number} rssi Signal strength of the hub + */ + public get rssi () { + return this._rssi; + } + + /** * @readonly * @property {number} voltage Voltage of the hub (Volts) diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index 748fa67..c58e2c6 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -58,6 +58,7 @@ export class LPF2Hub extends Hub { this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x02, 0x02])); // Activate button reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x03, 0x05])); // Request firmware version this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x04, 0x05])); // Request hardware version + this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x05, 0x02])); // Activate RSSI updates this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x06, 0x02])); // Activate battery level reports this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x0d, 0x05])); // Request primary MAC address this.emit("connect"); @@ -269,6 +270,14 @@ export class LPF2Hub extends Hub { } else if (data[3] === 0x04) { this._hardwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5)); + // RSSI update + } else if (data[3] === 0x05) { + const rssi = data.readInt8(5); + if (rssi !== 0) { + this._rssi = rssi; + this.emit("rssiChange", this._rssi); + } + // primary MAC Address } else if (data[3] === 0x0d) { this._primaryMACAddress = LPF2Hub.decodeMACAddress(data.slice(4, 10)); diff --git a/src/nobledevice.ts b/src/nobledevice.ts index 383b193..5b30d30 100644 --- a/src/nobledevice.ts +++ b/src/nobledevice.ts @@ -28,7 +28,7 @@ export class NobleDevice extends EventEmitter implements IBLEDevice { this._noblePeripheral = device; this._uuid = device.uuid; device.on("disconnect", () => { - this._connected = false; + this._connecting = false; this._connected = false; this.emit("disconnect"); }); diff --git a/src/webbledevice.ts b/src/webbledevice.ts index f38049b..cf8a337 100644 --- a/src/webbledevice.ts +++ b/src/webbledevice.ts @@ -27,7 +27,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEDevice { this._uuid = device.device.id; this._name = device.device.name; device.device.addEventListener("gattserverdisconnected", () => { - this._connected = false; + this._connecting = false; this._connected = false; this.emit("disconnect"); });