0

目前正在开发一个 android 应用程序以连接 ble 自定义服务。扫描工作正常,但现在我无法从服务中读取特征。我使用的是 PSoC 开发板。制作了具有多种特性的自定义服务,并使用程序 CySmart 进行了调试,一切正常。

    @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status){
            if (status == BluetoothGatt.GATT_SUCCESS)
            {

                List<BluetoothGattService> gattServices =   mBluetoothGatt.getServices();
                Log.e("onServicesDiscovered", "Services count: "+gattServices.size());

                for (BluetoothGattService gattService : gattServices) {
                    String serviceUUID = gattService.getUuid().toString();
                    Log.e("onServicesDiscovered", "Service uuid "+serviceUUID);
                }

                BluetoothGattService gattService = mBluetoothGatt.getService(UUID.fromString(ServiceUUID));
                if (gattService == null)
                {
                    Log.i("BLEtest", "gattservice null");
                    return; // return if the service is not supported
                }
                Characteristic1 = gattService.getCharacteristic(UUID.fromString(Char1UUID));
                Characteristic2 = gattService.getCharacteristic(UUID.fromString(Char2UUID));

            }
            broadcastUpdate(ACTION_SERVICES_DISCOVERED);
        }

现在在 android 应用程序中,当连接到 GATT 服务器后发现服务时,mBluetoothGatt.getServices() 在尝试使用我在自定义服务中实现的 UUID 发现服务时返回 null。发生这种情况后,我添加了返回所有发现的服务的代码部分,而不使用任何 UUID。结果是 3 个 UUID,与我实现的 UUID 不同。

02-18 02:33:29.366 19755-19767/jafs.app E/onServicesDiscovered: Services count: 3
02-18 02:33:29.366 19755-19767/jafs.app E/onServicesDiscovered: Service uuid 00001800-0000-1000-8000-00805f9b34fb
02-18 02:33:29.367 19755-19767/jafs.app E/onServicesDiscovered: Service uuid 00001801-0000-1000-8000-00805f9b34fb
02-18 02:33:29.367 19755-19767/jafs.app E/onServicesDiscovered: Service uuid 88117a52-cce5-40de-a40c-1984a342ea00
02-18 02:33:29.367 19755-19767/jafs.app I/BLEtest: gattservice null

我实现的自定义服务上的 UUID 是不同的。已经在自定义服务中生成了不同的 UUID,但它仍然返回相同的 UUID。我认为前 2 个 UUID 最初是在制作自定义 BLE 服务时默认设置的,但我最终改变了。不知何故,第三个不像其他人。

任何帮助都是有价值的!

4

0 回答 0