sandeepmistry / node-bbc-microbit-io

Johnny-Five IO Plugin for the BBC micro:bit
MIT License
17 stars 1 forks source link

Led-Matrix, Compass and other examples fail #1

Open steinerj opened 7 years ago

steinerj commented 7 years ago

Hi,

I've just given this project a spin and noticed that some examples work (e.g. button & thermometer) while others fail with the error below. I just had a quick look and I've seen that the parent project (node-bbc-microbit) was changed significantly since the last commit in this project... I just wanted to know if anyone is aware of changes, which might help me debug this, before I dive in properly.

1487239001614 Device(s) BBC micro:bit 1487239003525 Connected BBC micro:bit 1487239003540 Repl Initialized

clearing matrix C:\projects\nativescript\iot\node-bbc-microbit-io\node_modules\noble-device\lib\noble-device.js:108 return callback(new Error('service uuid ' + serviceUuid + ' not found!')); ^

TypeError: callback is not a function at BBCMicrobit.NobleDevice.writeDataCharacteristic (C:\projects\nativescript\iot\node-bbc-microbit-io\node_modules\noble-device\lib\noble-device.js:108:12 ) at BBCMicrobit.LedService.writeLedMatrixState (C:\projects\nativescript\iot\node-bbc-microbit-io\node_modules\bbc-microbit\lib\led-service.js:18:8) at LedMatrix.clear (C:\projects\nativescript\iot\node-bbc-microbit-io\lib\controllers\led-matrix.js:9:23) at Board. (C:\projects\nativescript\iot\node-bbc-microbit-io\examples\led-matrix.js:16:10) at emitNone (events.js:91:20) at Board.emit (events.js:185:7) at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickDomainCallback (internal/process/next_tick.js:122:9)

steinerj commented 7 years ago

Okay, I'm pretty sure I've sufficiently investigated it. It ultimately seems to be related to what @urisha mentioned in this PR: https://github.com/sandeepmistry/node-bluetooth-hci-socket/pull/31

There seems to be an issue with Intel BT chipsets (confirmed by superficial googling ;)). They seem to require a scan to have stopped, before being able to connect to a device. Otherwise they'd throw a "Connection Rejected due to Limited Resources" error. The error was thrown at random due to a race condition with the stopping of the scan and the actual connection to the device.

I've created a PR - see above - which forces a stopScan before continuing to connect. It's not ideal, since this might make the start up for non-Intel chipsets a bit slower but well...