How do I wake from sleep using a bluetooth Keyboard
I have a Mac book pro, and a Henge dock. The dock is nothing more then a holder that allows you to easily plug in a few devices so you can "dock" your MBP. I also have a Apple wireless keyboard. The keyboard is bluetooth.
The keyboard works fine "normally" but the problem is when I close the lid on my MBP the laptop goes to sleep (this can not be prevented) I place the laptop in the dock (with the lid closed) and I can not wake from sleep (I assume because no bluetooth). If I use my game pad to wake the device from sleep, I get the lock screen password prompt, however I can not actually enter anything because the bluetooth keyboard is not connected.
So how can I wake the Mac Book Pro from sleep using a bluetooth keyboard (the apple wireless keyboard), or failing that, force it to reconnect when the machine resumes so I can type my password?
Here are my hardware details.
Mac Book Pro 6.2 (I know that doesn't normally work but it's a closed hardware platform)
Bus 001 Device 008: ID 050d:0017 Belkin Components B8T017 Bluetooth+EDR 2.1
Bus 001 Device 007: ID 05ac:8218 Apple, Inc. Bluetooth Host Controller
Linux Version
Linux macbook 3.5.0-22-generic #34-Ubuntu SMP
Ubuntu 12.10
What I have done:
Paired my Apple Wireless keyboard with Ubuntu.
What I expect:
When I mash a key on my apple wireless keyboard the system wakes from sleep.
What Happens:
When I mash a key on my apple wireless keyboard; Nothing.....
What I expect from a acceptable answer:
A way to make it so when I mash a key my apple wireless keyboard my computer wakes from sleep, and I can continue on with my computing day.
Of Note:
I usually hate seeing this and saying it, but .... It works in Mac OS X and in Windows, so I know the hardware is capable of doing this.
What I found
I am going to take the time to explain a few things that I found out. This should help people understand why this is such a complicated process, and what they can do to help make it better, at least for them.
First, the Bluetooth radio on the MBP is a "USB" device. This is quite common on laptops and even some desktops. Because of that Linux treats it as a USB device and you can configure it accordingly.
Second, the Bluetooth radio has two modes HID mode with is a very basic "profile" for keyboards and mice only. This mode is what lets you use the keyboard before there is a Application managing the Bluetooth device. For example when your using your Bluetooth keyboard in the GRUB menu, that is HID mode. Your laptop and your keyboard still need to be paired, but they can operate at this very low level without issue or intervention (again once paired). However HID mode is very limited, and certain things will not work. For instance the battery level of the keyboard will not work. Also in HID mode I had a hard time with function keys and media keys (on this keyboard they are the same key and it can be toggled by software).
Next, you need to get the keyboard to send "something" to the laptop. You also need the laptop to receive "something". Then you have to tie it all together to get the laptop to actually wake up.
Finally, Linux, Ubuntu, Bluez, or someone, seems to think that all Bluetooth controllers should act in HCI mode. This is probably a very sane default given that even this keyboard is very limited in HID mode, and that anything beyond a simple mouse and keyboard (for example a cell phone, or head set) would require HCI mode. However HCI mode requires a full software stack to run and will not run while the laptop is suspended/sleep/powered off. So by default when your laptop sleeps it disconnects your keyboard and quits listening.
Actual Steps to get it Working
Step 0: A workaround
When I was doing this I got very frustrated by the fact that I was unable do anything to trouble shoot the issue. You can't do anything when the laptop is asleep, and at least with the Mac Book Pros you can't close the lid without them going to sleep. So your left with a situation where either Video won't work (because it's going to your external monitor that isn't plugged in when undocked) or you can see everything but have no keyboard (because it's not working/paired/whatever, and the internal one is not accessible). To get around this should you run into it. Use the visual keyboard at LDM's login screen. If you wake up to a password prompt, you should be able to click switch user, then use the visual keyboard to login. As long as you login as the same user your session should not be lost. That said, I wouldn't leave any work unsaved while going through these steps.
Step 1: Pre-pair your keyboard.
As I was testing I noticed this step was required. However, I don't fully understand why. Apple does some strange stuff so I am just gonna let it go.
- Reset your PRAM/NVRAM/Whatever. This will clear your current OS X settings, and may not be needed but better to start clean. The Apple support website has instructions. You do not need to reset the PMU.
- Start, or restart, into OS X and pair your keyboard normally. I recommend leaving all your other bluetooth devices turned off and focusing on your keyboard. From what I can tell this will store some information in NVRAM and all the keyboard to communicate with the powered down laptop.
- Click on Advanced (in OS X, once paired) and check "Allow bluetooth devices to wake computer". Once again the apple support website has instructions
- Restart the computer into Linux. At ReFIT/GRUB/while booting the keyboard should work just fine.
Step 2: Getting Linux to work with the keyboard
For some reason the keyboard will loose it's pairing as you login. Probably because the Bluetooth controller is switched to HCI mode. To correct this, you need to pair in Linux. This will break the pairing you did in step 1, but will not break HID mode when the laptop is powered off or booting. That said, when you reboot, your keyboard won't work till your bluetooth stack is fully running again in HCI mode. This is because the keyboard is trying to talk in HCI mode but no one is listening. If you shutdown and wait for the connection to time out, the keyboard will work again in HID mode.
- Install bluez-compat by running
sudo apt-get install bluez-compat
This will allow you to pair with ease. Without the Bluetooth manager just crashed for me. - Pair your Keyboard normally with Linux. Run
Bluetooth
from the Unity Dash and click the plus. Put your keyboard in pairing mode (hold down the power button on the Apple Wireless keyboard) and follow the instructions. It should pair quite smoothly. At this point your keyboard should work just fine in Linux and even sends signals to a HID controller when the laptop is asleep.
Step 3: Telling Linux it needs to wake up
Now we need to tell Linux to wake up if the bluetooth device gets "something". To do this is pretty easy thanks to the scripts at this site. Basic instructions are below but you should read the site if anything is unclear. Almost all of this comes from the linked site.
- Install some dependencies
sudo apt-get install notify-send zenity
- Download the udev resume script and copy to /usr/local/sbin/enable-wakeup.
- Download the device selection script and copy to /usr/local/sbin/select-resume-devices
- Make the scripts executable:
chmod a+x /usr/local/sbin/select-resume-devices
andchmod a+x /usr/local/sbin/enable-wakeup
. - Run with root permissions the device selection script.
sudo /usr/local/sbin/select-resume-devices
- Select, at a minimum, "Apple, Inc. Bluetooth Host Controller", "Belkin Components B8T017 Bluetooth+EDR 2.1", "Apple Inc. Internal Keyboard/Trackpad (ANSI)" and any other devices you want to use to resume your computer.
- Click OK.
- Review the file /etc/udev/rules.d/90-hid-wakeup-enable.rules and make sure it makes sense.
- Restart the computer.
Step 4: Testing and catches
Everything should work fine now that you restarted your computer. Once your logged back in, put your computer in sleep mode somehow. Smack a key on your keyboard and the laptop should resume. There are however a couple of catches.
- When the computer is in sleep mode it's looking for HID devices. So the keyboard starts in HID mode. When your done resuming from sleep mode, Linux is looking for an HCI device. The keyboard (not the laptop) needs to reset the connection. This happens naturally after about 45 seconds. You can force it by removing the batteries, but that may mess up the pairing. If you don't use the keyboard to resume from sleep this is not a problem.
- When rebooting, the keyboard will still be trying to communicate in HCI mode but the laptop will only be looking for HID devices. Again after the timeout the keyboard will get it, and work correctly again.