toy / blueutil

CLI for bluetooth on OSX: power, discoverable state, list, inquire devices, connect, info, …
https://github.com/toy/blueutil
Other
969 stars 52 forks source link

A1016 Keyboard and Ventura #71

Open jwrw opened 1 year ago

jwrw commented 1 year ago

I've a M1 Mac with 13.1 Ventura. I originally used blueutil to get my nice old A1016 keyboard connected. However, something changed and I ended up losing connectivity, deleted the pairing but couldn't get it back. Judging by comments on various forums, there's been a lot of work around the BT stack that has been breaking things. On the latest O/S, blueutil itself does seem to behave slightly differently than I might have expected. (e.g. why do I have to turn off BlueTooth to get the scan results to appear?)

Back to the A1016... I'm not sure if this counts as an issue but I wanted to share something that worked. I think the keyboard sends a PIN when you connect, which may conflict with the newer BT standards. If you just do blueutil --pair <kdb Mac> 0000 then switch on the keyboard and hit <return> on the A1016, you get an authentication failure.

BUT If you immediately repeat the blueutil --pair <kdb Mac> 0000 command and type 0000<return> on the A1016 keyboard, pairing is successful. You can then connect the keyboard using the BT panel in System Settings.

[NB.You will clearly need a connected keyboard to enter the blueutil command]

toy commented 1 year ago

Normally it is expected for devices that have a screen to present the pin for confirmation and for devices that can input numbers to input the same pin. So blueutil --pair ID PIN expects for pairing with a keyboard the PIN to be typed on the keyboard. Not sure if PIN can be only numbers on any characters, but not reqired to be 0000. You then should be able to also use blueutil --connect ID to connect without opening System Setting/System Preferences.

jwrw commented 1 year ago

Agree - the behaviour is 'abnormal' - it's quite an old keyboard. Other keys are ignored when you switch it on but the first press of return initiates a pairing with key 0000 from the keyboard. This fails, because blueutil like most hosts expects to initiate pairing with a keyboard. I guess any PIN would do in the command - as the first one is ignored when pairing fails and you can enter the second one on the A1016. Using the standard Apple Bluetooth pairing, MacOS throws up a PIN code in a pop-up when you initiate the connection with the <return> key. However, this immediately then disappears, as the keyboard sends its '0000' PIN and authentication fails. So blueutil has certainly dug me out of a hole and allowed be to get paired! Thx!

vlastoun commented 1 year ago

I have the same problem with Logitech mouse MX3 and keyboard Logitech Mechanical. I am not able to --inquiry or --pair them ( they can be paired over macos bluetooth ui). I found that its address is changed after every successfull paired atempt. Last two digits are increasing. But when running inquiry it does not work.. If i guess next correct adress then I try to pair and no success. I also try to put pin there and no success.

Is there any way I can debug it? or more verbose?

toy commented 1 year ago

@vlastoun One of the first links in search suggests that Logitech devices can do something odd about their mac address https://unix.stackexchange.com/q/690808. Problem with pairing is maybe the yet unresolved issue on newer osx versions.

a2mta commented 1 year ago

Hello @jwrw. I wanted to ask if you were able to do that trick once or if it's something that works all the time. It's just I bought the same keyboard the other day and was disappointed by the lack of macos support and don't want to throw it in the closet because of that. I have the same issue you described with almost the same setup (M1 mac pro with macos Ventura 13.4.1), and I could not reproduce your solution. blueutil just fails with two different errors ("Unspecified Error" and "No connection") Maybe it has something to do with the timings when you have to press "return" or something else. ?

vlastoun commented 1 year ago

No, I have never resolved my issue. It is happening for all my Logitech devices 24. 6. 2023 v 23:17, Dmitry @.***>: Hello @jwrw. I wanted to ask if you were able to do that trick once or if it's something that works all the time. It's just I bought the same keyboard the other day and was disappointed by the lack of macos support and don't want to throw it in the closet because of that. I have the same issue you described with almost the same setup (M1 mac pro with macos Ventura 13.4.1), and I could not reproduce your solution. blueutil just fails with two different errors ("Unspecified Error" and "No connection") Maybe it has something to do with the timings when you have to press "return" or something else. ?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

tamruta commented 9 months ago

I was able to connect my A1061 with M2 Mac Pro 2022 using blueutil --pair <kdb Mac> 0000

I've done this a few times now and my pairing has been stable. The kb connects automatically to my mac once I have paired

edit: 13.1 Ventura

