Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac osx monterrey support #404

Open
chipimix opened this issue May 25, 2022 · 20 comments
Open

mac osx monterrey support #404

chipimix opened this issue May 25, 2022 · 20 comments

Comments

@chipimix
Copy link

chipimix commented May 25, 2022

Hi!
Package inquire/inquireSync methods stop working when m1 mac osx updates to monterrey.
paired.js example script is the only one that keeps working.

I was using this fork: https://github.com/phablulo/node-bluetooth-serial-port.git
But the issue is the same in this repository's next-release branch.
If I run node examples/sync.js it outputs:

start inquiry
2022-05-25 14:38:10.317 node[11882:378464] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x13965a560
2022-05-25 14:38:10.318 node[11882:378464] -[IOBluetoothDeviceInquiry dealloc] -  0x13965a560

I'm using node v16.14.2.
I'm pretty sure this is an issue with the objective c files which stopped working in mac osx monterrey

@chipimix
Copy link
Author

if I run the node examples/async.js it outputs:

start inquiry
2022-05-25 15:43:49.938 node[16693:422607] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x13c658080
should be displayed before the end of inquiry
inquiry finished

Alternatively, blueutil cli seems to be working. If I run blueutil --inquiry
I get:

2022-05-25 15:44:49.519 blueutil[16705:422958] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x1378044c0

address: 98-d3-21-fc-8a-e3, not connected, not favourite, paired, name: "BITalino-8A-E3", recent access date: 2022-05-25 14:45:15 +0000
address: d0-d0-03-7b-a7-8c, not connected, not favourite, not paired, name: "[TV] Samsung 7 Series (65)", recent access date: 2022-05-25 14:45:15 +0000
address: a0-51-0b-38-42-89, not connected, not favourite, not paired, name: "PORTSGONCALVES", recent access date: 2022-05-25 14:45:15 +0000
2022-05-25 15:45:15.718 blueutil[16705:422958] -[IOBluetoothDeviceInquiry dealloc] -  0x1378044c0

@eelcocramer
Copy link
Owner

Thank you for posting your findings. I have yet to find a solution for the inquiry task. Also I'm not sure if the current implementation for communicating with a BT device still work.

@chipimix
Copy link
Author

chipimix commented May 25, 2022

It seems like the inquire method of the BluetoothWorker.mm class is not looping properly.
I am no expert in objective cpp but I found a working script here.
Perhaps someone with more knowledge in objective cpp and building node modules can help 🤞

@eelcocramer
Copy link
Owner

Thanks for the link. I will look into it.

@eelcocramer
Copy link
Owner

The code you linked looks quite nice. Pairing is also part of it and this is currently a missing feature for this module. However I look at the code and the device inquiry code does not look that different from what is in this module. I even tried using their exact code but it still won't work. I guess it has something to do with the thread the module is running in. Where they call CFRunLoopRun() the code blocks until the device inquiry is finished but this module calling CFRunLoopRun() does not block anything. The device inquiry seems to stop immediately without finding any devices.

eelcocramer added a commit that referenced this issue May 26, 2022
@eelcocramer
Copy link
Owner

Added the wip code to branch issue-404.

@chipimix
Copy link
Author

That's great, thank you!

I tested the issue-404 branch and now the sync.js script in the examples directory outputs found devices. Progress! 👍

start inquiry
2022-05-26 14:26:33.674 node[52015:725523] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x112f05600
found 2 devices
2022-05-26 14:26:46.825 node[52015:725523] -[IOBluetoothDeviceInquiry dealloc] -  0x112f05600
found device: 98-d3-21-fc-8a-e3 with address: 98-d3-21-fc-8a-e3
found device: a0-51-0b-38-42-89 with address: a0-51-0b-38-42-89
inquiry finished
should be displayed after the end of inquiry

Having said that, connection attempts still resulted in failure.

@eelcocramer
Copy link
Owner

