我正在尝试创建具有READ和NOTIFY属性的多个特征的BLE服务(适用于Android)。到目前为止,我可以连接到GATT服务器并从每个特征读取数据。另外,我可以订阅其中之一的通知。但是,也具有NOTIFY属性的另一个特征是不让我进行订阅。 我正在使用以下代码:
public static UUID SERVICE = UUID.fromString("00000010-0000-1000-8000-00805f9b34fb");
public static UUID CHARACTERISTIC = UUID.fromString("00000011-0000-1000-8000-00805f9b34fb");
public static UUID CHARACTERISTIC_2 = UUID.fromString("00000012-0000-1000-8000-00805f9b34fb");
public static UUID CLIENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
public static UUID CLIENT_CONFIG2 = UUID.fromString("00002903-0000-1000-8000-00805f9b34fb");
//Create a service
BluetoothGattService service = new BluetoothGattService(SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY);
//CREATE THE FIRST CHARACTERISTIC
BluetoothGattCharacteristic Characteristic1 = new BluetoothGattCharacteristic(CHARACTERISTIC1,
BluetoothGattCharacteristic.PROPERTY_READ
| BluetoothGattCharacteristic.PROPERTY_NOTIFY
| BluetoothGattCharacteristic.PROPERTY_WRITE,
BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM
| BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM);
//Create a descriptor
BluetoothGattDescriptor rideDescriptor = new BluetoothGattDescriptor(CLIENT_CONFIG,
BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM
| BluetoothGattDescriptor.PERMISSION_WRITE_ENCRYPTED_MITM);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE THE SECOND CHARACTERISTIC
BluetoothGattCharacteristic Characteristic2 = new BluetoothGattCharacteristic(CHARACTERISTIC,
BluetoothGattCharacteristic.PROPERTY_NOTIFY
| BluetoothGattCharacteristic.PROPERTY_READ,
BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM
| BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM);
BluetoothGattDescriptor rideDescriptor2 = new BluetoothGattDescriptor(CLIENT_CONFIG2,
BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM
| BluetoothGattDescriptor.PERMISSION_READ_ENCRYPTED_MITM);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Add the characteristic and the descriptor to the service
Characteristic1.addDescriptor(rideDescriptor);
Characteristic2.addDescriptor(rideDescriptor2);
service.addCharacteristic(rideCharacteristic);
service.addCharacteristic(rideCharacteristic2); ```
I think it has something to do with the UUIDs but I'm not sure.
Any ideas?
Thanks in advance.