Android、iOS和Win8的蓝牙低能耗连接参数
我一直在到处寻找适用于这三种操作平台的所需蓝牙连接参数。我正在为这个项目使用HOGP(通过HID GATT的蓝牙)配置文件 我的项目是一个由我自己编写的嵌入式系统,带有一个BLE模块,我可以控制以下连接参数Android、iOS和Win8的蓝牙低能耗连接参数,android,ios7,bluetooth,bluetooth-lowenergy,android-bluetooth,Android,Ios7,Bluetooth,Bluetooth Lowenergy,Android Bluetooth,我一直在到处寻找适用于这三种操作平台的所需蓝牙连接参数。我正在为这个项目使用HOGP(通过HID GATT的蓝牙)配置文件 我的项目是一个由我自己编写的嵌入式系统,带有一个BLE模块,我可以控制以下连接参数 最小连接间隔 最大连接间隔 从属延迟 监督超时 广告间隔分钟 最大广告间隔 我要连接的目标设备将是满足与Android>=4.3、iOS7和>=Win 8.1的连接 苹果公司非常友好,在第22页下面的链接中提供了一份包含适当参数的文档。我还没有找到任何关于Android和Win 8的信息
提前谢谢 首先,连接间隔定义了一个时间窗口,在此期间,两个设备使用相同的频率传输数据。总共有37个数据通道,每个连接间隔连接的设备都会跳转通过这些通道 因此,两个设备必须从一开始就商定这些参数的精确值,以便同步,即连接 其次,当建立连接时,主(或中心)发送它支持的连接参数。其他设备(或外围设备)只是盲目地使用它们。iOS默认将连接间隔设置为30毫秒。连接建立后,外设可以根据苹果提供的指导原则,通过定义最小值和最大值,请求更新连接参数。接收部分(在本例中为read iOS)将在[min;max]之间选择它认为最适合它的内容,并用它选择的精确值返回响应。如果值不符合指南,它还可以拒绝请求 最后,7.5ms是蓝牙规范定义的连接间隔的最小长度。最大值为4秒。它越低,带宽越高,但功耗越高。而在较高的值中则相反。最佳值取决于具体应用。考虑到您使用HID配置文件,我认为延迟对您很重要 iOS说它支持低至20毫秒的连接间隔(虽然我发现有时很难实现),但在您的情况下(HID配置文件),它们也允许11.25毫秒的连接间隔
希望有帮助。要修改Android中的参数(从中央到外围设备请求),您可以执行以下操作:
private String CONN_SERVICE_UUID = "00001800-0000-1000-8000-00805f9b34fb";
private static final UUID CONN_CHARACTERISTIC_UUID = UUID.fromString("00002a04-0000-1000-8000-00805F9B34FB");
private static final int CONN_INTERVAL = 0x0006;
private static final int SUPERVISION_TIMEOUT = 0x000A;
private void findServiceForConnectionParams(List<BluetoothGattService> gattServices){
BluetoothGattService connGattService = filterServices(gattServices, CONN_SERVICE_UUID);
if (connGattService != null) {
setConnectionInterval(connGattService);
}
}
private void setConnectionInterval(BluetoothGattService gattService) {
if (gattService == null) {
Log.e(TAG, "setConnectionInterval. Gatt service is null!");
return;
}
BluetoothGattCharacteristic connCharacteristic =
gattService.getCharacteristic(CONN_CHARACTERISTIC_UUID);
if (connCharacteristic != null) {
byte[] value = { (byte) (CONN_INTERVAL & 0x00FF), // gets LSB of 2 byte value
(byte) ((CONN_INTERVAL & 0xFF00) >> 8), // gets MSB of 2 byte value
(byte) (CONN_INTERVAL & 0x00FF),
(byte) ((CONN_INTERVAL & 0xFF00) >> 8),
0, 0,
(byte) (SUPERVISION_TIMEOUT & 0x00FF),
(byte) ((SUPERVISION_TIMEOUT & 0xFF00) >> 8)
};
connCharacteristic.setValue(value);
boolean status = mBluetoothGatt.writeCharacteristic(connCharacteristic);
Log.d(TAG, "setConnectionInterval. Change connection interval result: " + status);
} else {
Log.e(TAG, "setConnectionInterval. Connection characteristic is null!");
}
}
private BluetoothGattService filterServices(List<BluetoothGattService> gattServices, String targetUuid) {
for(BluetoothGattService gattService : gattServices){
String serviceUUID = gattService.getUuid().toString();
Log.i(TAG, "serviceUUID: " + serviceUUID);
if(serviceUUID.equals(targetUuid)){
Log.i(TAG, "serviceUUID matches! UUID: " + serviceUUID + " Type: " + gattService.getType());
// no needed, just to check which characteristics are offered
for(BluetoothGattCharacteristic characteristic : gattService.getCharacteristics()) {
Log.i(TAG, "serviceUUID characteristics: " + characteristic.getUuid().toString());
}
return gattService;
}
}
return null;
}
private String CONN_UUID=“00001800-0000-1000-8000-00805f9b34fb”;
专用静态最终UUID连接特性UUID=UUID.fromString(“00002a04-0000-1000-8000-00805F9B34FB”);
专用静态最终内部连接间隔=0x0006;
专用静态最终int监控\u超时=0x000A;
私有void findServiceForConnectionParams(列出gattServices){
BluetoothGattService ConngGattService=过滤器服务(GattService,CONN_服务_UUID);
if(connGattService!=null){
setConnectionInterval(连接服务);
}
}
私有void setConnectionInterval(BluetoothGattService gattService){
if(gattService==null){
Log.e(标记“setConnectionInterval.Gatt服务为空!”);
返回;
}
BluetoothGattCharacteristic特征=
gattService.getCharacteristic(连接特性);
if(connCharacteristic!=null){
byte[]value={(byte)(CONN_INTERVAL&0x00FF),//获取2字节值的LSB
(byte)((CONN_INTERVAL&0xFF00)>>8),//获取2字节值的MSB
(字节)(连接间隔和0x00FF),
(字节)((连接间隔&0xFF00)>>8),
0, 0,
(字节)(监控超时和0x00FF),
(字节)((监控超时&0xFF00)>>8)
};
connCharacteristic.setValue(值);
布尔状态=mBluetoothGatt.writeCharacteristic(connCharacteristic);
Log.d(标记“setConnectionInterval.Change连接间隔结果:”+状态);
}否则{
Log.e(标记“setConnectionInterval.ConnectionCharacteristicisNull!”);
}
}
私有BluetoothGattService筛选器服务(列出GattService,字符串targetUuid){
用于(蓝牙gattService gattService:gattServices){
字符串serviceUUID=gattService.getUuid().toString();
Log.i(标签“serviceUUID:+serviceUUID”);
if(serviceUUID.equals(targetUuid)){
Log.i(标记“serviceUUID匹配!UUID:+serviceUUID+”类型:+gattService.getType());
//不需要,只需检查提供了哪些特性
for(BluetoothGattCharacteristic特征:gattService.g