Oh wow. It did not seem to work when I tried it. Maybe there where no devices in reach. I will try again later.

@eelcocramer
Copy link
Owner

Are the devices you are trying to connect to already paired?

@chipimix
Copy link
Author

I did not try to connect to any device. The examples/sync.js script pretty much runs the rfcomm.inquireSync(); method and creates handlers for 'found' and 'finished' events.
Additionally, I tested the same script again after removing all previously paired devices:
image
And it still worked:

start inquiry
2022-05-27 12:39:21.788 node[4524:26501] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x6000030080e0
found 7 devices
2022-05-27 12:39:40.036 node[4524:26501] -[IOBluetoothDeviceInquiry dealloc] -  0x6000030080e0
found device: d0-7e-35-c9-64-08 with address: d0-7e-35-c9-64-08
found device: b0-be-83-07-e1-49 with address: b0-be-83-07-e1-49
found device: 20-1b-88-7c-06-48 with address: 20-1b-88-7c-06-48
found device: 98-d3-21-fc-8a-e3 with address: 98-d3-21-fc-8a-e3
found device: a0-51-0b-38-42-89 with address: a0-51-0b-38-42-89
found device: 00-1b-63-53-c8-21 with address: 00-1b-63-53-c8-21
found device: a0-78-17-8e-9f-a7 with address: a0-78-17-8e-9f-a7
inquiry finished
should be displayed after the end of inquiry

Your changes seem to have fixed inquireSync() method 👍 However, the inquire() method still doesn't work.

The findSerialPortChannel method works only if the device is already paired to the OS (previously it would prompt an alert message which asked the user to input the device PIN);
The connect method is not working.

@eelcocramer
Copy link
Owner

Thanks for the update. For me the sync script never exits but good to hear it is working for you. I think the problem is in letting the inquiry run in the background. I never got to be friends with the objective c threading model 😅

eelcocramer added a commit that referenced this issue May 27, 2022
@eelcocramer
Copy link
Owner

Maybe the bluetooth module of my Mac has issues. I added another attempt to branch issue-404-2. At least the behaviour for me is the same for both sync as async inquiry. Unfortunately that behaviour is not what I'm looking for ;-)

@chipimix
Copy link
Author

chipimix commented Jun 1, 2022

Sorry, I forgot to get back to you.
Objective c threading model implementation seems extra confusing indeed.
I could not replicate the same results on issue-404-2
Here's my output when running sync.js

start inquiry
2022-05-31 18:38:03.515 node[21904:290821] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x600003a7c1e0
before: 1

Alas, it seems it got stuck in the loop because the script never exited

@eelcocramer
Copy link
Owner

FYI I just released v3 of the module without support for MacOS as this issue remains unsolved for the moment.

This way Linux and Windows users can use the module on newer versions of Node. Hopefully the issue with MacOS can be solved and added later.

@chipimix
Copy link
Author

Thanks for the update, I dunno if you want to close this issue or leave it open for posterity sake 👍

@fromage9747
Copy link

Right so, no MacOS support. Saves me from buggering around. Off to Linux I go! Cheers.

@SoCuul
Copy link

SoCuul commented Jun 8, 2024

@eelcocramer has there been any update on this since you last posted? if not, what sort of help do you need to get the macos implementation working?

@eelcocramer
Copy link
Owner

No updates that I'm aware of. If you want to give it a try: it is pretty much trying to debug the example code and the code in these branches I guess. The culprit is most likely in the objective-c code.

@SoCuul
Copy link

SoCuul commented Jun 8, 2024

Is there any suspicion of which functions might be causing the problems? Just don't wanna have to make it harder than it might be.

@eelcocramer
Copy link
Owner

If I remember correctly the problem was in the inquiry phase. Because that comes first there may be issues in the connectivity phase that I'm not aware off.

If you look at the diff of the issue-404 and issue-404-2 branches you can see where I was looking to solve the issue before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants