I am working on creating an app that can act as both a client and server for gatt connections simultaneously, but I am getting an unknown status and a disconnected state every time I run the server while it is behaving as a client.
This is the process right now:
1) Start one phone as the server (Phone1)
2) Start the other phone as the client (Phone2)
3) Connect Phone2 to Phone1 and receive notification updates about the current time.
4) Start the server gatt server on Phone2, and this is where I am getting an unknown status for my Bluetooth gatt callback. First it disconnects Phone2 from Phone1 (breaking the gatt connection), then Phone2's onConnectionStateChange for the BluetoothGattCallBack returns a disconnected state and a status code 19.
I am not really sure what could be causing this but both phones are identical Motorola XT1526 API level 22s. Is it possible this is a hardware issue where the phone cannot act as both a gatt server and client simultaneously? I have also tried using one Bluetooth adapter object for the same phone's client and server, but also two separate Bluetooth adapter objects. Any help would be greatly appreciated.
According to Bluetooth specification (Bluetooth Spec 4.2 Vol. 6 part B 4.5: Connection State):
"There shall be only one connection between two LE device addresses. An initiator shall not send a connection request to an advertiser it is already connected to. If an advertiser receives a connection request from an initiator it is already connected to, it shall ignore that request."
It's possible that Android
phones prevent such situations with disconnection, cause I have the same problem here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With