blueutil icon indicating copy to clipboard operation
blueutil copied to clipboard

Fix BT devices inquiry

Open RaphaelKn opened this issue 2 years ago • 12 comments

RaphaelKn avatar Mar 27 '22 11:03 RaphaelKn

Hi @toy Do you have some time to take a look ? Thanks!

RaphaelKn avatar Mar 31 '22 15:03 RaphaelKn

Sorry for not replying earlier. I tried the code, but something was misbehaving in bluetooth framework (inquiry didn't work at all, with and without changes, and through pref pane), so I left it till weekend to hopefully investigate.

toy avatar Mar 31 '22 21:03 toy

Sure thing.. Thanks!

RaphaelKn avatar Apr 03 '22 01:04 RaphaelKn

I was able to reproduce the problem and only on Monterey. Can you please add description to this issue and a changelog entry?

Please tell what was the issue with [inquirer setInquiryLength:args->duration]? If it is removed, as it defaults to 10 seconds, when the problem with too long inquiry doesn't happen (previous versions, fixed in Monterey or afterwards, it also seems it doesn't happen always), the behaviour will be odd.

toy avatar Apr 04 '22 20:04 toy

So i don't have a good answer for why the [inquirer setInquiryLength:args->duration] isn't working - it seems likely to be an apple bug.

The default is set anyway to be 10 inside your code in any case by - https://github.com/RaphaelKn/blueutil/blob/90ba4dd77771acbf0d993670c45f7271a601a540/blueutil.m#L821, no ?

RaphaelKn avatar Apr 05 '22 13:04 RaphaelKn

So i don't have a good answer for why the [inquirer setInquiryLength:args->duration] isn't working - it seems likely to be an apple bug.

I meant why did you comment it out, so is something not working with all other changes if you don't comment it out?

toy avatar Apr 10 '22 23:04 toy

I assume that internally setting the inquiry timeout may be doing also something like [inquirer stop] so to my understanding it's better not to have both mechanisms working as i can't tell how it will behave. Once we figure out that [inquirer setInquiryLength:args->duration] is working again (assuming it's an apple bug, or something in this code), then we can just revet this PR.

RaphaelKn avatar Apr 11 '22 07:04 RaphaelKn

I tried these changes on Monterey 12.3 and even with them blueutil doesn't work. For example the "connect" and "disconnect" commands seem to silently fail. It also seems to be unable to look up a bluetooth device by name.

For example

mta@bayswater ~>blueutil --info 70-bf-92-09-10-b4
address: 70-bf-92-09-10-b4, connected (master, 0 dBm), not favourite, paired, name: "Jabra Talk 45", recent access date: 2022-04-23 03:13:42 +0000
mta@bayswater ~>blueutil --info "Jabra Talk 45"
Device not found by name: Jabra Talk 45

This is using blueutil built from commit 90ba4dd which is the tip of the fix-inquiry branch.

mtalexander avatar Apr 23 '22 03:04 mtalexander

@mtalexander I didn't try the other commands as i don't use blueutil, i was just asked by some friend to check on the inquiry which didn't work for him, and that's what i aim to fix here. Please let me know if the inquiry doesn't work you with this fix (it works for me and for my friend and seems to work for @toy as well). For other issues i think it would be better to open a separate issue, but that's up to @toy

RaphaelKn avatar Apr 24 '22 07:04 RaphaelKn

@mtalexander For connect/disconnect, please check #58, #62 and #64. For not getting info by name please create a new issue.

@RaphaelKn I finally checked on earlier mac and without [inquirer setInquiryLength:args->duration] the inquiry finishes after 10-15 seconds even if requested to run for longer, so please enable it. I also don't like that according to documentation stop should interrupt also updating found device names, which makes me think if it would be better to set inquiry length to duration, but set dispatch_after to duration + 5 (random number) seconds, though not sure.

toy avatar Apr 24 '22 17:04 toy

thanks @RaphaelKn, for your PR, I was able to use this app with Mojave on my intel mac and finally paired and old apple wireless keyboard.

Also I checked with the -T option and worked for me very well.

mliradelc avatar Oct 31 '23 11:10 mliradelc

@mliradelc So the released version doesn't work, but this PR fixes it? And what do you mean by -T option?

toy avatar Oct 31 '23 23:10 toy