Skip to content
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

Connected Clients Handling #7

Open
smokingfish opened this issue Dec 8, 2017 · 5 comments
Open

Connected Clients Handling #7

smokingfish opened this issue Dec 8, 2017 · 5 comments

Comments

@smokingfish
Copy link

smokingfish commented Dec 8, 2017

Hi there,

it would be nice to add a list of currently subscribed clients to the service views.
On my own GATT Server I see a lot of issues with keeping track of sessions/clients, events not firing on 'ungraceful' disconnects and so on. So it would be really helpful to see a nice sample for that. Would also be nice to expand the samples to notify selected clients only.

Pretty much SubscribedClientsChanged and GattSession.SessionStatusChanged to keep track of sessions/clients and expand on the NotifyValueAsync and show how to send notifications to selected clients only.

Also a question, do you know why GattSession.Close() is not implemented? I could really use that :)

@smokingfish
Copy link
Author

The most important thing to keep in mind with GATT and connections is that connections are exclusive. What is meant by that is that a BLE peripheral can only be connected to one central device (a mobile phone, etc.) at a time! As soon as a peripheral connects to a central device, it will stop advertising itself and other devices will no longer be able to see it or connect to it until the existing connection is broken.

From 'Introduction to GATT' from adafruit.

That is how my old dongle works and it would solve my problems.
As it works right now with the GATT service is that I can connect multiple centrals to the server, which makes the session handling necessary. I can also not call StopAdvertising after the first subscription because it breaks the current connection (the central will still be connected, but no messages or notifications go through).

@mtbeaver
Copy link

mtbeaver commented Nov 5, 2018

The introduction on GATT from Adafruit you quoted is out of date and applies to the 4.0 specification. For host radios supporting 4.1 topology, which we require for "peripheral role" to be enabled, simultaneous connections to a peripheral are supported.

With regard to your question, GattSession.Close (IDisposable) is implemented. If you are seeing issues with that, or with tracking subscribed clients, we would need tracing to diagnose what you are observing. We have instructions here, How to collect bluetooth logs.

@smokingfish
Copy link
Author

@mtbeaver Thank you for the answer.
By now most of my problems are solved by workaround. I see that multiple connections are supported in spec and I can work with that. But I am still missing the ability to close a session from the windows end.
You say GattSession.Close is implemented. On what version? MSDN clearly indicates that it is not implemented. We currently need to do a lifeline ping and close the connection cleanly on the peripheral side on low RSSI to work around this issue.

@mtbeaver
Copy link

mtbeaver commented Nov 6, 2018

Seems like this is some confusion after the docs were moved to the new format. in WRL, the GattSession object implements Windows::Foundation::IClosable interface, which exposes the Close method. In C#, this is projected as IDisposable, which exposes it as Dispose. For your App, assuming it is C#, should be using the Dispose method on the session.

You can see more details on how IClosable works here: Windows.Foundation.IClosable

@smokingfish
Copy link
Author

@mtbeaver Thanks again. But I figured as much and only asked because that does not seem to work. Calling Dispose on the session does indeed dispose the session on the windows side. But the peripheral still sees itself as connected and sending another message on a subscribed characteristic just creates new session object. I would expect Dispose/Close to actually disconnect the given peripheral.
This can easily be tested using nRF connect for example, connecting to a BLED for example and calling close on the BLED does indeed close the connection as expected, on windows it stays open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants