toy / blueutil

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

My bluetooth keyboard shows in Bluetooth control panel but not with blueutil --paired #79

Open timbyu opened 1 year ago

timbyu commented 1 year ago

I have a Microsoft Bluetooth Ergonomic Keyboard that keeps going to sleep after 5-10 minutes of inactivity. I was hoping to find a bluetooth utility that would let me interact with the keyboard in hopes that it would keep it awake. Right off the bat when I run blueutil with --paired I see all of my paired devices except this keyboard. When I go into MacOS settings under bluetooth the keyboard is listed as "Ergonomic Keyboard" (it even shows battery life) but it does not show in the list from blueutil. I am running Ventura 13.4.1 on an M2 MacBook pro. Any help for suggestions for how I can keep my bluetooth keyboard from sleeping would be very very much appreciated! image

toy commented 1 year ago

Thanks for opening the issue. Do you have this one? Tech specs tab shows that it is using Low Energy Bluetooth, not Classic Bluetooth. Currently blueutil only provides access to Classic devices (using IOBluetooth framework), as interface to Low Energy devices is in separate framework (Core Bluetooth). After looking at specs of few modern Bluetooth keyboards, I see that decent part of them are using Low Energy, so a good idea to check feasibility of adding interface to them to blueutil.

timbyu commented 1 year ago

I have this one https://www.microsoft.com/en-us/d/surface-ergonomic-keyboard/90pnc9ljwpx9 that says it is Bluetooth 4.0. I don't see anything about it being Low Energy but I guess it could be. If I were to get into the Core Bluetooth framework, what approach would you suggest to keep my keyboard from going to sleep?

toy commented 1 year ago

Bluetooth 4.0 can be both Classic and Low Energy, though tech specs tab from the link mentions «Bluetooth Low Energy compatible 4.0/4.1». After looking a bit at Core Bluetooth framework, I can say that unfortunately big part of it is not public. I don't know what will help keeping the keyboard from going to sleep, is it on keyboard side or on os side, is there an app from microsoft for configuring it? As an example of Core Bluetooth framework, here is an example for listing paired Low Energy devices:

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

int main() {
  @autoreleasepool {
    CBCentralManager *manager = [[CBCentralManager alloc] init];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
    id agent = [manager performSelector:@selector(sharedPairingAgent)];
    NSLog(@"%@", [agent performSelector:@selector(retrievePairedPeers)]);
#pragma clang diagnostic pop
  }
  return 0;
}