noble icon indicating copy to clipboard operation
noble copied to clipboard

scanStart event is emitted when adapter is not scanning.

Open hkayann opened this issue 2 years ago • 1 comments

try {
 var e = await noble.stopScanningAsync()
 send(e)
} catch(err) {
 done(err)
};
try {
 var e = await peripheralArray[index].connectAsync()
 send(e)
} catch(err) {
 done(err)
};

After connecting, for some reason scanStart event is emitted even thought the adapter does not scan.

hkayann avatar Mar 18 '22 11:03 hkayann

Was facing the same issue on ubuntu 22. Here is an easy fix:

edit hci-socket's gap implementation https://github.com/abandonware/noble/blob/master/lib/hci-socket/gap.js#L114 add this._scanState = 'started' before this.emit('scanStart', this._scanFilterDuplicates); line 114.

Explanation behind the edit in case anyone wants to do a pull req.

when connecting to a peripheral, Hci.prototype.createLeConn creates LE Add Device To Accept List, LE Set Scan Parameters and LE Set Scan Enable events. receives a LE Advertising Report commands related to the peripheral you want to connect to, then executes another LE Set Scan Enable to turn off scan and proceed with LE Create Connection command.

Without setting this._scanState = 'started' we loose track of search status, so the next update that comes to Gap.prototype.onLeScanEnableSetCmd does not reflect the state properly.

ahoura avatar Nov 24 '22 20:11 ahoura