noble / noble

A Node.js BLE (Bluetooth Low Energy) central module
MIT License
3.4k stars 870 forks source link

Tracking macOS High Sierra Support #679

Closed piotrdubiel closed 6 years ago

piotrdubiel commented 6 years ago

Setup noble: 1.8.1 node: 7.7.2 macOS High Sierra 10.13 GM (17A362a)

Description Current, Yosemite bindings no longer work on High Sierra, supposedly because of changes in CoreBluetooth. Here 'stateChange' events now comes as kCBMsgId4 I used method stated in https://github.com/sandeepmistry/bleno/issues/177#issuecomment-195975227, but haven't managed to compile https://github.com/sandeepmistry/osx-ble-peripheral on 10.13 SDK, because of linking error

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_CBXpcConnection"

which might mean it was removed.

zwaldowski commented 6 years ago

High Sierra has replaced blued with bluetoothd, and with it a replacement to the previous XPC messages.

mbruschi commented 6 years ago

@zwaldowski do you have any idea what we have to do in order to make it work again? How can I help?

As far as I know the noble on Linux works with bluetoothd am I right?

Edit: What I could figure out so far:

  1. We have to catch the osVersion here: https://github.com/sandeepmistry/noble/blob/master/lib/mac/bindings.js
  2. We have to create a highsierra.js file and replace com.apple.bluehd with com.apple.bluetoothd here https://github.com/sandeepmistry/noble/blob/master/lib/mac/yosemite.js#L18
  3. Then see if the protocol changed and if it did, we have to reverse engineer the message-id's: https://github.com/sandeepmistry/bleno/issues/177#issuecomment-195975227

Does someone agree on this?

Axadiw commented 6 years ago

We're working on it here: https://github.com/PolideaInternal/noble/tree/macos_highsierra

Unfortunately https://github.com/sandeepmistry/osx-ble-peripheral isn't working anymore on HighSierra (we're not able to swizzle CBXpcConnection class there).

We've been sniffing XPC traffic using http://newosxbook.com/tools/XPoCe.html and decompiling bluetoothd using https://www.hopperapp.com and we've managed to retrieve some of the correct ID's that are being sent byt XPC to bluetoothd on HighSierra.

If someone could test it, and fix all not working calls, we'll be very appreciated.

Generally I think that this XPC method should be abanddoned in noble and some legit implementation basing on CoreBluetooth should be used there (I think that https://github.com/sandeepmistry/noble/tree/more-test is a good start for it)

jacobrosenthal commented 6 years ago

I have a hopefully complete high sierra PR in https://github.com/sandeepmistry/noble/pull/727

Needs testing though.

You can have npm install from my git branch with npm install git://github.com/jacobrosenthal/noble.git#highsierra or edit your package.json and add the branch to your dependencies

  "dependencies": {
    "noble": "git://github.com/jacobrosenthal/noble.git#highsierra"
  }
Ezor commented 6 years ago

@jacobrosenthal Just tested it on a little project and it works like a charm

klategan commented 6 years ago

@jacobrosenthal Working perfectly. Thanks!

stefanclayster commented 6 years ago

Ive tried it with muse-lsl (https://github.com/urish/muse-lsl) and it connects to the device but wont get any data from the characteristics. Has anything changed in its interface?

jacobrosenthal commented 6 years ago

@stefanclayster can you enable debug logging for the bindings layer and report back DEBUG=highsierra-bindings node yourscripthere.js

jacobrosenthal commented 6 years ago

ping @stefanclayster you're the only one to report in with problems. Were you able to solve those? If not can you enable debugging by running like DEBUG=highsierra-bindings node yourscripthere.js

stefanclayster commented 6 years ago

Sorry I haven't responded yet, I am on a skiing holiday.I did run with the debug flag and i got too much data outputted to know where the bug is/what is relevant. I will have to investigate further.

jacobrosenthal commented 6 years ago

Please send that log over, well look at it.

On Mon, Jan 8, 2018 at 4:07 PM, stefanclayster notifications@github.com wrote:

Sorry I haven't responded yet, I am on a skiing holiday.I did run with the debug flag and i got too much data outputted to know where the bug is/what is relevant. I will have to investigate further.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sandeepmistry/noble/issues/679#issuecomment-356125478, or mute the thread https://github.com/notifications/unsubscribe-auth/AAb0dN4s1SahT9JldegRrTcLOX-A_3bKks5tIp-ZgaJpZM4PcTX6 .

stefanclayster commented 6 years ago

debuglog.txt Here is the log.

stefanclayster commented 6 years ago

I reckon that log was too short. Longer version below with data from characteristics.

debuglog2.txt

jacobrosenthal commented 6 years ago

@stefanclayster Seems like all xpcids are being caught and you're getting a ton of reads (83). Make sure you pull fresh? Its had some changes, but otherwise I think youll need to poke around and debug in this function to see why that function or the emit inside it isnt being called for you https://github.com/sandeepmistry/noble/pull/727/files#diff-81c793ee25a4a5820d33c0d4c9beeea0R519

To explain the log: 48s peripheral founds 45 stop scanning 57 response to stop scanning we dont do anything with 46 49 connect/connected 62 72 discover services / did discoverservices 75 discover characteristics 60 params update we dont do anything with 77 response discover characteristics 81 notify / 86 response notify on a bunch of chars 79 write value a couple times 83 response read value over and over again

stefanclayster commented 6 years ago

Cool! Ill dig into it! Thank you.

stefanclayster commented 6 years ago

Is the emitter on 'characteristicvaluechanged' removed? I cannot find it in the repo at all (github search) while it exists in noble repo.

jacobrosenthal commented 6 years ago

That appears to be a web bluetooth specific event thats consumed by the web bluetooth bindings layer. Shouldn't have anything to do with macosx support.

High Sierra consumes the kCBMsgId83 event for reads and subscribe notifications triggering 'read' emits to characteristic.js which are consumed in noble.js and trigger 'data' emits for user facing code.

weisjohn commented 6 years ago

Switching to @jacobrosenthal's fork allowed me to get events right away. Thanks.

ainthek commented 5 years ago

Do we need another patch for Mohave now ?