diff --git a/src/poweredup-browser.ts b/src/poweredup-browser.ts index 583ddda..152b5d4 100644 --- a/src/poweredup-browser.ts +++ b/src/poweredup-browser.ts @@ -130,9 +130,9 @@ export class PoweredUP extends EventEmitter { private _determineLPF2HubType (device: IBLEAbstraction): Promise { - return new Promise((resolve) => { + return new Promise(async (resolve) => { let buf: Buffer = Buffer.alloc(0); - device.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, (data: Buffer) => { + await device.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, (data: Buffer) => { buf = Buffer.concat([buf, data]); while (buf[0] <= buf.length) { const len = buf[0]; diff --git a/src/webbleabstraction.ts b/src/webbleabstraction.ts index 09a359d..9e09275 100644 --- a/src/webbleabstraction.ts +++ b/src/webbleabstraction.ts @@ -85,7 +85,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEAbstraction { } - public subscribeToCharacteristic (uuid: string, callback: (data: Buffer) => void) { + public subscribeToCharacteristic (uuid: string, callback: (data: Buffer) => void): Promise { if (this._listeners[uuid]) { this._characteristics[uuid].removeEventListener("characteristicvaluechanged", this._listeners[uuid]); } @@ -108,7 +108,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEAbstraction { callback(data); } - this._characteristics[uuid].startNotifications(); + return this._characteristics[uuid].startNotifications(); }