diff --git a/src/hub.ts b/src/hub.ts index dff1883..684fd5c 100644 --- a/src/hub.ts +++ b/src/hub.ts @@ -26,6 +26,7 @@ export class Hub extends EventEmitter { protected _name: string = ""; protected _firmwareVersion: string = "0.0.00.0000"; protected _hardwareVersion: string = "0.0.00.0000"; + protected _primaryMACAddress: string = "00:00:00:00:00:00"; protected _batteryLevel: number = 100; protected _voltage: number = 0; protected _current: number = 0; @@ -72,6 +73,15 @@ export class Hub extends EventEmitter { } + /** + * @readonly + * @property {string} primaryMACAddress Primary MAC address of the hub + */ + public get primaryMACAddress () { + return this._primaryMACAddress; + } + + /** * @readonly * @property {string} uuid UUID of the hub diff --git a/src/lpf2hub.ts b/src/lpf2hub.ts index 0e49b33..d8393d1 100644 --- a/src/lpf2hub.ts +++ b/src/lpf2hub.ts @@ -21,6 +21,10 @@ export class LPF2Hub extends Hub { return [t[0], t[1], t.substring(2, 4), t.substring(4)].join("."); } + private static decodeMACAddress(v: Uint8Array) { + return Array.from(v).map((n) => toHex(n, 2)).join(":"); + } + protected _ledPort: number = 0x32; protected _voltagePort: number | undefined; protected _voltageMaxV: number = 9.6; @@ -45,6 +49,7 @@ export class LPF2Hub extends Hub { 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, 0x06, 0x02])); // Activate battery level reports + this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x01, 0x0d, 0x05])); // Request primary MAC address if (this._voltagePort !== undefined) { this._writeMessage(Consts.BLECharacteristic.LPF2_ALL, Buffer.from([0x41, this._voltagePort, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01])); // Activate voltage reports } @@ -267,6 +272,10 @@ export class LPF2Hub extends Hub { } else if (data[3] === 0x04) { this._hardwareVersion = LPF2Hub.decodeVersion(data.readInt32LE(5)); + // primary MAC Address + } else if (data[3] === 0x0d) { + this._primaryMACAddress = LPF2Hub.decodeMACAddress(data.slice(4, 10)); + // Battery level reports } else if (data[3] === 0x06) { this._batteryLevel = data[5];