toy commented 9 months ago

@tamruta Great to hear that it works for you. Do you mean A1016? Also see my comment about the pin.

jwrw commented 9 months ago

I think I managed the trick with the A1016 a couple of times - but once I got it paired I didn't want to risk trying it over and over. It is quite likely that you need to be a little lucky with the timing?!?!

tamruta commented 9 months ago

@toy Sorry I meant A1016

When my kb is low on battery it disconnects more easily. If I don't type something as soon as it connects, the connection is lost. In that situation I just keep an eye on the green light by the power switch to connect.

I think I needed more luck to get the mac address of the kb than to pair with it. I was using --inquiry and it wouldn't show up unless the kb was switched as soon as I had ran --inquiry.

toy commented 9 months ago

@tamruta Unless you unpair the keyboard, you shouldn't need to pair it to connect, so --connect NAME should be enough, also you can use name and not the address for that.

tamruta commented 9 months ago

@toy Ah sorry for the confusion, I was just mentioning that for notes. I've not had any trouble connecting once it has been paired. Thanks for the tip! I haven't tried using the name

strangerbit commented 8 months ago

Hello @jwrw. I wanted to ask if you were able to do that trick once or if it's something that works all the time. It's just I bought the same keyboard the other day and was disappointed by the lack of macos support and don't want to throw it in the closet because of that. I have the same issue you described with almost the same setup (M1 mac pro with macos Ventura 13.4.1), and I could not reproduce your solution. blueutil just fails with two different errors ("Unspecified Error" and "No connection") Maybe it has something to do with the timings when you have to press "return" or something else. ?

I have exactly the same issue.

blueutil --pair 00-01-A4-xx-xx-xx 0000 Failed to pair "00-01-A4-xx-xx-xx" with error 0x02 (No Connection)

jwrw commented 8 months ago

Config

Apple Studion M1 Max, Sonoma 14.0 (recently upgraded from Ventura but steps are the same)
blueutil 2.9.1 Apple Wireless Keyboard (aka A1016) 1.1.0

(My A1016 was connected and working fine so I went to bluetooth settings, clicked the little 'i' next to the keyboard and selected 'Forget Device...' and clicked the scary red 'Forget Device' on the warning dialog.)

Preamble

Plug in a generic USB keyboard - all typing is on that keyboard unless specified. If you're doing this on a laptop, then you don't need the USB keyboard, the input will be on that laptop keyboard.

Get the keyboard mac address

Terminal Terminal 2 A1016 Note
Open a Terminal window Open a second terminal window A1016 switched off
Enter blueutil --inquiry Get 1 line confirmation inquiry is running
Switch on keyboard
After 10s enter blueutil -p 0 Power off bluetooth
Results of inquiry now appear
Enter blueutil -p 1 Put bluetooth back on
Find mac address of keyboard here You can close Terminal 2 now Switch off keyboard

Pair the A1016

You're using the USB (or laptop) keyboard to enter Terminal commands and the A1016 is switched off. Terminal A1016 Note
Type blueutil --pair 00-0a-95-xx-xx-xx 0000 BUT DON'T HIT 'Enter' YET
Swtch on keyboard
Hit 'Enter' Within a few seconds
Get message Input pin 0000 on "Apple Wireless Keyboard" (00-0a-95-xx-xx-xx)
Hit 'Enter'
Get message Failed to pair "00-0a-95-xx-xx-xx" with error 0x1f (Unspecified Error)
Fairly quickly press 'Up Arrow' then 'Enter' to repeat the blueutil --pair 00-0a-95-xx-xx-xx 0000 command This is just what I did - I don't know how fast you need to be but a few seconds seems OK
Get message Input pin 0000 on "Apple Wireless Keyboard" (00-0a-95-xx-xx-xx)
Type 0000 and press 'Enter' Send the PIN from the A1016, again fairly quickly after entering the pair command

If you have the bluetooth settings open you should see the keyboard appear as connected. Hit 'Enter' and it should all be OK.

adamesq commented 8 months ago

Unfortunately, I cannot get this to work on M2 Mac Mini running Ventura...I've tried over 20 times. I've got the MAC address using the method above (and double-checked with a mid-2014 MBP), but almost always gives a no connection error on the M2. Occasionally, I get Unspecified Errors, but NEVER get prompted for the Input pin. Just a big fail on this end.

toy commented 8 months ago

@jwrw About «Get the keyboard mac address» - inquiry gets stuck or just takes much more time? About «Pair the A1016» - does it not work if typing 0000 and pressing 'Enter' on first attempt?

