node-bluetooth-serial-port icon indicating copy to clipboard operation
node-bluetooth-serial-port copied to clipboard

mac osx monterrey support

Open chipimix opened this issue 3 years ago • 20 comments

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 avatar May 25 '22 13:05 chipimix

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

chipimix avatar May 25 '22 14:05 chipimix

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.

eelcocramer avatar May 25 '22 18:05 eelcocramer

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 🤞

chipimix avatar May 25 '22 18:05 chipimix

Thanks for the link. I will look into it.

eelcocramer avatar May 25 '22 21:05 eelcocramer

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 avatar May 26 '22 12:05 eelcocramer

Added the wip code to branch issue-404.

eelcocramer avatar May 26 '22 13:05 eelcocramer

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.

chipimix avatar May 26 '22 13:05 chipimix

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 avatar May 26 '22 17:05 eelcocramer

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

eelcocramer avatar May 26 '22 17:05 eelcocramer

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.

chipimix avatar May 27 '22 11:05 chipimix

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 avatar May 27 '22 14:05 eelcocramer

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 ;-)

eelcocramer avatar May 27 '22 18:05 eelcocramer

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

chipimix avatar Jun 01 '22 08:06 chipimix

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.

eelcocramer avatar Jun 22 '22 08:06 eelcocramer

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

chipimix avatar Jun 22 '22 10:06 chipimix

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

fromage9747 avatar Mar 17 '24 06:03 fromage9747