currantlabs / ble

BSD 3-Clause "New" or "Revised" License
210 stars 178 forks source link

Not working on macOS High Sierra #58

Open ziflex opened 7 years ago

ziflex commented 7 years ago

Hi there,

I know that macOS High Sierra was released just few days ago, but just wanted to warn those of you who develop on Mac. That's what I'm getting from the lib in console:

Unhandled event: xpc.Dict{"kCBMsgId":4, "kCBMsgArgs":xpc.Dict{"kCBMsgArgState":5}}
Scapal commented 7 years ago

Same here

ziflex commented 7 years ago

Same in Noble

https://github.com/sandeepmistry/noble/issues/679

ziflex commented 7 years ago

One of the reasons why it might fail is that Apple switched from com.apple.bluehd to com.apple.bluetoothd.

And here https://github.com/currantlabs/ble/blob/master/darwin/device.go#L80

We explicitly connect to com.apple.bluehd.

ziflex commented 7 years ago

And therefore state event changed from 6 to 4

https://github.com/currantlabs/ble/blob/master/darwin/device.go#L19

ziflex commented 7 years ago

Ok, I made it work Here are my changes:

evtStateChanged               = 4

https://github.com/currantlabs/ble/blob/master/darwin/device.go#L19

d.pm = xpc.XpcConnect("com.apple.bluetoothd", d)
d.cm = xpc.XpcConnect("com.apple.bluetoothd", d)

https://github.com/currantlabs/ble/blob/master/darwin/device.go#L80

I think we could come up with some kind of ConnectionProvider and EventCodesProvider which would be selected based on the version of macOS.

bennesp commented 7 years ago

I tried with that changes, with and without sudo, and it says

Scanning for 5s...
done

without showing any device (and there are ~320 devices BLE that I can see with the Apple Bluetooth Explorer)

What am I doing wrong?

deadprogram commented 7 years ago

This PR from Noble appears to have added the new XPC API calls needed for High Sierra:

https://github.com/sandeepmistry/noble/pull/689

The https://github.com/go-ble/ble fork of ble seems like has some work in this area... @moogle19 can you please fill us in on what you are up to, and how we can help?

deadprogram commented 7 years ago

I just submitted a PR https://github.com/go-ble/ble/pull/2 on the branch that @moogle19 has been working on. It should work on both High Sierra, as well as on El Capitan/Yosemite. Anyone who can help by testing on High Sierra would be most helpful.

deadprogram commented 7 years ago

For anyone interested, please check out https://github.com/go-ble/ble/issues/3

ziflex commented 7 years ago

@deadprogram I will try to test it this week.

ziflex commented 6 years ago

@deadprogram did you guys change public API?

ziflex commented 6 years ago

@deadprogram and btw, is go-ble is intended to be a proxy repo for fixes or a completely independent fork ? Wondering, maybe it's better to move to it.

deadprogram commented 6 years ago

@moogle19 made a change to the API related to Addr or something like that. Relatively small change.

From what I can tell, it is a more active fork and hence why I have mostly moved to it. I guess it is the new "main" fork?

ziflex commented 6 years ago

@deadprogram Ok, I will try to move to it and see how it works on High Sierra.

ziflex commented 6 years ago

@deadprogram it works!