@adamesq Do you have bluetooth permission on for your terminal? See https://github.com/toy/blueutil/issues/82#issuecomment-1772548214

jwrw commented 8 months ago

Hi @toy, I tried leaving the command for a good 10 minutes and got no response, other than the initial confirmation

~ % blueutil --inquiry
2023-10-31 09:17:28.028 blueutil[81517:1660588] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x6000026bc080

If I leave the command for a little time (e.g. 1 minute) then try the blueutil -p off ; blueutil -p on trick, I get to see only the BT devices that are not connected (i.e. I don't see the BT keyboard and mouse that are connected)

In this case the output is like...

~ % blueutil --inquiry
2023-10-31 09:32:36.621 blueutil[83381:1678866] -[IOBluetoothDeviceInquiry initWithDelegate:] -  0x6000001c8050
address: 90-0f-0c-xx-xx-xx, not connected, not favourite, not paired, name: "the big TV", recent access date: 2023-10-31 09:32:58 +0000
address: 00-1d-df-xx-xx-xx, not connected, not favourite, not paired, name: "SoundSticks Wireless", recent access date: 2023-10-31 09:32:58 +0000
2023-10-31 09:32:58.125 blueutil[83381:1678866] -[IOBluetoothDeviceInquiry dealloc] -  0x6000001c8050
jwrw commented 8 months ago

Re: pairing - I tried all sorts of combinations, certainly 0000<enter> was the first thing, but the keyboard BT doesn't seem to be active until that first <enter>. Doing it a second time immediately after, as per the above, was what worked for me.

adamesq commented 8 months ago

@jwrw About «Get the keyboard mac address» - inquiry gets stuck or just takes much more time? About «Pair the A1016» - does it not work if typing 0000 and pressing 'Enter' on first attempt?

@adamesq Do you have bluetooth permission on for your terminal? See #82 (comment)

Thank you for the suggestion. I had not, but after adding the permission, I now get Connection Errors. In both cases (before and after enabling, I never get to the request to enter 0000. 🤔

EDIT: After posting the reply above, I tried just hitting "enter" after inputting the pair request. Between the connection errors, I started seeing the request to enter 0000. After about 15 randomly timed requests, I hit "0000 " while waiting for a connection error. It just happened to be timed correctly. 'Input pin 0000 on "00:0x:xx:xx:xx:xx"' just happened to show up while I was inputing and...now connected. Kinda hit and miss. I appreciate the help here, but not the hoops we are all having to jump through in lieu of a simple fix in the Mac OS!

lnealan commented 8 months ago

Thank you for the suggestion. I had not, but after adding the permission, I now get Connection Errors. In both cases (before and after enabling, I never get to the request to enter 0000. 🤔

EDIT: After posting the reply above, I tried just hitting "enter" after inputting the pair request. Between the connection errors, I started seeing the request to enter 0000. After about 15 randomly timed requests, I hit "0000 " while waiting for a connection error. It just happened to be timed correctly. 'Input pin 0000 on "00:0x:xx:xx:xx:xx"' just happened to show up while I was inputing and...now connected. Kinda hit and miss. I appreciate the help here, but not the hoops we are all having to jump through in lieu of a simple fix in the Mac OS!

I had the same issue of never getting the Input pin prompt and was only able to finally get it after resetting the PRAM on my macbook pro. Once that was working i was able to successfully pair as well.

hou-mon commented 8 months ago

I too had the same issues of never getting the input pin prompt. A solution that's worked for me and seems reproducible was to add the device as a favorite BEFORE attempting to pair. The keyboard doesn't need to be on to do this:

blueutil --add-favourite 00-0a-95-xx-xx-xx

From that point I would follow @jwrw pair instructions.

paulzaptec commented 7 months ago

I had a similar problem with only ever getting "No Connection" or "Unspecified Error" on macOS Sonoma / MBP M1. This seems to be because I had the Bluetooth settings window open.

Closing the Bluetooth settings window allowed me to successfully pair an A1016 keyboard with: blueutil --pair 00-0a-95-xx-xx-xx 0000

dariolob commented 7 months ago

Hey there. I've tried every possibile combination but I'm still unable to pair my A1016 to Sonoma 14.1 on Mac Mini M1. I followed @jwrw instructions religiously, bluetooth permissions are in place, I've tried with the BT settings window both open and closed, also tried adding the device as a favorite like suggested by @hou-mon... nothing. Do I have to give up? :(