Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with Android Bluetooth Gatt Server/Client Simultaneous Connection

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.

like image 783
user1634494 Avatar asked Nov 08 '22 19:11

user1634494


1 Answers

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.

like image 164
Andrei Piatygin Avatar answered Nov 14 '22 21:11

Andrei Piatygin