Wait for second advertisement packet before reading hub name

This commit is contained in:
Nathan Kellenicki 2019-01-29 19:02:11 -08:00
parent ccb4fced4f
commit bbcade6bb3
2 changed files with 15 additions and 9 deletions

View File

@ -31,7 +31,7 @@ export class Hub extends EventEmitter {
protected _ports: {[port: string]: Port} = {};
protected _characteristics: {[uuid: string]: Characteristic} = {};
protected _name: string;
protected _name: string = "";
protected _firmwareInfo: IFirmwareInfo = { major: 0, minor: 0, bugFix: 0, build: 0 };
protected _batteryLevel: number = 100;
protected _voltage: number = 0;
@ -46,7 +46,10 @@ export class Hub extends EventEmitter {
this.autoSubscribe = !!autoSubscribe;
this._peripheral = peripheral;
this._uuid = peripheral.uuid;
// NK: This hack allows LPF2.0 hubs to send a second advertisement packet consisting of the hub name before we try to read it
setTimeout(() => {
this._name = peripheral.advertisement.localName;
}, 200);
}

View File

@ -154,6 +154,8 @@ export class PoweredUP extends EventEmitter {
}
});
// NK: This hack allows LPF2.0 hubs to send a second advertisement packet consisting of the hub name before we try to read it
setTimeout(() => {
debug(`Hub ${hub.uuid} discovered`);
/**
* Emits when a Powered UP Hub device is found.
@ -161,6 +163,7 @@ export class PoweredUP extends EventEmitter {
* @param {WeDo2SmartHub | BoostMoveHub | PUPHub | PUPRemote | DuploTrainBase} hub
*/
this.emit("discover", hub);
}, 500);
}