Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android、iOS和Win8的蓝牙低能耗连接参数_Android_Ios7_Bluetooth_Bluetooth Lowenergy_Android Bluetooth - Fatal编程技术网

Android、iOS和Win8的蓝牙低能耗连接参数

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的信息

我一直在到处寻找适用于这三种操作平台的所需蓝牙连接参数。我正在为这个项目使用HOGP(通过HID GATT的蓝牙)配置文件

我的项目是一个由我自己编写的嵌入式系统,带有一个BLE模块,我可以控制以下连接参数

  • 最小连接间隔
  • 最大连接间隔
  • 从属延迟
  • 监督超时
  • 广告间隔分钟
  • 最大广告间隔
  • 我要连接的目标设备将是满足与Android>=4.3、iOS7和>=Win 8.1的连接

    苹果公司非常友好,在第22页下面的链接中提供了一份包含适当参数的文档。我还没有找到任何关于Android和Win 8的信息

    我目前的iOS7工作设置通过免费软件lightBlue的双向通信进行了全面测试,如下所示。我的iOS7嵌入式代码和主机软件工作正常

  • 连接间隔至少30ms
  • 连接间隔最大为56.25ms
  • 从机延迟3
  • 监控超时5000ms
  • 我在另一个堆栈溢出页面上发现,android据称在以下链接中以7.5ms的连接间隔工作

  • 不幸的是,苹果iOS规范的第二个要求是“间隔最小”≥ 20毫秒”

    我是否不理解这些范围或它们是如何解释的?如果我将安卓系统的最小间隔设置为7.5ms,这难道不会使苹果公司的要求无效吗?如果可能,如何满足系统和Win8的要求

    我的理解是,从设备在最小值和最大值之间提供建议设置,主设备(智能手机)会提醒用户该范围内的实际选定值

    我非常感谢在这个问题上的任何帮助,并希望这篇文章能够使其他人受益,因为BLE的知识库相当新且不完整


    提前谢谢

    首先,连接间隔定义了一个时间窗口,在此期间,两个设备使用相同的频率传输数据。总共有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