简体   繁体   English

Android-GATT Server连续广告

[英]Android - GATT Server advertise continuosly

I developed two applications that implements both GATT roles: server and client. 我开发了同时实现GATT角色的两个应用程序:服务器和客户端。 In my case, the GATT server is also the GAP peripheral and the GATT client is the GAP central. 就我而言,GATT服务器也是GAP外设,而GATT客户端也是GAP中心。

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 我正在使用SDK版本23

According to the BLE specification following is allowed: A device which is in connection state can have both master and slave roles simultaneously. 根据BLE规范,允许以下操作:处于连接状态的设备可以同时具有主角色和从角色。 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. 唯一的限制如下:两个BLE设备不能同时作为主设备和从设备,因为两个BLE设备一次只能建立一个连接。

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. 尽管BLE规范规定了这些规则,但设备中的BLE芯片限制了连接数量以及同时发生的其他BLE事件的数量。 If you see unexpected behaviors on BLE, I would suggest to try the same thing with different devices that have different BLE chips. 如果您在BLE上看到意外的行为,我建议在具有不同BLE芯片的不同设备上尝试相同的操作。

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. 您无需使用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. 如果设备处于连接状态,则根据芯片的性能,如果同时发布广告,连接可能会不稳定。

After receiving STATE_CONNECTED in your GattServerCallback , before stopping advertise, run mGattServer.connect(device, false); 接收后STATE_CONNECTEDGattServerCallback ,之前停止打广告,运行mGattServer.connect(device, false); to tell the fool Android that "Hey, I want to keep this connection alive!"! 告诉傻瓜Android:“嘿,我想保持这种连接的活力!”!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM