Apple Magic Keyboard 2 Not Working Properly Over Bluetooth (16.10)

16.10applebluetoothkeyboard

I've already taken a look at these posts:
How do I get the Apple Wireless Keyboard Working in 10.10? and
How do I get the Apple Wireless Keyboard Working in 10.10?, but none seem to resolve the problem I'm facing.

In brief, I am able to connect to the keyboard and the keyboard works just fine. But after I shutdown the system and turn it on again, the keyboard won't be connected to the system anymore.

My guess is that Apple Magic Keyboard 2 thinks it's connected to the system so it's not in pairing mode anymore and hence not receiving any connections, but actually it's not connected. (Maybe ubuntu lost connection ? Maybe when shutting down last night, ubuntu forogt to properly disconnect the keyboard) ?

First when it was not connected (after I turned on the PC), it was listed in bluetooth devices and present in bluetoothctl devices. Also info showed it as paired and trusted, but not connected. I first tried to issue connect MAC_ADDR, but the following was thrown:

bluetoothctl:

Failed to connect: org.bluez.Error.Failed

syslog:

Can't get HIDP connection info
connect error: Host is down (112)

I then tried removing the device and connecting it back again, but after I removed it from bluetoothctl, It's not even detected anymore ! (That's why I guessed the keyboard is not in pairing mode anymore and thinks it's connected)

Do you have any idea how can I get it to work reliably ? I can't waste an hour every day or so after each Off/On of the system.

Thanks !

Best Answer

Okay, answering my own question here, I seem to have found a way that works, consistently.

Everytime the bluetooth has problems connecting, do the following:

  1. Remove the already paired device from bluetooth UI (select it, and click -, this step is definitely important)
  2. Do the following in a terminal:

    bluetoothctl
    ->power off
    ->power on
    ->scan on // this should find the keyboard in seconds, if It didn't, turn the keyboard off and on again.

    ->trust MAC_ADDR
    ->pair MAC_ADDR
    ->connect MAC_ADDR

This procedure has worked consistently for me. You might be able to remove the devices also from the bluetoothctl's CMD (remove MAC_ADDR), but it didn't work for me once and I found removing from the UI more consistent.

Hope this helps someone.