zmkfirmware / zmk

ZMK Firmware Repository
https://zmk.dev/
MIT License
2.64k stars 2.71k forks source link

nice!nano won't connect (authentication failed) #1189

Open jwav opened 2 years ago

jwav commented 2 years ago

I'm using:

After "flashing" the nice!nano with the drag&drop method with an a priori valid UF2 (see below), I can see the nice!nano with the correct label in the Bluetooth devices list. But when trying to connect with btdevice, I get this error :

$ btdevice -c QAZ
Connecting to: QAZ
Error: GDBus.Error:org.bluez.Error.AuthenticationFailed: Authentication Failed

Other attempt, this time with gatttool:

$ sudo gatttool -t random -b DD:F8:C9:79:79:25 -I
[DD:F8:C9:79:79:25][LE]> connect
Attempting to connect to DD:F8:C9:79:79:25
Connection successful
[DD:F8:C9:79:79:25][LE]> 
(gatttool:4142): GLib-WARNING **: 11:26:15.134: Invalid file descriptor.
[DD:F8:C9:79:79:25][LE]>

In this case, the connection is announced as "successful", but it doesn't seem to do anything.

Any idea what's causing this?

Additional notes: This problem arises regardless of how the UF2 is produced (GitHub Actions or local build with west) and no error has ever arisen when compiling with this command : $ west build -p -b nice_nano -- -DSHIELD=qaz

caksoylar commented 2 years ago

Did you connect to another device on the same BT profile (on the keyboard)? See the Bluetooth docs page for details on how BT profiles and pairing works in ZMK if you aren't familiar.

You can also get help faster and interactively on the ZMK Discord server if you prefer.

eXsoR65 commented 2 years ago

I had the same issue on a Mac, as @caksoylar was hitting this may be that the devices tired connect on the same profile. I fixed it by resetting all profiles, turning off bluetooth all device except the one I want to pair, pair to the device, and repeat it for all other devices.

jwav commented 2 years ago

I've just tried the following protocol:

It seems to be an issue unaddressed by @caksoylar 's and @eXsoR65 's posts, if I didn't misunderstand them.

So far I've neglected one possibility because it seemed non pertinent: Does the fact that the nice!nano is powered by its USB connector affect connectivity? Although I don't see why this would matter, you never know until you check the schematics. I'll do this later today.

Ah, and also: it's not connected to a keyboard. But I don't see why this would prevent pairing...

caksoylar commented 2 years ago

Just to double check, are you aware of how ZMK works with multiple BT profiles on the keyboard? In your message you haven't mentioned clearing or switching profiles.

Does the fact that the nice!nano is powered by its USB connector affect connectivity?

There is USB detection logic in ZMK which sometimes fails to detect when a device is power-only or not. But that wouldn't prevent BT pairing and connecting, instead it should connect successfully but try to send keystrokes over USB instead of BT. See the note at https://zmk.dev/docs/behaviors/outputs/#summary.

jwav commented 2 years ago

Got it for the USB thing. Concerning the BT profiles: I've carefully read the article you linked, but I'm not sure I understand what I could do to see if it's a profile problem. Is there a way to browse through BT profiles without simulating a BT_CLR or BT_NEXT press? If not, I guess I'll have to bodge something to simulate these key presses, but even then I'm not sure what I should do with them.

Any pointers on what to do regarding profiles?

eXsoR65 commented 2 years ago

Is there a way to browse through BT profiles without simulating a BT_CLR or BT_NEXT press? If not, I guess I'll have to bodge something to simulate these key presses, but even then I'm not sure what I should do with them.

Any pointers on what to do regarding profiles?

The "profiles" is bluetooth profile that saves your computer/device hardware id etc.. on the Microcontroller's memory. The only way to change/switch profiles or clear aka reset a profile is via key mapping.

In your keymap add the following.

  1. Add the header for bluetooth where other headers are defined.

#include <dt-bindings/zmk/bt.h>

  1. Then somewhere on your keymap, map the key codes related to Bluetooth Profiles.

To clear a profile &bt BT_CLR

To switch to the next profile. &bt BT_NEXT , &bt BT_PRV , or Selecting a profile &bt BT_SEL 0 (note you can have up to 5 profile so BT_SEL 0 - 4)

For an example have a look at this Corne keymap. https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/corne/corne.keymap

jwav commented 2 years ago

Thanks mate, I can't try this right now but it's on the top of the list.

S3NTYN3L commented 2 years ago

Thank you, @caksoylar for the hint and thank you, @eXsoR65, for the hand-holding! I was wracking my brain for about two hours messing with BT front/back-end configs, checking solder joints, etc thinking that was the reason for my constant disconnect/reconnect issue. I ended up shorting the pads (switches not arrived yet) for the corresponding layer change and BT_CLR keys five times, reenabled BT, reset the N!N and it instantly paired.

BenBlumer commented 10 months ago

I had the same issue on a Mac, as @caksoylar was hitting this may be that the devices tired connect on the same profile. I fixed it by resetting all profiles, turning off bluetooth all device except the one I want to pair, pair to the device, and repeat it for all other devices.

This worked for me. Clearing all the other profiles was the ticket unfortunately. Is this a bug? Is there any explanation for this?

BenBlumer commented 10 months ago

Oh!

So -- I dual boot Ubuntu and Windows 11. I had my keyboard paired with W11 (as well as a phone and a tablet). The issue arose when I was trying to pair it with Ubuntu. Clearing all the profiles helped. I then booted W11 and tried to re-pair. It wouldn't do it. This time, I only cleared the profile for the Ubuntu connection. All of a sudden, it would pair.

It seems like ZMK doesn't want to pair to two OSes on the same device (or with the same bluetooth MAC address?).

Is this a fundamental bluetooth issue or a ZMK issue?