Closed stefan-sedlak closed 4 years ago
Hello, In my opinion, Deep Thought must have returned this error after 7.5 mln years of calculating. That means, it's not the Answer. It's just transaction collision and user should restart ;)
Back to your question. Just yesterday I released an updated version of nRF Toolbox, where the Proximity profile is using the GATT server and allows multiple connections. Have a look here: https://github.com/NordicSemiconductor/Android-nRF-Toolbox/tree/master/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity
The server services are defined in ProximityServerManager
.
The ProximityServerManager
instance is created in ProximityServer
. There is just one instance of this manager. It will automatically handle requests from all devices and pass them to the right BleManager
.
Whenever a device is connected (the app acts like Proximity Client: it scans for Proximity tags (scanning returns BluetoothDevice
object for each scanned device)) a ProximityManager
(extends BleManager
) is created. The useServer(server)
method is used to assign the server manager and finally, connect(device)
method is called.
When the device connects, the following methods are called in the given order:
gatt.getServices()
, verify that required service has been found on the device (return true is so), and obtain references to characteristics and/or descriptors that are to be used.When the device disconnects, onDeviceDisconnected will be called. As services have been invalidated, this method should release all references to previously saved attributes.
Before 5., you will be able to perform client and server operations in your BleManager
s. Each manager should be treated as a single device API. It will send and receive data to single specified device.
BluetoothDevice
can be obtained in 2 ways.
onScanResult(int callbackType, ScanResult result)
// We recommend using Android Scanner Compat Library if you plan to support older Android versions.
You can also obtain an already bonded device using [BluetoothAdapter#getBondedDevices()](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getBondedDevices()).onDeviceConnectedToServer(@NonNull BluetoothDevice device)
will be called for every connected device. You should be able to create BleManager
instance there, assign the server to it and connect to this device (calling manager.connect(device).enqueue()
will connect the manager to the server, despite the server being already connected, where it is the device that acts like client).Hi @philips77 ,
thanks for great answer!
I checked Android-nRF-Toolbox example after studying BLE standard and Android API (I like to understand what I develop). I miss example peripheral handles multiple centrals. As I understand there is just start of GATT server.
I thought that I will not use 3rd party libraries but I am really glad that you provided good one. iOS Bluetooth API is much more better than Android API(s) and you saved a lot of my time.
My central connects to multiple peripherals after scanning provided by your scanning library ;)
My peripheral handles multiple centrals connections. BLEManager
is created and connected in onDeviceConnectedToServer
by manager.connect(device).enqueue()
It is a bit confusing to (re)connect when device (central) is already connected.
I was just afraid of
E/BleManager: onConnectionUpdated received status: 42, interval: 12, latency: 0, timeout: 200
in log. It is still present in log however multiple connections (centrals->peripheral) work well. I already tested it.
Thanks, Stefan
Hi @philips77 could you please provide an example how to integrate GATT server with multiple connected clients /
BleManager
-s? I have a use case where I need to notify different characteristic values to different clients.From README file it is not clear. I miss link between connected client's
BluetoothDevice
and itsBleManager
. Or how to initializeBleManager
for connected client.I used in
onDeviceConnectedToServer(@NonNull BluetoothDevice device)
:and tried to add:
It is only method were I can set
BluetoothDevice
.But it causes:
42 is "Answer to the Ultimate Question of Life, the Universe, and Everything" however in our case status 42 means BLE_HCI_DIFFERENT_TRANSACTION_COLLISION what does not look well.
However it seems that
MyBleManager
'sBleManagerGattCallback
triggersonServerReady(@NonNull BluetoothGattServer server)
with local GATT server service and characteristics. What I would expect.So I am confused :)
Thanks for your advise.