3

I developed two applications that implements both GATT roles: server and client. In my case, the GATT server is also the GAP peripheral and the GATT client is the GAP central.

I can connect/disconnect the client to/from the server, but I found some problems when I tried to stop advertising in the moment when the client is connected to the server. In this case, the connection is broken.

I can't understand. If two devices are connected, the server shoud not need to transmit advertising packets to keep alive the connection... That's strange.

I am using the SDK version 23

matt92CH
  • 31
  • 3

2 Answers2

1

After receiving STATE_CONNECTED in your GattServerCallback, before stopping advertise, run mGattServer.connect(device, false); to tell the fool Android that "Hey, I want to keep this connection alive!"!

YUSMLE
  • 705
  • 6
  • 21
0

According to the BLE specification following is allowed: A device which is in connection state can have both master and slave roles simultaneously. Master and slave devices may have multiple connections. The only restriction is the following: Two BLE devices cannot be both master and slave for each other at the same time since two BLE devices can have only one connection at a time.

Although BLE specification states these rules, it is the BLE chip in your device that limits the number of connections and number of other BLE events that are happening simultaneously. If you see unexpected behaviors on BLE, I would suggest to try the same thing with different devices that have different BLE chips.

After a connection is established, it is lower layers' task to keep the connection alive. You don't need to do anything using the API. If the device is in connection, the connection may not be stable in case it advertises at the same time depending on the capability of the chip.

ulusoyca
  • 841
  • 9
  • 18
  • Thak's for the reply. I agree that it's not the task of application to keep the connection alive, but if I try to stop advertising when the connection is established, automatically devices are disconnected. I would to stop advertising to prevent other device connecting to my GATT server and most important thing to consume less power. – matt92CH Dec 26 '15 at 08:57