-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HID over GATT feasibility #459
Comments
It depends. Do you want to implement the server (emulate mouse/keyboard)? Than it may be possible, 50/50. I never tried, but perhaps there are no restrictions like there are for the client. |
Yes I was talking about the server. Thus your android device can be used as mouse and keyboard for a PC from instance. I already have a working prototype using just the Android API. I'm hoping using this library will ease the pain of managing bonding and reconnect for instance. |
That's so cool! Good luck with the project. |
Good to know, though I'm not sure I understand why it would not work as server only before. The |
I must have missed that. I'l fix the doc. Before 2.6.0 to be able to use the |
If I'm just a server but want to initiate a connection to a client device which function should I call? |
For a connection as a client just call the |
Is there a mechanism in place that makes sure The doc says you must call |
That should be called bo matter what even with no callbacks for the write request. |
Looks like I got most of it working but very much like my earlier prototype it fails to properly reconnect to a bound host. When I restart the server after successful bounding somehow the connection is automatically reestablished for a short time, the host reads a few characteristics but then it disconnects and Windows displays "Driver error" as device status. From there I need to delete the paired device and do the bounding anew. Here are some of the last bits of logs I get before it drops out:
|
I wonder if the problem could be in the start-up sequence:
It looks like the device connects before the server is setup properly. TBH I'm not even sure how the device connects in this case. I'm guessing the host is trying to connect as soon the server boots but that could be a bit too early… |
Looks like my issue is similar to that: Certainly the report map is not read properly for some reason. In the logs I can see that during pairing the MTU is changed to 517 and this is not happening when the connection fails. |
Try delaying the advertising after you get the server ready event. |
Also, dod you try a different phone? |
Yes I just did that, should help fix the start-up sequence. Though the issue remain, the HID report map is not read properly it seems. |
Good point I should definitely try another phone. |
Now I still have the problem that I don't know how to reconnect a paired client. Things work after pairing but once the server is shutdown and the connection is lost, more often than not I can't establish a connection with a paired host. I'm not sure which API I should use to do that. I guess I need to look into In the few cases where the connection could be reestablished on its own the report map read was corrupted so I'm guessing that was somehow just a case of the new connection being mistaken for the old connection somehow and the MTU got mixed up maybe. My earlier prototype without using the library had the same issue and my attempt at using |
Hi,
The Android is to work as a HID device, so you have a HID Service. You advertise from Android with some HID service and connect to it on Windows. This causes initial pairing and, as I understand, you are able to send HID messages correctly. Then you restart the phone and try to connect again. Usually, in this case a proper HID device would use direct advertising to automatically trigger connection from the Client. On Android you can't advertise directly, so you're using the only advertising possible, which is the normal, like before pairing. Android should use resolvable private address in this case, so Windows should be able to resume encryption without problems by matching LTK to the resolved MAC address. You should get a standard The Indeed, BLE library doesn't call You may also, instead of using |
When it comes to resuming encryption issue, we would need to see sniffer traces of logs. It's hard to say which side is responsible for the failure and why. Anyway, it's OS job to manage pairing, so the library can't help here and using native API may not help. Did you try a different phone, like Pixel 6 or 7 to rule out phone problem? |
Correct, pairing is triggered from Windows 10/11 settings by searching for new device and selecting the smartphone that's advertising. Once pairing is complete I can control the PC mouse cursor from the Android phone as my prototype's HID device is a mouse which is sending HID reports through that Though there is something a bit funny with the pairing process. I need to accept two pairing request on the Android phone. The first one without pin and a second one with pin. |
Not the phone, just the app. |
Good to know and yes that's what I do. I moved the advertising to start once the server is ready from |
As mentioned above this was only happening when the advertising was started first and I'm guessing when doing a quick app restart. But then the HID report map which is the largest data chunk the client needs to read was not transmitted properly and Windows would go |
I just tried that and using |
Interesting, when I tried using
Will do, maybe I can just force access to private data members instead of forking and using a sub-module just now. |
BTW I had another case of what looks like a reconnect when restarting the app from Android Studio despite the late advertising. Sometimes it still does it, must be a timing thing, though it always end in driver error because of incomplete report map read. |
Also maybe I'm missing something from the HID over GATT specs:
Though I did double check that this |
I did something like that from
So I'm a bit clueless there. Not sure what else I could try. I did double check the specs and it looks like my advertisement is set as connectable so that should do it really… but instead nothing 😁 |
Things to try:
|
If you want automatic reconnection, Android would have to advertise directly, I believe. It's actually up to Windows implementation. The What you may also try is to remove bonding after each disconnection. There's a Anyway, you can't get direct adv from Android so perhaps that's the only option. And I can't say whether it will work. |
There must be ways to get it working somehow. I've seen third party app do that. I've ordered a couple of nRF52840-Dongle to see if I can check how regular devices are doing it. |
It seems to me like most BLE device including Android ones run a couple of standard services. There is notably this Generic Attribute Service with a Service Changed Characteristic which supports indicate. Is there a way to fire up that indication on Android to tell our clients our services have changed just after we created our service? Could this be used to trigger the bounded clients to reconnect? |
Actually the app I thought got this working is actually using classic Bluetooth rather than BLE. In fact it seems they are using something like that: |
When trying this implementation which is not working out of the box, notably it does not wait for the callback while adding multiple GATT services, the reconnect actually worked but not the HID device. Reconnect works I'm guessing as long as the HID device is not added properly. So I was in a state where reconnects would work and the battery status was displayed so somehow the battery status service worked but the HID device would not work and was not detected by Windows. Fixing it by making sure I wait a bit after adding a service makes the HID device work after bounding but reconnect is broken. That makes me think that there could really be a configuration issue in my HID service maybe that Those nRF52840-Dongles should be there next week. |
No, that indication can only indicate during a connection that a new service discovery is required, but the device needs to be already connected and encryption should be resumed by then. |
I wonder if the key to get the reconnect to work with Windows is to use |
As far as I know, the legacy |
Considering using this library to implement HID over GATT. Would it be suitable? I reckon it should be doable since it is just a GATT server with multiple services but I thought I should ask first just in case.
The text was updated successfully, but these errors were encountered: